This is an archive of the discontinued LLVM Phabricator instance.

Generate Libclang invocation reproducers using a new -cc1gen-reproducer option
ClosedPublic

Authored by arphaman on Dec 7 2017, 1:46 PM.

Details

Summary

This patch is a follow up to the previous work that recorded Libclang invocations into temporary files: https://reviews.llvm.org/D40527.

It adds a new -cc1 mode to clang: -cc1gen-reproducer. The goal of this mode is to generate Clang reproducer files for Libclang tool invocation. The JSON format in the invocation files is not really intended to be stable, so Libclang and Clang should be of the same version when generating reproducers.
The new mode emits the information about the temporary files in the reproducers to stdout using JSON. It also injects additional Libclang-specific information about the reproducer to the reproducer's .sh files.

Thanks for taking a look!

Diff Detail

Repository
rL LLVM

Event Timeline

arphaman created this revision.Dec 7 2017, 1:46 PM
bruno added a comment.Dec 18 2017, 2:19 PM

Hi Alex,

Thanks for improving this.

  • Instead of adding -cc1gen-reproducer, why can't you run that through -cc1 and have a flag similar to -###, which just prints the reproducer line?
  • I didn't understand how you can use the final output information, can you give an example to illustrate?
include/clang/Driver/Driver.h
394 ↗(On Diff #126032)

I assume the number of temporary files are usually small, can you switch to SmallVector here?

tools/driver/cc1gen_reproducer_main.cpp
187 ↗(On Diff #126032)

int Result = 1;
....
(no need for the else clause)

arphaman marked 2 inline comments as done.Dec 21 2017, 1:22 PM

Hi Alex,

Thanks for improving this.

  • Instead of adding -cc1gen-reproducer, why can't you run that through -cc1 and have a flag similar to -###, which just prints the reproducer line?

It would be difficult to add this logic to the regular -cc1, as it would need to construct a real compiler invocation on top of the pseudo one which takes the libclang invocation file (because it has to load the actual compiler arguments from the libclang file). This would be difficult and quite disruptive to the code in the cc1 driver and the compiler invocation. The approach in this patch is much simpler to implement and maintain, and does not disrupt the code in the cc1 driver. This patch makes it more of a tool rather than a clang driver invocation.

  • I didn't understand how you can use the final output information, can you give an example to illustrate?

Given a sample output like:

REPRODUCER:
{
"files":["/tmp/a.c","/tmp/a.sh"]
}

The tool's client (also a libclang client) will parse the JSON object with the files that make up the reproducer. It will then be able to do whatever it needs with those specific files.

include/clang/Driver/Driver.h
394 ↗(On Diff #126032)

Yep.

arphaman updated this revision to Diff 127935.Dec 21 2017, 1:22 PM
arphaman marked an inline comment as done.

Address review comments

bruno accepted this revision.Jan 5 2018, 2:02 PM

Makes sense, LGTM.

Should we add documentation explaining how to use this? I'm fine if it comes in a follow up commit.

This revision is now accepted and ready to land.Jan 5 2018, 2:02 PM

Makes sense, LGTM.

Should we add documentation explaining how to use this? I'm fine if it comes in a follow up commit.

Sorry, just got time to get back to this now. Thanks for the review! I'll add a document for this new functionality tomorrow.

Makes sense, LGTM.

Should we add documentation explaining how to use this? I'm fine if it comes in a follow up commit.

Sorry, just got time to get back to this now. Thanks for the review! I'll add a document for this new functionality tomorrow.

  • In a follow-up commit tomorrow.
This revision was automatically updated to reflect the committed changes.