]> granicus.if.org Git - clang/commitdiff
[clang][slh] Forward mSLH only to Clang CC1
authorZola Bridges <zbrid@google.com>
Mon, 26 Nov 2018 18:13:31 +0000 (18:13 +0000)
committerZola Bridges <zbrid@google.com>
Mon, 26 Nov 2018 18:13:31 +0000 (18:13 +0000)
Summary:
-mno-speculative-load-hardening isn't a cc1 option, therefore,
before this change:

clang -mno-speculative-load-hardening hello.cpp

would have the following error:

error: unknown argument: '-mno-speculative-load-hardening'

This change will only ever forward -mspeculative-load-hardening
which is a CC1 option based on which flag was passed to clang.

Also added a test that uses this option that fails if an error like the
above is ever thrown.

Thank you ericwf for help debugging and fixing this error.

Reviewers: chandlerc, EricWF

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D54763

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347582 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/ToolChains/Clang.cpp
test/CodeGen/attr-speculative-load-hardening.c

index 9a36f7b429c397505b53dcd0091146856335ae95..6b2083ce02500c337d1f648c69b56ef6b58a10b5 100644 (file)
@@ -4452,8 +4452,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
 
   Args.AddLastArg(CmdArgs, options::OPT_pthread);
 
-  Args.AddLastArg(CmdArgs, options::OPT_mspeculative_load_hardening,
-                  options::OPT_mno_speculative_load_hardening);
+  if (Args.hasFlag(options::OPT_mspeculative_load_hardening, options::OPT_mno_speculative_load_hardening,
+                   false))
+    CmdArgs.push_back(Args.MakeArgString("-mspeculative-load-hardening"));
 
   RenderSSPOptions(TC, Args, CmdArgs, KernelOrKext);
 
index ccbded44bb47064e7eb784497d58b311e2f41684..97bccd03585c3945f2a03516a3d77ce9fe4741ba 100644 (file)
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -mspeculative-load-hardening -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s -check-prefix=SLH
+// RUN: %clang -mno-speculative-load-hardening -S -emit-llvm %s -o - | FileCheck %s -check-prefix=NOSLH
 //
 // Check that we set the attribute on each function.
 
@@ -8,3 +9,7 @@ int test1() {
 // SLH: @{{.*}}test1{{.*}}[[SLH:#[0-9]+]]
 
 // SLH: attributes [[SLH]] = { {{.*}}speculative_load_hardening{{.*}} }
+
+// NOSLH: @{{.*}}test1{{.*}}[[NOSLH:#[0-9]+]]
+
+// NOSLH-NOT: attributes [[SLH]] = { {{.*}}speculative_load_hardening{{.*}} }