[clang] [CIR] Upstream global variable linkage types (PR #129072)
Henrich Lauko via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 28 01:07:07 PST 2025
================
@@ -210,6 +223,193 @@ void CIRGenModule::emitGlobalDefinition(clang::GlobalDecl gd,
llvm_unreachable("Invalid argument to CIRGenModule::emitGlobalDefinition");
}
+static bool shouldBeInCOMDAT(CIRGenModule &cgm, const Decl &d) {
+ assert(!cir::MissingFeatures::supportComdat());
+
+ if (d.hasAttr<SelectAnyAttr>())
+ return true;
+
+ GVALinkage linkage;
+ if (auto *vd = dyn_cast<VarDecl>(&d))
+ linkage = cgm.getASTContext().GetGVALinkageForVariable(vd);
+ else
+ linkage =
+ cgm.getASTContext().GetGVALinkageForFunction(cast<FunctionDecl>(&d));
+
+ switch (linkage) {
+ case clang::GVA_Internal:
+ case clang::GVA_AvailableExternally:
+ case clang::GVA_StrongExternal:
+ return false;
+ case clang::GVA_DiscardableODR:
+ case clang::GVA_StrongODR:
+ return true;
+ }
+ llvm_unreachable("No such linkage");
+}
+
+// TODO(CIR): this could be a common method between LLVM codegen.
+static bool isVarDeclStrongDefinition(const ASTContext &astContext,
----------------
xlauko wrote:
This is a copy-paste from `clang/lib/CodeGen/CodeGenModule.h` without an actual dependency on CIR.
`CIRGenModule` is only used to obtain `ASTContext` and check `cgm.supportsCOMDAT()`, both of which can be passed as direct arguments. In fact, `ASTContext` already is; it just needs to be forwarded to `shouldBeInCOMDAT`.
Would it be better to expose this function from Clang CodeGen and adjust the interface for use here? What do you think, @erichkeane?
https://github.com/llvm/llvm-project/pull/129072
More information about the cfe-commits
mailing list