This is an archive of the discontinued LLVM Phabricator instance.

[Driver] Add compiler option to generate a reproducer
ClosedPublic

Authored by bruno on Dec 8 2016, 6:05 PM.

Details

Summary

One way to currently test the reproducers is to setup
"FORCE_CLANG_DIAGNOSTICS_CRASH=1" before invoking clang. This simulates
a crash and produces the same contents needed by the reproducers.

The reproducers are specially useful when triaging Modules issues, not
only on crashes, but also for reproducing misleading warnings, errors,
etc. I propose we add '-gen-reproducer' driver option to clang (or
any similar name) and give users a flag option.

Additionally, clang already have -fno-crash-diagnostics, which disables
the crash reproducers. I've decided not to propose "-fcrash-diagnostics"
since it doesn't convey the ideia of reproduction despite a crash.

Diff Detail

Event Timeline

bruno updated this revision to Diff 80852.Dec 8 2016, 6:05 PM
bruno retitled this revision from to [Driver] Add compiler option to generate a reproducer.
bruno updated this object.
bruno added reviewers: rsmith, v.g.vassilev.
bruno added subscribers: cfe-commits, mehdi_amini.
v.g.vassilev edited edge metadata.Dec 9 2016, 4:45 AM

Thanks for working on this, Bruno!

This would be a useful feature to us, too.

I am wondering if there is clearer name than -gen-reproducer.

IIUC, the goal is to extract all environment (system) dependent pieces, copying them to a folder where the compiler can be chroot-ed (via -isysroot). In some sense, what we do seems close to what -header-include-file list_of_includes.txt does and additionally copying the contents of the list_of_includes.txt (and possibly mounting a vfs overlay).

EricWF added a subscriber: EricWF.Dec 9 2016, 7:28 AM
mehdi_amini added inline comments.Dec 9 2016, 9:29 AM
include/clang/Basic/DiagnosticDriverKinds.td
95

Is it worth it? What about "failing because %1 is set">;

And then later:

Diags.Report(diag::err_drv_force_crash) << "option '-gen-reproducer'";
bruno added a comment.Dec 9 2016, 4:56 PM

I am wondering if there is clearer name than -gen-reproducer.

Probably, I'm open to suggestions :-)

IIUC, the goal is to extract all environment (system) dependent pieces, copying them to a folder where the compiler can be chroot-ed (via -isysroot).

It doesn't necessarily needs a -isysroot to work, only if the original invocation used it, then we need to use it as well to ask the VFS (transparently) for the right path locations.

In some sense, what we do seems close to what -header-include-file list_of_includes.txt does and additionally copying the contents of the list_of_includes.txt (and possibly mounting a vfs overlay).

-header-include-file does something similar but more limited, I added some specific callbacks for the module collector back in the day that it might not collect yet though, for instance, it collects module.modulemap's and will soon collect header maps and some other stuff.

It also has some special handling for symlinks; it doesn't copy both files, but generate two yaml entries that point to the same "physical" location.

bruno updated this revision to Diff 80981.Dec 9 2016, 4:58 PM
bruno edited edge metadata.

Update after Mehdi's review!

v.g.vassilev accepted this revision.Jan 29 2017, 4:49 AM

My questions were answered. LGTM!

This revision is now accepted and ready to land.Jan 29 2017, 4:49 AM
rsmith accepted this revision.Apr 11 2017, 11:59 AM

LGTM with one change.

include/clang/Basic/DiagnosticDriverKinds.td
95

Even though we don't have translations for our diagnostics, it's intended that they be translatable, so you should not hardcode strings like "option " and "environment variable " in the code. Use a %select here instead, maybe? (See http://clang.llvm.org/docs/InternalsManual.html#the-format-string)

This revision was automatically updated to reflect the committed changes.