Index: test/wasm/lto/atomics.ll =================================================================== --- test/wasm/lto/atomics.ll +++ test/wasm/lto/atomics.ll @@ -1,5 +1,9 @@ ; RUN: llvm-as %s -o %t.o ; RUN: wasm-ld %t.o -o %t.wasm -lto-O0 +; RUN: wasm-ld --shared-memory %t.o -o %t.shared.wasm -lto-O0 +; RUN: llvm-objdump -d %t.shared.wasm +; RUN: llc %s -mattr=+atomics -o %t.threads.o + ; Atomic operations with fail to compile if the ThreadModel is not ; correctly set to Single (i.e. if atomics are not lowered to regular ops). @@ -8,7 +12,10 @@ @foo = hidden global i32 1 -define void @_start() { - %1 = load atomic i32, i32* @foo unordered, align 4 +define void @_start() #0 { + %1 = load atomic i32, i32* @foo seq_cst, align 4 + store atomic i32 %1, i32* @foo seq_cst, align 4 ret void } + +attributes #0 = { noinline optnone "target-features"="+atomics" } Index: wasm/LTO.cpp =================================================================== --- wasm/LTO.cpp +++ wasm/LTO.cpp @@ -47,8 +47,12 @@ C.Options.FunctionSections = true; C.Options.DataSections = true; - // Wasm currently only supports ThreadModel::Single - C.Options.ThreadModel = ThreadModel::Single; + // When shared memory is disabled wasm doesn't support atomics operations. + // Setting the thead model based on the SharedMemory option seems like + // reasonable default. Idealy the bitcode metadata would set this on + // a per function basis instead. + C.Options.ThreadModel = + Config->SharedMemory ? ThreadModel::POSIX : ThreadModel::Single; C.DisableVerify = Config->DisableVerify; C.DiagHandler = diagnosticHandler;