[clang] aed488e - [Driver] Move -fsemantic-interposition decision from cc1 to driver

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 2 20:45:37 PST 2020


Author: Fangrui Song
Date: 2020-02-02T20:45:29-08:00
New Revision: aed488e3a4dfdf15696521e13ac5e6ac2f9e7af7

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

LOG: [Driver] Move -fsemantic-interposition decision from cc1 to driver

And add test/Driver/fsemantic-interposition.c

Added: 
    clang/test/Driver/fsemantic-interposition.c

Modified: 
    clang/lib/Driver/ToolChains/Clang.cpp
    clang/lib/Frontend/CompilerInvocation.cpp
    clang/test/CodeGen/semantic-interposition.c
    clang/test/Driver/clang_f_opts.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index c8195f0f4ccf..433fdded5b7a 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4384,6 +4384,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     CmdArgs.push_back(A->getValue());
   }
 
+  if (Args.hasFlag(options::OPT_fsemantic_interposition,
+                   options::OPT_fno_semantic_interposition, false) &&
+      RelocationModel != llvm::Reloc::Static && !IsPIE)
+    CmdArgs.push_back("-fsemantic-interposition");
+
   CmdArgs.push_back("-mthread-model");
   if (Arg *A = Args.getLastArg(options::OPT_mthread_model)) {
     if (!TC.isThreadModelSupported(A->getValue()))
@@ -5036,10 +5041,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
                   options::OPT_fno_emulated_tls);
   Args.AddLastArg(CmdArgs, options::OPT_fkeep_static_consts);
 
-  if (Args.hasFlag(options::OPT_fsemantic_interposition,
-                   options::OPT_fno_semantic_interposition, false))
-    CmdArgs.push_back("-fsemantic-interposition");
-
   // AltiVec-like language extensions aren't relevant for assembling.
   if (!isa<PreprocessJobAction>(JA) || Output.getType() != types::TY_PP_Asm)
     Args.AddLastArg(CmdArgs, options::OPT_fzvector);

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index f3015d0f7085..a71145202052 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3031,9 +3031,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
       Opts.setDefaultCallingConv(DefaultCC);
   }
 
-  // -fsemantic-interposition
-  Opts.SemanticInterposition =
-      Args.hasArg(OPT_fsemantic_interposition) && Opts.PICLevel && !Opts.PIE;
+  Opts.SemanticInterposition = Args.hasArg(OPT_fsemantic_interposition);
 
   // -mrtd option
   if (Arg *A = Args.getLastArg(OPT_mrtd)) {

diff  --git a/clang/test/CodeGen/semantic-interposition.c b/clang/test/CodeGen/semantic-interposition.c
index 77df61566e07..43656e36021f 100644
--- a/clang/test/CodeGen/semantic-interposition.c
+++ b/clang/test/CodeGen/semantic-interposition.c
@@ -1,14 +1,5 @@
-// Semantic Interposition is active if
-//  -fsemantic-interposition is set,
-// - pic-level > 0
-// - pic-is-pie is not set
+// RUN: %clang_cc1 -emit-llvm -fsemantic-interposition %s -o - | FileCheck --check-prefix=INTERPOSITION %s
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck --check-prefix=NO %s
 
-// RUN: %clang_cc1 -emit-llvm -fsemantic-interposition -pic-level 0 %s -o - | FileCheck %s -check-prefix=CHECK-NO-INTERPOSITION
-// RUN: %clang_cc1 -emit-llvm -fsemantic-interposition -pic-level 1 %s -o - | FileCheck %s -check-prefix=CHECK-INTERPOSITION
-// RUN: %clang_cc1 -emit-llvm -fsemantic-interposition -pic-level 2 %s -o - | FileCheck %s -check-prefix=CHECK-INTERPOSITION
-// RUN: %clang_cc1 -emit-llvm -fsemantic-interposition -pic-level 0 %s -o - | FileCheck %s -check-prefix=CHECK-NO-INTERPOSITION
-// RUN: %clang_cc1 -emit-llvm -fsemantic-interposition -pic-level 1 -pic-is-pie %s -o - | FileCheck %s -check-prefix=CHECK-NO-INTERPOSITION
-// RUN: %clang_cc1 -emit-llvm -fsemantic-interposition -pic-level 2 -pic-is-pie %s -o - | FileCheck %s -check-prefix=CHECK-NO-INTERPOSITION
-
-// CHECK-NO-INTERPOSITION-NOT: "SemanticInterposition"
-// CHECK-INTERPOSITION: !{{[0-9]+}} = !{i32 1, !"SemanticInterposition", i32 1}
+// INTERPOSITION: !{{[0-9]+}} = !{i32 1, !"SemanticInterposition", i32 1}
+// NO-NOT: "SemanticInterposition"

diff  --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c
index e3fe373d7198..970b4e934e78 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -251,8 +251,6 @@
 // RUN:     -fexec-charset=UTF-8                                             \
 // RUN:     -fivopts -fno-ivopts                                              \
 // RUN:     -fnon-call-exceptions -fno-non-call-exceptions                    \
-// RUN:     -fno-semantic-interposition                                       \
-// RUN:     -fsemantic-interposition                                          \
 // RUN:     -fpermissive -fno-permissive                                      \
 // RUN:     -fdefer-pop -fno-defer-pop                                        \
 // RUN:     -fprefetch-loop-arrays -fno-prefetch-loop-arrays                  \

diff  --git a/clang/test/Driver/fsemantic-interposition.c b/clang/test/Driver/fsemantic-interposition.c
new file mode 100644
index 000000000000..484be679c232
--- /dev/null
+++ b/clang/test/Driver/fsemantic-interposition.c
@@ -0,0 +1,9 @@
+// RUN: %clang -target %itanium_abi_triple %s -Werror -fpic -fsemantic-interposition -c -### 2>&1 | FileCheck %s
+// RUN: %clang -target %itanium_abi_triple %s -Werror -fPIC -fsemantic-interposition -c -### 2>&1 | FileCheck %s
+// CHECK: "-fsemantic-interposition"
+
+// RUN: %clang -target %itanium_abi_triple %s -Werror -fPIC -fsemantic-interposition -fno-semantic-interposition -c -### 2>&1 | FileCheck --check-prefix=NO %s
+// RUN: %clang -target %itanium_abi_triple %s -Werror -fsemantic-interposition -c -### 2>&1 | FileCheck --check-prefix=NO %s
+// RUN: %clang -target %itanium_abi_triple %s -Werror -fPIC -c -### 2>&1 | FileCheck --check-prefix=NO %s
+// RUN: %clang -target %itanium_abi_triple %s -Werror -fPIE -fsemantic-interposition -c -### 2>&1 | FileCheck --check-prefix=NO %s
+// NO-NOT: "-fsemantic-interposition"


        


More information about the cfe-commits mailing list