From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 2C56E383D839 for ; Thu, 19 May 2022 14:16:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2C56E383D839 Received: by mail-wr1-x430.google.com with SMTP id k30so7382615wrd.5 for ; Thu, 19 May 2022 07:16:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=JRfCWfaT7E4S3dYoxohkY3kafedYndLCR604xVPL9mM=; b=yBgQtqXbnWoX5+q2PxtNG/n28RNpihiVT2/EQXLdM0M71GRJrCxou38ye5UPYZ6YjN DrEb9puwwpJJ7WjxeINqo2S7gK1AwzUNOKySBLVxJCq4kkRSQ0329Y/LJWZFweFVOo22 jSJTW0M5+dpVHiHfLxQq8UZVN7cp0+YE5hucFhCus33vuZisE+10Mh9u6ntLA/uChh2q 7KR8ZRNz9cTMIr6PWKjF+EISkJ7xzPAzY/R59RraeorZZxkj+gG/1wIx1SyrwT8JWBui eBEjioC9ZZI1eh0QZVTtHgBezQhsBwGe5fOTMxfzdKgWEj5DiCO8YAwa6M7R0jrhBIa8 vwcw== X-Gm-Message-State: AOAM531kp0NUSz+OLv/tl46oXBBKSksFI/1Grs1brTlL3a6gXmUZfgqV szM1Mwz31CeloJUOadzng2oia8d0J2aXRQ== X-Google-Smtp-Source: ABdhPJy3z7yEHIVLx4W/YCIDpyhhNAj89QO5kWAFtmAyl/nmBYBWuc7+whYG/mitAnFEx+2kxbzB+Q== X-Received: by 2002:a5d:69c5:0:b0:20e:5884:5c75 with SMTP id s5-20020a5d69c5000000b0020e58845c75mr4428250wrw.19.1652969781839; Thu, 19 May 2022 07:16:21 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id f25-20020a1c6a19000000b003942a244f45sm6881087wmc.30.2022.05.19.07.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 May 2022 07:16:21 -0700 (PDT) Date: Thu, 19 May 2022 14:16:20 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [Ada] Preserve unchecked conversion of string constant Message-ID: <20220519141620.GA3723475@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="AqsLC8rIMeq19msA" Content-Disposition: inline X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 May 2022 14:16:24 -0000 --AqsLC8rIMeq19msA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline This makes it possible to pass the result to a C function directly. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * gcc-interface/utils.cc (unchecked_convert): Do not fold a string constant if the target type is pointer to character. --AqsLC8rIMeq19msA Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/gcc-interface/utils.cc b/gcc/ada/gcc-interface/utils.cc --- a/gcc/ada/gcc-interface/utils.cc +++ b/gcc/ada/gcc-interface/utils.cc @@ -5637,6 +5637,13 @@ unchecked_convert (tree type, tree expr, bool notrunc_p) return unchecked_convert (type, expr, notrunc_p); } + /* If we are converting a string constant to a pointer to character, make + sure that the string is not folded into an integer constant. */ + else if (TREE_CODE (expr) == STRING_CST + && POINTER_TYPE_P (type) + && TYPE_STRING_FLAG (TREE_TYPE (type))) + expr = build1 (VIEW_CONVERT_EXPR, type, expr); + /* Otherwise, just build a VIEW_CONVERT_EXPR of the expression. */ else { --AqsLC8rIMeq19msA--