[PATCH] D47829: [Driver] Accept the -fno-shrink-wrap option for GCC compatibility

Simon Dardis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 12 02:26:19 PDT 2018


sdardis updated this revision to Diff 150904.
sdardis added a comment.

Modify implementation to produce a function attribute.


Repository:
  rC Clang

https://reviews.llvm.org/D47829

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CodeGenFunction.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/noshrinkwrapping.c


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;
+}
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: 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/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: 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: 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<f_Group>,
   Flags<[CC1Option]>, HelpText<"Do not include source location information with diagnostics">;
+def fno_shrink_wrap : Flag<["-"], "fno-shrink-wrap">, Group<f_Group>,
+  Flags<[CC1Option]>, HelpText<"Disable shrink wrapping">;
 def fdiagnostics_absolute_paths : Flag<["-"], "fdiagnostics-absolute-paths">, Group<f_Group>,
   Flags<[CC1Option, CoreOption]>, HelpText<"Print absolute paths in diagnostics">;
 def fno_spell_checking : Flag<["-"], "fno-spell-checking">, Group<f_Group>,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47829.150904.patch
Type: text/x-patch
Size: 3571 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180612/086ba133/attachment-0001.bin>


More information about the cfe-commits mailing list