[clang] ee7fb36 - [Driver] Fix -f[no-]inline to override -f[no-]inline-functions/-finline-hint-functions

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 10 00:15:17 PDT 2022


Author: Fangrui Song
Date: 2022-04-10T00:15:12-07:00
New Revision: ee7fb36ba03a75e404d1030666883e050052c5a1

URL: https://github.com/llvm/llvm-project/commit/ee7fb36ba03a75e404d1030666883e050052c5a1
DIFF: https://github.com/llvm/llvm-project/commit/ee7fb36ba03a75e404d1030666883e050052c5a1.diff

LOG: [Driver] Fix -f[no-]inline to override -f[no-]inline-functions/-finline-hint-functions

Fix two cases to match GCC:

* -fno-inline -finline => (no cc1 option)
* -fno-inline -finline-functions => -fno-inline

Added: 
    clang/test/Driver/finline.c

Modified: 
    clang/lib/Driver/ToolChains/Clang.cpp

Removed: 
    clang/test/Driver/noinline.c


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 1601dba171d26..1cb73f89e081d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6509,12 +6509,15 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
                    false))
     CmdArgs.push_back("-fgnu89-inline");
 
-  if (Args.hasArg(options::OPT_fno_inline))
-    CmdArgs.push_back("-fno-inline");
-
-  Args.AddLastArg(CmdArgs, options::OPT_finline_functions,
-                  options::OPT_finline_hint_functions,
-                  options::OPT_fno_inline_functions);
+  const Arg *InlineArg = Args.getLastArg(options::OPT_finline_functions,
+                                         options::OPT_finline_hint_functions,
+                                         options::OPT_fno_inline_functions);
+  if (Arg *A = Args.getLastArg(options::OPT_finline, options::OPT_fno_inline)) {
+    if (A->getOption().matches(options::OPT_fno_inline))
+      A->render(Args, CmdArgs);
+  } else if (InlineArg) {
+    InlineArg->render(Args, CmdArgs);
+  }
 
   // FIXME: Find a better way to determine whether the language has modules
   // support by default, or just assume that all languages do.

diff  --git a/clang/test/Driver/finline.c b/clang/test/Driver/finline.c
new file mode 100644
index 0000000000000..8eacd5e923ef0
--- /dev/null
+++ b/clang/test/Driver/finline.c
@@ -0,0 +1,15 @@
+/// -fno-inline overrides -finline-functions/-finline-hint-functions.
+// RUN: %clang -### -c --target=x86_64-apple-darwin10 -O2 -fno-inline -fno-inline-functions %s 2>&1 | FileCheck %s --check-prefix=NOINLINE
+// RUN: %clang -### -c --target=x86_64 -O2 -finline -fno-inline -finline-functions %s 2>&1 | FileCheck %s --check-prefix=NOINLINE
+// NOINLINE-NOT: "-finline-functions"
+// NOINLINE:     "-fno-inline"
+// NOINLINE-NOT: "-finline-functions"
+
+/// -finline overrides -finline-functions.
+// RUN: %clang -### -c --target=x86_64 -O2 -fno-inline -finline -finline-functions %s 2>&1 | FileCheck %s --check-prefix=INLINE
+// INLINE-NOT: "-finline-functions"
+// INLINE-NOT: "-fno-inline"
+// INLINE-NOT: "-finline"
+
+// RUN: %clang -### -c --target=aarch64 -O2 -finline-functions %s 2>&1 | FileCheck %s --check-prefix=INLINE-FUNCTIONS
+// INLINE-FUNCTIONS: "-finline-functions"

diff  --git a/clang/test/Driver/noinline.c b/clang/test/Driver/noinline.c
deleted file mode 100644
index 70f950cf52970..0000000000000
--- a/clang/test/Driver/noinline.c
+++ /dev/null
@@ -1,10 +0,0 @@
-// Make sure the driver is correctly passing -fno-inline-functions
-// rdar://10972766
-
-// RUN: %clang -target x86_64-apple-darwin10 \
-// RUN:   -fno-inline -fno-inline-functions -### -fsyntax-only %s 2> %t
-// RUN: FileCheck < %t %s
-
-// CHECK: clang
-// CHECK: "-fno-inline"
-// CHECK: "-fno-inline-functions"


        


More information about the cfe-commits mailing list