[clang] 336e1f0 - [Driver] Omit -mthread-model posix which is the CC1 default

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 7 12:28:36 PDT 2020


Author: Fangrui Song
Date: 2020-06-07T12:27:11-07:00
New Revision: 336e1f03d1bcda60cf02df09d2331a0ea9af3030

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

LOG: [Driver] Omit -mthread-model posix which is the CC1 default

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Clang.cpp
    clang/test/Driver/thread-model.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 577733a112c4..63b9d0e14003 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4444,15 +4444,20 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     if (RelocationModel != llvm::Reloc::Static && !IsPIE)
       A->render(Args, CmdArgs);
 
-  CmdArgs.push_back("-mthread-model");
-  if (Arg *A = Args.getLastArg(options::OPT_mthread_model)) {
-    if (!TC.isThreadModelSupported(A->getValue()))
-      D.Diag(diag::err_drv_invalid_thread_model_for_target)
-          << A->getValue() << A->getAsString(Args);
-    CmdArgs.push_back(A->getValue());
+  {
+    std::string Model;
+    if (Arg *A = Args.getLastArg(options::OPT_mthread_model)) {
+      if (!TC.isThreadModelSupported(A->getValue()))
+        D.Diag(diag::err_drv_invalid_thread_model_for_target)
+            << A->getValue() << A->getAsString(Args);
+      Model = A->getValue();
+    } else
+      Model = TC.getThreadModel();
+    if (Model != "posix") {
+      CmdArgs.push_back("-mthread-model");
+      CmdArgs.push_back(Args.MakeArgString(Model));
+    }
   }
-  else
-    CmdArgs.push_back(Args.MakeArgString(TC.getThreadModel()));
 
   Args.AddLastArg(CmdArgs, options::OPT_fveclib);
 

diff  --git a/clang/test/Driver/thread-model.c b/clang/test/Driver/thread-model.c
index d01ef1c1a47c..5bc2be2f7378 100644
--- a/clang/test/Driver/thread-model.c
+++ b/clang/test/Driver/thread-model.c
@@ -1,31 +1,16 @@
-// RUN: %clang -### -target arm-unknown-linux-gnu -c %s -mthread-model posix -v 2>&1 | FileCheck -check-prefix=CHECK-POSIX %s
-// RUN: %clang -### -target arm-unknown-linux-gnu -c %s -mthread-model single -v 2>&1 | FileCheck -check-prefix=CHECK-SINGLE %s
-// RUN: not %clang -target arm-unknown-linux-gnu -c %s -mthread-model silly -v 2>&1 | FileCheck -check-prefix=CHECK-INVALID %s
-// CHECK-POSIX: "-mthread-model" "posix"
-// CHECK-SINGLE: "-mthread-model" "single"
-// CHECK-INVALID: error: invalid thread model 'silly' in '-mthread-model silly' for this target
+// RUN: %clang -### -target arm-unknown-linux-gnu -c %s -mthread-model posix -v 2>&1 | FileCheck %s
+// RUN: %clang -### -target arm-unknown-linux-gnu -c %s -v 2>&1 | FileCheck %s
+// RUN: %clang -### -target arm-unknown-linux-gnu -c %s -mthread-model single -v 2>&1 | FileCheck --check-prefix=SINGLE %s
+// RUN: not %clang -target arm-unknown-linux-gnu -c %s -mthread-model silly -v 2>&1 | FileCheck --check-prefix=INVALID %s
 
-// RUN: %clang -### -target arm-unknown-linux-gnu -c %s -v 2>&1 | FileCheck -check-prefix=CHECK-LINUX-POSIX %s
-// RUN: %clang -### -target arm-unknown-linux-gnu -c %s -v -mthread-model single 2>&1 | FileCheck -check-prefix=CHECK-LINUX-SINGLE %s
-// RUN: %clang -### -target arm-unknown-linux-gnu -c %s -v -mthread-model silly 2>&1 | FileCheck -check-prefix=CHECK-LINUX-INVALID %s
-// CHECK-LINUX-POSIX: Thread model: posix
-// CHECK-LINUX-POSIX: "-mthread-model" "posix"
-// CHECK-LINUX-SINGLE: Thread model: single
-// CHECK-LINUX-SINGLE: "-mthread-model" "single"
-// CHECK-LINUX-INVALID-NOT: Thread model:
+// CHECK: Thread model: posix
+// CHECK-NOT: "-mthread-model"
+// SINGLE: Thread model: single
+// SINGLE: "-mthread-model" "single"
+// INVALID: error: invalid thread model 'silly' in '-mthread-model silly' for this target
 
-// RUN: %clang -### -target wasm32-unknown-linux-gnu -c %s -v 2>&1 | FileCheck -check-prefix=CHECK-WEBASSEMBLY-DEFAULT %s
-// RUN: %clang -### -target wasm32-unknown-linux-gnu -c %s -v -mthread-model single 2>&1 | FileCheck -check-prefix=CHECK-WEBASSEMBLY-SINGLE %s
-// RUN: %clang -### -target wasm32-unknown-linux-gnu -c %s -v -mthread-model posix 2>&1 | FileCheck -check-prefix=CHECK-WEBASSEMBLY-POSIX %s
-// RUN: %clang -### -target wasm32-unknown-linux-gnu -c %s -v -mthread-model silly 2>&1 | FileCheck -check-prefix=CHECK-WEBASSEMBLY-INVALID %s
-// RUN: %clang -### -target wasm64-unknown-linux-gnu -c %s -v 2>&1 | FileCheck -check-prefix=CHECK-WEBASSEMBLY-DEFAULT %s
-// RUN: %clang -### -target wasm64-unknown-linux-gnu -c %s -v -mthread-model single 2>&1 | FileCheck -check-prefix=CHECK-WEBASSEMBLY-SINGLE %s
-// RUN: %clang -### -target wasm64-unknown-linux-gnu -c %s -v -mthread-model posix 2>&1 | FileCheck -check-prefix=CHECK-WEBASSEMBLY-POSIX %s
-// RUN: %clang -### -target wasm64-unknown-linux-gnu -c %s -v -mthread-model silly 2>&1 | FileCheck -check-prefix=CHECK-WEBASSEMBLY-INVALID %s
-// CHECK-WEBASSEMBLY-DEFAULT: Thread model: posix
-// CHECK-WEBASSEMBLY-DEFAULT: "-mthread-model" "posix"
-// CHECK-WEBASSEMBLY-SINGLE: Thread model: single
-// CHECK-WEBASSEMBLY-SINGLE: "-mthread-model" "single"
-// CHECK-WEBASSEMBLY-POSIX: Thread model: posix
-// CHECK-WEBASSEMBLY-POSIX: "-mthread-model" "posix"
-// CHECK-WEBASSEMBLY-INVALID-NOT: Thread model:
+// RUN: %clang -### -target wasm32-unknown-linux-gnu -c %s -v 2>&1 | FileCheck %s
+// RUN: %clang -### -target wasm32-unknown-linux-gnu -c %s -v -mthread-model single 2>&1 | FileCheck --check-prefix=SINGLE %s
+// RUN: %clang -### -target wasm32-unknown-linux-gnu -c %s -v -mthread-model posix 2>&1 | FileCheck %s
+// RUN: %clang -### -target wasm32-unknown-linux-gnu -c %s -v -mthread-model silly 2>&1 | FileCheck --check-prefix=INVALID %s
+// RUN: %clang -### -target wasm64-unknown-linux-gnu -c %s -v 2>&1 | FileCheck %s


        


More information about the cfe-commits mailing list