public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-8982] d: Don't include terminating null pointer in string expression conversion (PR102185)
@ 2021-09-12 15:47 Iain Buclaw
  0 siblings, 0 replies; only message in thread
From: Iain Buclaw @ 2021-09-12 15:47 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:09a2049123e242aaf8a4bbfa8eb3ce92901b6f4e

commit r11-8982-g09a2049123e242aaf8a4bbfa8eb3ce92901b6f4e
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Fri Sep 3 09:34:00 2021 +0200

    d: Don't include terminating null pointer in string expression conversion (PR102185)
    
    This gets re-added by the ExprVisitor when lowering StringExp back into a
    STRING_CST during the code generator pass.
    
            PR d/102185
    
    gcc/d/ChangeLog:
    
            * d-builtins.cc (d_eval_constant_expression): Don't include
            terminating null pointer in string expression conversion.
    
    gcc/testsuite/ChangeLog:
    
            * gdc.dg/pr102185.d: New test.
    
    (cherry picked from commit 53a4def0dc1aac39d592a0d20e9ec16e8b5574ac)

Diff:
---
 gcc/d/d-builtins.cc             | 2 +-
 gcc/testsuite/gdc.dg/pr102185.d | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index 6d294697223..9d40cbc5a0b 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -369,7 +369,7 @@ d_eval_constant_expression (const Loc &loc, tree cst)
       else if (code == STRING_CST)
 	{
 	  const void *string = TREE_STRING_POINTER (cst);
-	  size_t len = TREE_STRING_LENGTH (cst);
+	  size_t len = TREE_STRING_LENGTH (cst) - 1;
 	  return StringExp::create (loc, CONST_CAST (void *, string), len);
 	}
       else if (code == VECTOR_CST)
diff --git a/gcc/testsuite/gdc.dg/pr102185.d b/gcc/testsuite/gdc.dg/pr102185.d
new file mode 100644
index 00000000000..39823a3c556
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr102185.d
@@ -0,0 +1,7 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102185
+// { dg-do compile }
+
+static assert(__traits(getTargetInfo, "floatAbi").length == 0 ||
+              __traits(getTargetInfo, "floatAbi") == "hard" ||
+              __traits(getTargetInfo, "floatAbi") == "soft" ||
+              __traits(getTargetInfo, "floatAbi") == "softfp");


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-12 15:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-12 15:47 [gcc r11-8982] d: Don't include terminating null pointer in string expression conversion (PR102185) Iain Buclaw

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).