From 77619231ca2d8082bc2fa85162f7734ce8064f5e Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Thu, 5 Apr 2018 04:55:30 +0200 Subject: [PATCH] Point users to Bugzilla on ICEs --- src/dmd/backend/util2.c | 3 ++ src/dmd/mars.d | 97 ++++++++++++++++++++++++-------------- test/runnable/test18141.sh | 3 +- 3 files changed, 67 insertions(+), 36 deletions(-) diff --git a/src/dmd/backend/util2.c b/src/dmd/backend/util2.c index 05c1c1b30963..8a794ab262fe 100644 --- a/src/dmd/backend/util2.c +++ b/src/dmd/backend/util2.c @@ -38,6 +38,8 @@ void *ph_calloc(size_t nbytes); void ph_free(void *p); void *ph_realloc(void *p , size_t nbytes); +extern "C" void printInternalFailure(FILE* stream); // from dmd/mars.d + void util_exit(int exitcode); @@ -52,6 +54,7 @@ void file_progress() void util_assert(const char *file, int line) { fflush(stdout); + printInternalFailure(stdout); printf("Internal error: %s %d\n",file,line); err_exit(); #if __clang__ diff --git a/src/dmd/mars.d b/src/dmd/mars.d index 1a7ad3f9eb54..f55dd5136a89 100644 --- a/src/dmd/mars.d +++ b/src/dmd/mars.d @@ -70,6 +70,25 @@ private void logo() printf("DMD%llu D Compiler %s\n%s %s\n", cast(ulong)size_t.sizeof * 8, global._version, global.copyright, global.written); } +/** +Print DMD's logo with more debug information and error-reporting pointers. + +Params: + stream = output stream to print the information on +*/ +extern(C) void printInternalFailure(FILE* stream) +{ + fputs(("---\n" ~ + "ERROR: This is a compiler bug.\n" ~ + "Please report it via https://issues.dlang.org/enter_bug.cgi\n" ~ + "with, preferably, a reduced, reproducible example and the information below.\n" ~ + "DustMite (https://github.com/CyberShadow/DustMite/wiki) can help with the reduction.\n" ~ + "---\n").ptr, stream); + stream.fprintf("DMD %s\n", global._version); + stream.printPredefinedVersions; + stream.printGlobalConfigs(); + fputs("---\n".ptr, stream); +} /** * Print DMD's usage message on stdout @@ -495,40 +514,10 @@ private int tryMain(size_t argc, const(char)** argv) Objc._init(); builtin_init(); - printPredefinedVersions(); - if (global.params.verbose) { - message("binary %s", global.params.argv0); - message("version %s", global._version); - message("config %s", global.inifilename ? global.inifilename : "(none)"); - // Print DFLAGS environment variable - { - Strings dflags; - getenv_setargv(readFromEnv(&environment, "DFLAGS"), &dflags); - OutBuffer buf; - foreach (flag; dflags.asDArray) - { - bool needsQuoting; - for (auto flagp = flag; flagp; flagp++) - { - auto c = flagp[0]; - if (!(isalnum(c) || c == '_')) - { - needsQuoting = true; - break; - } - } - - if (flag.strchr(' ')) - buf.printf("'%s' ", flag); - else - buf.printf("%s ", flag); - } - - auto res = buf.peekSlice() ? buf.peekSlice()[0 .. $ - 1] : "(none)"; - message("DFLAGS %.*s", res.length, res.ptr); - } + stdout.printPredefinedVersions(); + stdout.printGlobalConfigs(); } //printf("%d source files\n",files.dim); @@ -1094,6 +1083,8 @@ int main() dmd_coverSetMerge(true); } + scope(failure) stderr.printInternalFailure; + auto args = Runtime.cArgs(); return tryMain(args.argc, cast(const(char)**)args.argv); } @@ -1406,9 +1397,9 @@ void addDefaultVersionIdentifiers() VersionCondition.addPredefinedGlobalIdent("D_HardFloat"); } -private void printPredefinedVersions() +private void printPredefinedVersions(FILE* stream) { - if (global.params.verbose && global.versionids) + if (global.versionids) { OutBuffer buf; foreach (const str; *global.versionids) @@ -1416,10 +1407,46 @@ private void printPredefinedVersions() buf.writeByte(' '); buf.writestring(str.toChars()); } - message("predefs %s", buf.peekString()); + stream.fprintf("predefs %s", buf.peekString()); } } +extern(C) void printGlobalConfigs(FILE* stream) +{ + stream.fprintf("binary %s\n", global.params.argv0); + stream.fprintf("version %s\n", global._version); + stream.fprintf("config %s\n", global.inifilename ? global.inifilename : "(none)"); + // Print DFLAGS environment variable + { + StringTable environment; + environment._init(0); + Strings dflags; + getenv_setargv(readFromEnv(&environment, "DFLAGS"), &dflags); + environment.reset(1); + OutBuffer buf; + foreach (flag; dflags.asDArray) + { + bool needsQuoting; + for (auto flagp = flag; flagp; flagp++) + { + auto c = flagp[0]; + if (!(isalnum(c) || c == '_')) + { + needsQuoting = true; + break; + } + } + + if (flag.strchr(' ')) + buf.printf("'%s' ", flag); + else + buf.printf("%s ", flag); + } + + auto res = buf.peekSlice() ? buf.peekSlice()[0 .. $ - 1] : "(none)"; + stream.fprintf("DFLAGS %.*s\n", res.length, res.ptr); + } +} /**************************************** * Determine the instruction set to be used. diff --git a/test/runnable/test18141.sh b/test/runnable/test18141.sh index e2922d2b19ed..62f46a24f692 100755 --- a/test/runnable/test18141.sh +++ b/test/runnable/test18141.sh @@ -6,4 +6,5 @@ else expected="Posix" fi -echo "void main(){}" | "${DMD}" -v -o- - | grep "predefs" | grep "${expected}" +out=$(echo "void main(){}" | "${DMD}" -v -o- -) +echo "$out" | grep "predefs" | grep "${expected}"