[PATCH] D30920: Do not pass -Os and -Oz to the Gold plugin

Pirama Arumuga Nainar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 13 16:12:47 PDT 2017


pirama created this revision.
Herald added a subscriber: mehdi_amini.

Address PR32155: Skip passing -Os and -Oz to the Gold plugin using
-plugin-opt.


https://reviews.llvm.org/D30920

Files:
  lib/Driver/ToolChains/CommonArgs.cpp
  test/Driver/gold-lto.c


Index: test/Driver/gold-lto.c
===================================================================
--- test/Driver/gold-lto.c
+++ test/Driver/gold-lto.c
@@ -26,3 +26,9 @@
 // RUN: %clang -target i686-linux-android -### %t.o -flto 2>&1 \
 // RUN:     | FileCheck %s --check-prefix=CHECK-X86-ANDROID
 // CHECK-X86-ANDROID: "-plugin" "{{.*}}/LLVMgold.so"
+//
+// Test that -Os and -Oz are not passed to the plugin
+// RUN: %clang -### %t.o -flto -Os 2>&1 \
+// RUN:     | FileCheck %s --implicit-check-not "-plugin-opt=Os"
+// RUN: %clang -### %t.o -flto -Os 2>&1 \
+// RUN:     | FileCheck %s --implicit-check-not "-plugin-opt=Oz"
Index: lib/Driver/ToolChains/CommonArgs.cpp
===================================================================
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -366,12 +366,17 @@
   if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
     StringRef OOpt;
     if (A->getOption().matches(options::OPT_O4) ||
-        A->getOption().matches(options::OPT_Ofast))
+        A->getOption().matches(options::OPT_Ofast)) {
       OOpt = "3";
-    else if (A->getOption().matches(options::OPT_O))
-      OOpt = A->getValue();
-    else if (A->getOption().matches(options::OPT_O0))
+    } else if (A->getOption().matches(options::OPT_O)) {
+      StringRef OptLevel = A->getValue();
+      // Do not pass optimization levels pertaining to code size to the plugin.
+      // They are captured by corresponding function attributes.
+      if (!OptLevel.equals("s") && !OptLevel.equals("z"))
+        OOpt = OptLevel;
+    } else if (A->getOption().matches(options::OPT_O0)) {
       OOpt = "0";
+    }
     if (!OOpt.empty())
       CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=O") + OOpt));
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30920.91642.patch
Type: text/x-patch
Size: 1763 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170313/f3907faa/attachment.bin>


More information about the cfe-commits mailing list