From 9b847128c8ac1d6f8abe346642b36a3f5823ec7d Mon Sep 17 00:00:00 2001 From: RazvanN7 Date: Thu, 3 Aug 2023 12:36:58 +0300 Subject: [PATCH] Fix Issue 24065 - __traits(getTargetInfo) causes a segfault when passed a non value --- compiler/src/dmd/traits.d | 2 +- compiler/test/fail_compilation/test24065.d | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 compiler/test/fail_compilation/test24065.d diff --git a/compiler/src/dmd/traits.d b/compiler/src/dmd/traits.d index 21ec3ab0e189..28f459916b97 100644 --- a/compiler/src/dmd/traits.d +++ b/compiler/src/dmd/traits.d @@ -1909,7 +1909,7 @@ Expression semanticTraits(TraitsExp e, Scope* sc) StringExp se = ex ? ex.ctfeInterpret().toStringExp() : null; if (!ex || !se || se.len == 0) { - e.error("string expected as argument of __traits `%s` instead of `%s`", e.ident.toChars(), ex.toChars()); + e.error("string expected as argument of __traits `%s` instead of `%s`", e.ident.toChars(), (*e.args)[0].toChars()); return ErrorExp.get(); } se = se.toUTF8(sc); diff --git a/compiler/test/fail_compilation/test24065.d b/compiler/test/fail_compilation/test24065.d new file mode 100644 index 000000000000..9e4ebbf4d163 --- /dev/null +++ b/compiler/test/fail_compilation/test24065.d @@ -0,0 +1,18 @@ +// https://issues.dlang.org/show_bug.cgi?id=24065 + +/* +TEST_OUTPUT: +--- +fail_compilation/test24065.d(12): Error: string expected as argument of __traits `getTargetInfo` instead of `int` +fail_compilation/test24065.d(15): Error: string expected as argument of __traits `getTargetInfo` instead of `foo` +fail_compilation/test24065.d(18): Error: string expected as argument of __traits `getTargetInfo` instead of `e` +--- +*/ + +auto s1 = __traits(getTargetInfo, int); + +void foo() {} +auto s2 = __traits(getTargetInfo, foo); + +enum e; +auto s3 = __traits(getTargetInfo, e);