Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/dmd/backend/util2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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__
Expand Down
96 changes: 61 additions & 35 deletions src/dmd/mars.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -1406,20 +1397,55 @@ 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)
{
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[])
{
bool needsQuoting;
foreach (c; flag[0 .. strlen(flag)])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly readFrom calls getenv which returns a boring, old C-string.

{
if (!(isalnum(c) || c == '_'))
{
needsQuoting = true;
break;
}
}

if (flag.strchr(' '))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that be if (needsquoting) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but I just moved the code - check the red part on the left.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently it's not that easy (breaks a test), so I will modify this in a different PR.

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.
Expand Down
3 changes: 2 additions & 1 deletion test/runnable/test18141.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"