This is an archive of the discontinued LLVM Phabricator instance.

[clang][cli] Parse Lang and CodeGen options separately
ClosedPublic

Authored by jansvoboda11 on Jan 14 2021, 4:58 AM.

Details

Summary

This patch moves the parsing of {Lang,CodeGen}Options from parseSimpleArgs to the original Parse{Lang,CodeGen}Args functions.

This ensures all marshalled LangOptions are being parsed after the call setLangDefaults, which in turn enables us to marshall LangOptions that somehow depend on the defaults. (In a future patch.)

Now, CodeGenOptions need to be parsed after LangOptions, because -cl-mad-enable (a CodeGenOpt) depends on the value of -cl-fast-relaxed-math and -cl-unsafe-math-optimizations (LangOpts).

Unfortunately, this removes the nice property that marshalled options get parsed in the exact order they appear in the .td file. Now we cannot be sure that a TableGen record referenced in ImpliedByAnyOf has already been parsed. This might cause an ordering issues (i.e. reading value of uninitialized variable). I plan to mitigate this by moving each XxxOpt group from parseSimpleArgs back to their original parsing function. With this setup, if an option from group A references option from group B in TableGen, the compiler will require us to make the CompilerInvocation member for B visible in the parsing function for A. That's where we notice that B didn't get parsed yet.

Diff Detail

Event Timeline

jansvoboda11 created this revision.Jan 14 2021, 4:58 AM
jansvoboda11 requested review of this revision.Jan 14 2021, 4:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 14 2021, 4:58 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
jansvoboda11 edited the summary of this revision. (Show Details)Jan 14 2021, 6:11 AM

Stop setting the default for LaxVectorConversions in CompilerInvocation

jansvoboda11 added inline comments.Jan 14 2021, 9:02 AM
clang/include/clang/Driver/Options.td
1831

This replaces the conditional in CompilerInvocation::setLangDefaults.

The enum cases need to be fully qualified now, because we can't use NormalizedValuesScope<"LangOptions::LaxVectorConversionKind"> due to the "arbitrary" expression for default value.

clang/test/Frontend/diagnostics-order.c
12

The order of these diagnostics depends on the order of argument parsing. Because we've moved CodeGenOpts parsing after LangOpts, this needs to be adjusted.

This revision is now accepted and ready to land.Jan 14 2021, 9:16 AM
This revision was landed with ongoing or failed builds.Jan 19 2021, 12:53 AM
This revision was automatically updated to reflect the committed changes.

Committed with the parsing macro moved to the top of the file as discussed with Michael. This will make following patches cleaner.