Skip to content

Commit 0c3f772

Browse files
committed
IRGen: ensure that declarations are not COMDATed
Unfortunately, declarations cannot be marked with their COMDAT groups. This fixes multithreaded IRGen where we would emit declarations for the global initializers with COMDATs causing the IR Verifier to object. The existing test cases cover this scenario.
1 parent 167f94f commit 0c3f772

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,8 @@ Address IRGenModule::getAddrOfSILGlobalVariable(SILGlobalVariable *var,
19031903
/// Add a zero initializer.
19041904
if (forDefinition)
19051905
gvar->setInitializer(llvm::Constant::getNullValue(storageTypeWithContainer));
1906+
else
1907+
gvar->setComdat(nullptr);
19061908
}
19071909
llvm::Constant *addr = gvar;
19081910
if (var->isInitializedObject()) {
@@ -2184,8 +2186,11 @@ llvm::Function *IRGenModule::getAddrOfSILFunction(
21842186
// associated with it. The combination of the two allows us to identify the
21852187
// @_silgen_name functions. These are locally defined function thunks used in
21862188
// the standard library. Do not give them DLLImport DLL Storage.
2187-
if (useDllStorage() && f->hasCReferences() && !forDefinition)
2188-
fn->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
2189+
if (!forDefinition) {
2190+
fn->setComdat(nullptr);
2191+
if (f->hasCReferences())
2192+
fn->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
2193+
}
21892194

21902195
// If we have an order number for this function, set it up as appropriate.
21912196
if (hasOrderNumber) {

0 commit comments

Comments
 (0)