]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
d: __FUNCTION__ doesn't work in core.stdc.stdio functions without cast (PR101441)
authorIain Buclaw <ibuclaw@gdcproject.org>
Mon, 26 Jul 2021 13:24:12 +0000 (15:24 +0200)
committerIain Buclaw <ibuclaw@gdcproject.org>
Wed, 28 Jul 2021 11:27:13 +0000 (13:27 +0200)
Backports fix from upstream to allow __FUNCTION__ and
__PRETTY_FUNCTION__ to be used as C string literals.

Reviewed-on: https://github.com/dlang/dmd/pull/12923

PR d/101441

gcc/d/ChangeLog:

* dmd/expression.c (FuncInitExp::resolveLoc): Set type as `string'.
(PrettyFuncInitExp::resolveLoc): Likewise.

gcc/testsuite/ChangeLog:

* gdc.test/compilable/b19002.d: New test.

(cherry picked from commit 1a2306ffe79df89389cc850ce85c586d0f1c8264)

gcc/d/dmd/expression.c
gcc/testsuite/gdc.test/compilable/b19002.d [new file with mode: 0644]

index 7166f9724241e5328ef86dff82cb9c9404757de4..18aa6aa9ab4300a45e846ee88d37f4eb5c548b8a 100644 (file)
@@ -5620,7 +5620,7 @@ Expression *FuncInitExp::resolveLoc(Loc loc, Scope *sc)
         s = "";
     Expression *e = new StringExp(loc, const_cast<char *>(s));
     e = expressionSemantic(e, sc);
-    e = e->castTo(sc, type);
+    e->type = Type::tstring;
     return e;
 }
 
@@ -5654,7 +5654,7 @@ Expression *PrettyFuncInitExp::resolveLoc(Loc loc, Scope *sc)
 
     Expression *e = new StringExp(loc, const_cast<char *>(s));
     e = expressionSemantic(e, sc);
-    e = e->castTo(sc, type);
+    e->type = Type::tstring;
     return e;
 }
 
diff --git a/gcc/testsuite/gdc.test/compilable/b19002.d b/gcc/testsuite/gdc.test/compilable/b19002.d
new file mode 100644 (file)
index 0000000..fd8e6d1
--- /dev/null
@@ -0,0 +1,12 @@
+module b19002;
+
+void printf(scope const char* format){}
+
+void main()
+{
+    printf(__FILE__);
+    printf(__FILE_FULL_PATH__);
+    printf(__FUNCTION__);
+    printf(__PRETTY_FUNCTION__);
+    printf(__MODULE__);
+}