Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -1393,6 +1393,8 @@ HelpText<"Do not include column number on diagnostics">; def fno_show_source_location : Flag<["-"], "fno-show-source-location">, Group, Flags<[CC1Option]>, HelpText<"Do not include source location information with diagnostics">; +def fno_shrink_wrap : Flag<["-"], "fno-shrink-wrap">, Group, + Flags<[CC1Option]>, HelpText<"Disable shrink wrapping">; def fdiagnostics_absolute_paths : Flag<["-"], "fdiagnostics-absolute-paths">, Group, Flags<[CC1Option, CoreOption]>, HelpText<"Print absolute paths in diagnostics">; def fno_spell_checking : Flag<["-"], "fno-spell-checking">, Group, Index: include/clang/Frontend/CodeGenOptions.def =================================================================== --- include/clang/Frontend/CodeGenOptions.def +++ include/clang/Frontend/CodeGenOptions.def @@ -216,6 +216,7 @@ CODEGENOPT(TimePasses , 1, 0) ///< Set when -ftime-report is enabled. CODEGENOPT(UnrollLoops , 1, 0) ///< Control whether loops are unrolled. CODEGENOPT(RerollLoops , 1, 0) ///< Control whether loops are rerolled. +CODEGENOPT(NoShrinkWrap , 1, 0) ///< Set when -fno-shrink-wrap is enabled. CODEGENOPT(NoUseJumpTables , 1, 0) ///< Set when -fno-jump-tables is enabled. CODEGENOPT(UnsafeFPMath , 1, 0) ///< Allow unsafe floating point optzns. CODEGENOPT(UnwindTables , 1, 0) ///< Emit unwind tables. Index: lib/CodeGen/CodeGenFunction.cpp =================================================================== --- lib/CodeGen/CodeGenFunction.cpp +++ lib/CodeGen/CodeGenFunction.cpp @@ -935,6 +935,11 @@ } } + // Add no-shrink-wrap value. + if (CGM.getCodeGenOpts().NoShrinkWrap) + Fn->addFnAttr("no-shrink-wrap", + llvm::toStringRef(CGM.getCodeGenOpts().NoShrinkWrap)); + // Add no-jump-tables value. Fn->addFnAttr("no-jump-tables", llvm::toStringRef(CGM.getCodeGenOpts().NoUseJumpTables)); Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -4054,6 +4054,9 @@ Args.AddLastArg(CmdArgs, options::OPT_ftrap_function_EQ); + if (Args.hasArg(options::OPT_fno_shrink_wrap)) + CmdArgs.push_back("-fno-shrink-wrap"); + // -fno-strict-overflow implies -fwrapv if it isn't disabled, but // -fstrict-overflow won't turn off an explicitly enabled -fwrapv. if (Arg *A = Args.getLastArg(options::OPT_fwrapv, options::OPT_fno_wrapv)) { Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -743,6 +743,8 @@ Opts.MergeFunctions = Args.hasArg(OPT_fmerge_functions); + Opts.NoShrinkWrap = Args.hasArg(OPT_fno_shrink_wrap); + Opts.NoUseJumpTables = Args.hasArg(OPT_fno_jump_tables); Opts.ProfileSampleAccurate = Args.hasArg(OPT_fprofile_sample_accurate); Index: test/CodeGen/noshrinkwrapping.c =================================================================== --- /dev/null +++ test/CodeGen/noshrinkwrapping.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -S -fno-shrink-wrapping %s -emit-llvm -o - | FileCheck %s + +// CHECK-LABEL: main +// CHECK: attributes #0 = {{.*}}"no-shrink-wrapping"="true"{{.*}} + +int main() { + return 0; +}