Skip to content

Commit 2be5698

Browse files
committed
[clang][cli] Add ability to make fixups to CompilerInvocation after option parsing
Depends on D83211 Reviewed By: Bigcheese Original patch by Daniel Grumberg. Differential Revision: https://reviews.llvm.org/D83298
1 parent 83a0386 commit 2be5698

2 files changed

Lines changed: 17 additions & 23 deletions

File tree

‎clang/include/clang/Driver/Options.td‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ def fcf_protection : Flag<["-"], "fcf-protection">, Group<f_Group>, Flags<[CoreO
13471347
Alias<fcf_protection_EQ>, AliasArgs<["full"]>,
13481348
HelpText<"Enable cf-protection in 'full' mode">;
13491349

1350-
defm xray_instrument : OptInFFlag<"xray-instrument", "Generate XRay instrumentation sleds on function entry and exit">;
1350+
defm xray_instrument : OptInFFlag<"xray-instrument", "Generate XRay instrumentation sleds on function entry and exit", "", "", [], "LangOpts->XRayInstrument">;
13511351

13521352
def fxray_instruction_threshold_EQ :
13531353
JoinedOrSeparate<["-"], "fxray-instruction-threshold=">,
@@ -1375,15 +1375,15 @@ def fxray_modes :
13751375
HelpText<"List of modes to link in by default into XRay instrumented binaries.">;
13761376

13771377
defm xray_always_emit_customevents : OptInFFlag<"xray-always-emit-customevents",
1378-
"Always emit __xray_customevent(...) calls even if the containing function is not always instrumented">;
1378+
"Always emit __xray_customevent(...) calls even if the containing function is not always instrumented", "", "", [], "LangOpts->XRayAlwaysEmitCustomEvents">;
13791379

13801380
defm xray_always_emit_typedevents : OptInFFlag<"xray-always-emit-typedevents",
1381-
"Always emit __xray_typedevent(...) calls even if the containing function is not always instrumented">;
1381+
"Always emit __xray_typedevent(...) calls even if the containing function is not always instrumented", "", "", [], "LangOpts->XRayAlwaysEmitTypedEvents">;
13821382

13831383
defm xray_ignore_loops : OptInFFlag<"xray-ignore-loops",
1384-
"Don't instrument functions with loops unless they also meet the minimum function size">;
1384+
"Don't instrument functions with loops unless they also meet the minimum function size", "", "", [], "CodeGenOpts.XRayIgnoreLoops">;
13851385
defm xray_function_index : OptOutFFlag<"xray-function-index", "",
1386-
"Omit function index section at the expense of single-function patching performance">;
1386+
"Omit function index section at the expense of single-function patching performance", "", [], "CodeGenOpts.XRayOmitFunctionIndex">;
13871387

13881388
def fxray_link_deps : Flag<["-"], "fxray-link-deps">, Group<f_Group>,
13891389
Flags<[CC1Option]>,

‎clang/lib/Frontend/CompilerInvocation.cpp‎

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,17 @@ static T extractMaskValue(T KeyPath) {
245245
return KeyPath & Value;
246246
}
247247

248+
static void FixupInvocation(CompilerInvocation &Invocation) {
249+
LangOptions &LangOpts = *Invocation.getLangOpts();
250+
DiagnosticOptions &DiagOpts = Invocation.getDiagnosticOpts();
251+
CodeGenOptions &CodeGenOpts = Invocation.getCodeGenOpts();
252+
CodeGenOpts.XRayInstrumentFunctions = LangOpts.XRayInstrument;
253+
CodeGenOpts.XRayAlwaysEmitCustomEvents = LangOpts.XRayAlwaysEmitCustomEvents;
254+
CodeGenOpts.XRayAlwaysEmitTypedEvents = LangOpts.XRayAlwaysEmitTypedEvents;
255+
256+
llvm::sys::Process::UseANSIEscapeCodes(DiagOpts.UseANSIEscapeCodes);
257+
}
258+
248259
//===----------------------------------------------------------------------===//
249260
// Deserialization (from args)
250261
//===----------------------------------------------------------------------===//
@@ -1189,16 +1200,8 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
11891200
Opts.InstrumentFunctionEntryBare =
11901201
Args.hasArg(OPT_finstrument_function_entry_bare);
11911202

1192-
Opts.XRayInstrumentFunctions =
1193-
Args.hasArg(OPT_fxray_instrument);
1194-
Opts.XRayAlwaysEmitCustomEvents =
1195-
Args.hasArg(OPT_fxray_always_emit_customevents);
1196-
Opts.XRayAlwaysEmitTypedEvents =
1197-
Args.hasArg(OPT_fxray_always_emit_typedevents);
11981203
Opts.XRayInstructionThreshold =
11991204
getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags);
1200-
Opts.XRayIgnoreLoops = Args.hasArg(OPT_fxray_ignore_loops);
1201-
Opts.XRayOmitFunctionIndex = Args.hasArg(OPT_fno_xray_function_index);
12021205
Opts.XRayTotalFunctionGroups =
12031206
getLastArgIntValue(Args, OPT_fxray_function_groups, 1, Diags);
12041207
Opts.XRaySelectedFunctionGroup =
@@ -3447,13 +3450,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
34473450
systemBlacklists.begin(),
34483451
systemBlacklists.end());
34493452

3450-
// -fxray-instrument
3451-
Opts.XRayInstrument = Args.hasArg(OPT_fxray_instrument);
3452-
Opts.XRayAlwaysEmitCustomEvents =
3453-
Args.hasArg(OPT_fxray_always_emit_customevents);
3454-
Opts.XRayAlwaysEmitTypedEvents =
3455-
Args.hasArg(OPT_fxray_always_emit_typedevents);
3456-
34573453
// -fxray-{always,never}-instrument= filenames.
34583454
Opts.XRayAlwaysInstrumentFiles =
34593455
Args.getAllArgValues(OPT_fxray_always_instrument);
@@ -3827,9 +3823,7 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
38273823
}
38283824

38293825
Success &= Res.parseSimpleArgs(Args, Diags);
3830-
3831-
llvm::sys::Process::UseANSIEscapeCodes(
3832-
Res.DiagnosticOpts->UseANSIEscapeCodes);
3826+
FixupInvocation(Res);
38333827

38343828
Success &= ParseAnalyzerArgs(*Res.getAnalyzerOpts(), Args, Diags);
38353829
Success &= ParseMigratorArgs(Res.getMigratorOpts(), Args);

0 commit comments

Comments
 (0)