Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -1032,7 +1032,9 @@ HelpText<"Like -finstrument-functions, but insert the calls after inlining">; def finstrument_function_entry_bare : Flag<["-"], "finstrument-function-entry-bare">, Group, Flags<[CC1Option]>, HelpText<"Instrument function entry only, after inlining, without arguments to the instrumentation call">; - +def finstrument_control_flow : Flag<["-"], "finstrument-control-flow">, + Group, Flags<[CC1Option]>, + HelpText<"Instrument control flow instructions for indirect branch tracking">; def fxray_instrument : Flag<["-"], "fxray-instrument">, Group, Flags<[CC1Option]>, HelpText<"Generate XRay instrumentation sleds on function entry and exit">; Index: include/clang/Frontend/CodeGenOptions.def =================================================================== --- include/clang/Frontend/CodeGenOptions.def +++ include/clang/Frontend/CodeGenOptions.def @@ -80,7 +80,8 @@ ///< -finstrument-functions-after-inlining is enabled. CODEGENOPT(InstrumentFunctionEntryBare , 1, 0) ///< Set when ///< -finstrument-function-entry-bare is enabled. - +CODEGENOPT(InstrumentControlFlow , 1, 0) ///< if -finstrument-control-flow is + ///< enabled, set the option. CODEGENOPT(XRayInstrumentFunctions , 1, 0) ///< Set when -fxray-instrument is ///< enabled. Index: lib/CodeGen/BackendUtil.cpp =================================================================== --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -435,6 +435,7 @@ Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames; Options.EmulatedTLS = CodeGenOpts.EmulatedTLS; Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning(); + Options.InstrumentControlFlow = CodeGenOpts.InstrumentControlFlow; if (CodeGenOpts.EnableSplitDwarf) Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile; Index: lib/CodeGen/CGCall.cpp =================================================================== --- lib/CodeGen/CGCall.cpp +++ lib/CodeGen/CGCall.cpp @@ -1735,6 +1735,9 @@ FuncAttrs.addAttribute("no-signed-zeros-fp-math", llvm::toStringRef(CodeGenOpts.NoSignedZeros)); FuncAttrs.addAttribute( + "instrument-control-flow", + llvm::toStringRef(CodeGenOpts.InstrumentControlFlow)); + FuncAttrs.addAttribute( "correctly-rounded-divide-sqrt-fp-math", llvm::toStringRef(CodeGenOpts.CorrectlyRoundedDivSqrt)); Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3976,6 +3976,9 @@ // Forward -cl options to -cc1 RenderOpenCLOptions(Args, CmdArgs); + if (Args.getLastArg(options::OPT_finstrument_control_flow)) { + CmdArgs.push_back("-finstrument-control-flow"); + } // Forward -f options with positive and negative forms; we translate // these by hand. Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -784,6 +784,7 @@ Args.hasArg(OPT_finstrument_functions_after_inlining); Opts.InstrumentFunctionEntryBare = Args.hasArg(OPT_finstrument_function_entry_bare); + Opts.InstrumentControlFlow = Args.hasArg(OPT_finstrument_control_flow); Opts.XRayInstrumentFunctions = Args.hasArg(OPT_fxray_instrument); Opts.XRayInstructionThreshold = getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags); Index: test/CodeGen/instrument-control-flow.c =================================================================== --- /dev/null +++ test/CodeGen/instrument-control-flow.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -S -emit-llvm -finstrument-control-flow -o - %s | FileCheck %s + +// CHECK: define void @foo() [[NUW:#[0-9]+]] +void foo(void) { +} + +// CHECK: attributes [[NUW]] = { {{.*}} "instrument-control-flow"="true" {{.*}} } Index: test/Driver/clang_f_opts.c =================================================================== --- test/Driver/clang_f_opts.c +++ test/Driver/clang_f_opts.c @@ -502,4 +502,7 @@ // RUN: %clang -### -target x86_64-unknown-windows-msvc -fno-short-wchar %s 2>&1 | FileCheck -check-prefix CHECK-WINDOWS-ISO10646 %s // CHECK-WINDOWS-ISO10646: "-fwchar-type=int" // CHECK-WINDOWS-ISO10646: "-fsigned-wchar" - +// RUN: %clang -### -S -finstrument-control-flow %s 2>&1 | FileCheck -check-prefix=CHECK-INSTRUMENT-CONTROL-FLOW %s +// RUN: %clang -### -S %s 2>&1 | FileCheck -check-prefix=CHECK-NO-INSTRUMENT-CONTROL-FLOW %s +// CHECK-INSTRUMENT-CONTROL-FLOW: -finstrument-control-flow +// CHECK-NO-INSTRUMENT-CONTROL-FLOW-NOT: -finstrument-control-flow