Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions clang/lib/CIR/CodeGen/CIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ void CIRGenModule::buildGlobalVarDefinition(const clang::VarDecl *D,
setTLSMode(GV, *D);
}

// TODO(cir): maybeSetTrivialComdat(*D, *GV);
maybeSetTrivialComdat(*D, GV);

// TODO(cir):
// Emit the initializer function if necessary.
Expand Down Expand Up @@ -3008,11 +3008,14 @@ bool CIRGenModule::supportsCOMDAT() const {
return getTriple().supportsCOMDAT();
}

void CIRGenModule::maybeSetTrivialComdat(const Decl &D, mlir::Operation *Op) {
if (!shouldBeInCOMDAT(*this, D))
void CIRGenModule::maybeSetTrivialComdat(const Decl &d, mlir::Operation *op) {
if (!shouldBeInCOMDAT(*this, d))
return;

// TODO: Op.setComdat
auto globalOp = dyn_cast_or_null<mlir::cir::GlobalOp>(op);
if (globalOp)
globalOp.setComdat(true);
// Keep it as missing feature as we need to implement comdat for FuncOp.
// in the future.
assert(!MissingFeatures::setComdat() && "NYI");
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ class CIRGenModule : public CIRGenTypeCache {
clang::GlobalDecl &Result) const;

bool supportsCOMDAT() const;
void maybeSetTrivialComdat(const clang::Decl &D, mlir::Operation *Op);
void maybeSetTrivialComdat(const clang::Decl &d, mlir::Operation *op);

void emitError(const llvm::Twine &message) { theModule.emitError(message); }

Expand Down
31 changes: 19 additions & 12 deletions clang/test/CIR/CodeGen/cxx1z-inline-variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,25 @@ const int &compat_use_after_redecl1 = compat::c;
const int &compat_use_after_redecl2 = compat::d;
const int &compat_use_after_redecl3 = compat::g;

// CIR: cir.global weak_odr @_ZN6compat1bE = #cir.int<2> : !s32i {alignment = 4 : i64}
// CIR: cir.global weak_odr @_ZN6compat1aE = #cir.int<1> : !s32i {alignment = 4 : i64}
// CIR: cir.global weak_odr @_ZN6compat1cE = #cir.int<3> : !s32i {alignment = 4 : i64}
// CIR: cir.global weak_odr comdat @_ZN6compat1bE = #cir.int<2> : !s32i {alignment = 4 : i64}
// CIR: cir.global weak_odr comdat @_ZN6compat1aE = #cir.int<1> : !s32i {alignment = 4 : i64}
// CIR: cir.global weak_odr comdat @_ZN6compat1cE = #cir.int<3> : !s32i {alignment = 4 : i64}
// CIR: cir.global external @_ZN6compat1eE = #cir.int<5> : !s32i {alignment = 4 : i64}
// CIR: cir.global weak_odr @_ZN6compat1fE = #cir.int<6> : !s32i {alignment = 4 : i64}
// CIR: cir.global linkonce_odr @_ZN6compat1dE = #cir.int<4> : !s32i {alignment = 4 : i64}
// CIR: cir.global linkonce_odr @_ZN6compat1gE = #cir.int<7> : !s32i {alignment = 4 : i64}
// CIR: cir.global weak_odr comdat @_ZN6compat1fE = #cir.int<6> : !s32i {alignment = 4 : i64}
// CIR: cir.global linkonce_odr comdat @_ZN6compat1dE = #cir.int<4> : !s32i {alignment = 4 : i64}
// CIR: cir.global linkonce_odr comdat @_ZN6compat1gE = #cir.int<7> : !s32i {alignment = 4 : i64}

// LLVM: @_ZN6compat1bE = weak_odr global i32 2, align 4
// LLVM: @_ZN6compat1aE = weak_odr global i32 1, align 4
// LLVM: @_ZN6compat1cE = weak_odr global i32 3, align 4
// LLVM: $_ZN6compat1bE = comdat any
// LLVM: $_ZN6compat1aE = comdat any
// LLVM: $_ZN6compat1cE = comdat any
// LLVM: $_ZN6compat1fE = comdat any
// LLVM: $_ZN6compat1dE = comdat any
// LLVM: $_ZN6compat1gE = comdat any

// LLVM: @_ZN6compat1bE = weak_odr global i32 2, comdat, align 4
// LLVM: @_ZN6compat1aE = weak_odr global i32 1, comdat, align 4
// LLVM: @_ZN6compat1cE = weak_odr global i32 3, comdat, align 4
// LLVM: @_ZN6compat1eE = global i32 5, align 4
// LLVM: @_ZN6compat1fE = weak_odr global i32 6, align 4
// LLVM: @_ZN6compat1dE = linkonce_odr global i32 4, align 4
// LLVM: @_ZN6compat1gE = linkonce_odr global i32 7, align 4
// LLVM: @_ZN6compat1fE = weak_odr global i32 6, comdat, align 4
// LLVM: @_ZN6compat1dE = linkonce_odr global i32 4, comdat, align 4
// LLVM: @_ZN6compat1gE = linkonce_odr global i32 7, comdat, align 4
2 changes: 1 addition & 1 deletion clang/test/CIR/CodeGen/weak.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void active (void)
// LLVM-NEXT: call void @B()

int __attribute__((selectany)) y;
// CIR: cir.global weak_odr @y
// CIR: cir.global weak_odr comdat @y

int __attribute__((weak)) x;
// CIR: cir.global weak