]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
d: Don't include terminating null pointer in string expression conversion (PR102185)
authorIain Buclaw <ibuclaw@gdcproject.org>
Fri, 3 Sep 2021 07:34:00 +0000 (09:34 +0200)
committerIain Buclaw <ibuclaw@gdcproject.org>
Sun, 12 Sep 2021 15:36:19 +0000 (17:36 +0200)
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.

gcc/d/d-builtins.cc
gcc/testsuite/gdc.dg/pr102185.d [new file with mode: 0644]

index ab39d69c294e419d46d520c65393e1a61da77991..33347a14c670fd5ff167907c28f27d4e1cf534db 100644 (file)
@@ -380,7 +380,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 (file)
index 0000000..39823a3
--- /dev/null
@@ -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");