This is an archive of the discontinued LLVM Phabricator instance.

[WIP][clang][cli] Test manual header search argument generation with round-trip
AbandonedPublic

Authored by jansvoboda11 on Jan 12 2021, 1:30 AM.

Details

Summary

This patch tests the manual header search argument generation by performing a "parse, generate, parse" round-trip on each compiler invocation. This way, the manually written C++ code gets exercised by the suite of Clang's end-to-end tests. Moreover, this ensures people adding new command line options are forced to implement the generation as well, either via the TableGen marshalling infrastructure or manually in CompilerInvocation.

It makes sense to enable this only for assert builds, so that we don't perform useless work in release builds.

Depending on our roll-out strategy, we might create more patches like this for other groups of options and upstream the work one-by-one, or put all option groups into this patch and enable round-tripping for all of -cc1 in a single commit.

Please note this is a work-in-progress. Ideally, we'll be able to get rid of the duplicate methods (parseSimpleArgs, generateCC1CommandLine, AddAllArgsExcept) and the HeaderSearchOptSpecs array.

Depends on D94472.

Diff Detail

Event Timeline

jansvoboda11 created this revision.Jan 12 2021, 1:30 AM
jansvoboda11 requested review of this revision.Jan 12 2021, 1:30 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJan 12 2021, 1:30 AM
jansvoboda11 planned changes to this revision.Jan 12 2021, 1:30 AM

Marking this as "Changes Planned" to not occupy reviewers' Ready to Review queue.

jansvoboda11 edited the summary of this revision. (Show Details)Jan 12 2021, 1:32 AM
jansvoboda11 edited the summary of this revision. (Show Details)
dexonsmith added inline comments.Jan 12 2021, 10:29 AM
clang/include/clang/Frontend/CompilerInvocation.h
199–203

You can avoid the duplication at least for the WIP with:

void generateCC1CommandLine(llvm::SmallVectorImpl<const char *> &Args,
                              StringAllocator SA,
                              ArrayRef<llvm::opt::OptSpecifier> Included = None) const;

and then in the body:

auto IsIncluded = Included.empty()
    ? [](OptSpecifier) { return true; }
    : [&Included](OptSpecifier Opt) { return Included.count(Opt); };

// ...
if (... && IsIncluded(Opt)) {

I'm wondering if we can get this in incrementally without needing to list in code which options are correctly handled. Here's one way to do it:

  • Add a tool, clang-cc1-args, that shows the diff between round-tripping when given a set of args. (This could potentially grow other functionality vs. diffing. So maybe clang-cc1-args diff [args] would be the usage?)
  • Add RUN lines to tests that test the args we think should round-trip correctly and confirm there's no diff. This can be done incrementally as options get handled.
  • Only once we think we have all the options covered, add the assertion from this patch.
jansvoboda11 abandoned this revision.Jan 15 2021, 10:02 AM

Hmm, that would still require us to keep a list of options we've converted. It's better than hard-coding it like this patch does, but I'd like it to be more automatic.

I've updated D94472 with my initial implementation of more hands-off solution. The gist is that the original ArgList instance constructs set of options the CompilerInvocation queries during parsing. This will tell us which options we should be able to generate and which we shouldn't need to copy from the original argument list to the new one via AddAllArgsXxx.

Abandoning this patch as per your suggestion to merge round-tripping with the actual command line generation.