From patchwork Fri Nov 6 15:05:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 541004 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 328F91402BB for ; Sat, 7 Nov 2015 02:06:12 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Y4QpBjmg; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=Pe7drUpAwvKcXoRc 80GELZ/TKYidvBiPUFP1kSyvwozOUwzxvbesTPXWSNzYjBKKoUsuTRqDiEtwUaIM H4LAalPSd+qHLZOSQMck4INOE32hubRcj8yjEnCywhjd2lC+J6FjarkaNg65MpiT 1uli+IrlGzkIn7xpV4WeDkOPNeo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=/MnTvdLKkUFAjLS7hqjR8v lWpiA=; b=Y4QpBjmgH5OEfSepvfZutP1/CIYOr4Ssiy3iiXHxY2MPxB116sAyez zlfL4MnOsatuYMYj9NYi9wc+IEMWjnTg6n2Kko88RavkS7inSl0nPp9j9crVjJ+t ClDP2Kr+80qxfoZxaafApERTGB5LAFz1cS1yOF/JZx/DWnA4xJc+k= Received: (qmail 70902 invoked by alias); 6 Nov 2015 15:06:05 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 69865 invoked by uid 89); 6 Nov 2015 15:06:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (207.82.80.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 06 Nov 2015 15:06:03 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-36-cJf32PZ0Qp29g4Lrr9f37A-1; Fri, 06 Nov 2015 15:05:58 +0000 Received: from localhost ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 6 Nov 2015 15:05:58 +0000 From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Move c_getstr to fold-const.c Date: Fri, 06 Nov 2015 15:05:58 +0000 Message-ID: <87a8qrtbft.fsf@e105548-lin.cambridge.arm.com> User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-MC-Unique: cJf32PZ0Qp29g4Lrr9f37A-1 Upcoming patches to fold-const-call.c want to use c_getstr, which is currently defined in builtins.c. The function doesn't really do anything related to built-ins, and I'd rather not make fold-const-call.c depend on builtins.c and builtins.c depend on fold-const-call.c, so this patch moves the function to fold-const.c instead. Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi. OK to install? Thanks, Richard gcc/ * builtins.h (c_getstr): Move to... * fold-const.h (c_getstr): ...here. * builtins.c (c_getstr): Move to... * fold-const.c (c_getstr): ...here. diff --git a/gcc/builtins.c b/gcc/builtins.c index 8f0717c..69c56e7 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -616,27 +616,6 @@ c_strlen (tree src, int only_value) return ssize_int (strlen (ptr + offset)); } -/* Return a char pointer for a C string if it is a string constant - or sum of string constant and integer constant. */ - -const char * -c_getstr (tree src) -{ - tree offset_node; - - src = string_constant (src, &offset_node); - if (src == 0) - return 0; - - if (offset_node == 0) - return TREE_STRING_POINTER (src); - else if (!tree_fits_uhwi_p (offset_node) - || compare_tree_int (offset_node, TREE_STRING_LENGTH (src) - 1) > 0) - return 0; - - return TREE_STRING_POINTER (src) + tree_to_uhwi (offset_node); -} - /* Return a constant integer corresponding to target reading GET_MODE_BITSIZE (MODE) bits from string constant STR. */ diff --git a/gcc/builtins.h b/gcc/builtins.h index cce9e75..b039632 100644 --- a/gcc/builtins.h +++ b/gcc/builtins.h @@ -87,7 +87,6 @@ extern bool is_simple_builtin (tree); extern bool is_inexpensive_builtin (tree); extern bool readonly_data_expr (tree exp); -extern const char *c_getstr (tree); extern bool init_target_chars (void); extern unsigned HOST_WIDE_INT target_newline; extern unsigned HOST_WIDE_INT target_percent; diff --git a/gcc/fold-const.c b/gcc/fold-const.c index ee9b349..3b6e898 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -14397,3 +14397,24 @@ fold_build_pointer_plus_hwi_loc (location_t loc, tree ptr, HOST_WIDE_INT off) return fold_build2_loc (loc, POINTER_PLUS_EXPR, TREE_TYPE (ptr), ptr, size_int (off)); } + +/* Return a char pointer for a C string if it is a string constant + or sum of string constant and integer constant. */ + +const char * +c_getstr (tree src) +{ + tree offset_node; + + src = string_constant (src, &offset_node); + if (src == 0) + return 0; + + if (offset_node == 0) + return TREE_STRING_POINTER (src); + else if (!tree_fits_uhwi_p (offset_node) + || compare_tree_int (offset_node, TREE_STRING_LENGTH (src) - 1) > 0) + return 0; + + return TREE_STRING_POINTER (src) + tree_to_uhwi (offset_node); +} diff --git a/gcc/fold-const.h b/gcc/fold-const.h index 97d18cf..94a21b7 100644 --- a/gcc/fold-const.h +++ b/gcc/fold-const.h @@ -180,6 +180,7 @@ extern tree exact_inverse (tree, tree); extern tree const_unop (enum tree_code, tree, tree); extern tree const_binop (enum tree_code, tree, tree, tree); extern bool negate_mathfn_p (enum built_in_function); +extern const char *c_getstr (tree); /* Return OFF converted to a pointer offset type suitable as offset for POINTER_PLUS_EXPR. Use location LOC for this conversion. */