[PATCH] D57874: [WebAssembly] Set '-matomics' when '-pthread' is set

Heejin Ahn via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 6 19:35:31 PST 2019


aheejin created this revision.
aheejin added a reviewer: dschuff.
Herald added subscribers: cfe-commits, jfb, sunfish, jgravelle-google, sbc100.
Herald added a project: clang.

In wasm, we always use '-matomics' when we use '-pthread'. This will
make users type one less option and options will be more consistent.


Repository:
  rC Clang

https://reviews.llvm.org/D57874

Files:
  lib/Frontend/CompilerInvocation.cpp
  test/Driver/wasm32-unknown-unknown.cpp
  test/Driver/wasm64-unknown-unknown.cpp


Index: test/Driver/wasm64-unknown-unknown.cpp
===================================================================
--- test/Driver/wasm64-unknown-unknown.cpp
+++ test/Driver/wasm64-unknown-unknown.cpp
@@ -120,3 +120,6 @@
   // CHECK: SwitchILi8
   Switch<sizeof(va_list)>();
 }
+
+// -pthread turns on -matomics
+// THREADS: attributes #{{[[0-9]+}} = {{{.*}}"target-features"="+atomics"{{.*}}}
Index: test/Driver/wasm32-unknown-unknown.cpp
===================================================================
--- test/Driver/wasm32-unknown-unknown.cpp
+++ test/Driver/wasm32-unknown-unknown.cpp
@@ -120,3 +120,6 @@
   // CHECK: SwitchILi4
   Switch<sizeof(va_list)>();
 }
+
+// -pthread turns on -matomics
+// THREADS: attributes #{{[[0-9]+}} = {{{.*}}"target-features"="+atomics"{{.*}}}
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -3332,6 +3332,11 @@
     Res.getDiagnosticOpts().Warnings.push_back("spir-compat");
   }
 
+  if (Arch == llvm::Triple::wasm32 || Arch == llvm::Triple::wasm64) {
+    if (LangOpts.POSIXThreads)
+      Res.getTargetOpts().FeaturesAsWritten.push_back("+atomics");
+  }
+
   // If sanitizer is enabled, disable OPT_ffine_grained_bitfield_accesses.
   if (Res.getCodeGenOpts().FineGrainedBitfieldAccesses &&
       !Res.getLangOpts()->Sanitize.empty()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57874.185699.patch
Type: text/x-patch
Size: 1431 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190207/de7c6756/attachment.bin>


More information about the cfe-commits mailing list