From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Eric Botcazou <ebotcazou@adacore.com>
Subject: [Ada] Preserve unchecked conversion of string constant
Date: Thu, 19 May 2022 14:16:20 +0000 [thread overview]
Message-ID: <20220519141620.GA3723475@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 251 bytes --]
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.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 705 bytes --]
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
{
reply other threads:[~2022-05-19 14:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220519141620.GA3723475@adacore.com \
--to=derodat@adacore.com \
--cc=ebotcazou@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).