Skip to content

Commit 07fee05

Browse files
committed
[openmp][wasm] Use external symbol instead of common symbol for lock
The `gomp_critical_user` lock is typically compiled using a common symbol, but the WebAssembly backend does not have these implemented. This change uses an external symbol instead, which avoids compiler crashes when compiling `#pragma omp critical` code to WebAssembly.
1 parent 961d943 commit 07fee05

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4982,10 +4982,13 @@ OpenMPIRBuilder::getOrCreateInternalVariable(Type *Ty, const StringRef &Name,
49824982
// variable for possibly changing that to internal or private, or maybe
49834983
// create different versions of the function for different OMP internal
49844984
// variables.
4985-
auto *GV = new GlobalVariable(
4986-
M, Ty, /*IsConstant=*/false, GlobalValue::CommonLinkage,
4987-
Constant::getNullValue(Ty), Elem.first(),
4988-
/*InsertBefore=*/nullptr, GlobalValue::NotThreadLocal, AddressSpace);
4985+
auto Linkage = this->M.getTargetTriple().rfind("wasm32") == 0
4986+
? GlobalValue::ExternalLinkage
4987+
: GlobalValue::CommonLinkage;
4988+
auto *GV = new GlobalVariable(M, Ty, /*IsConstant=*/false, Linkage,
4989+
Constant::getNullValue(Ty), Elem.first(),
4990+
/*InsertBefore=*/nullptr,
4991+
GlobalValue::NotThreadLocal, AddressSpace);
49894992
const DataLayout &DL = M.getDataLayout();
49904993
const llvm::Align TypeAlign = DL.getABITypeAlign(Ty);
49914994
const llvm::Align PtrAlign = DL.getPointerABIAlignment(AddressSpace);

0 commit comments

Comments
 (0)