Hi, This patch fixes an issue with the routine that converts STRING_CST to a StringExp for the dmd front-end to use during the semantic pass.
The null terminator gets re-added by the ExprVisitor when lowering StringExp back into a STRING_CST during the code generator pass. Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32, committed to mainline and backported to the releases/gcc-11 branch. Regards, Iain. --- gcc/d/ChangeLog: PR d/102185 * d-builtins.cc (d_eval_constant_expression): Don't include terminating null pointer in string expression conversion. gcc/testsuite/ChangeLog: PR d/102185 * gdc.dg/pr102185.d: New test. --- gcc/d/d-builtins.cc | 2 +- gcc/testsuite/gdc.dg/pr102185.d | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gdc.dg/pr102185.d diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc index ab39d69c294..33347a14c67 100644 --- a/gcc/d/d-builtins.cc +++ b/gcc/d/d-builtins.cc @@ -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 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"); -- 2.30.2