[clang] [CIR] Add addLLVMUsed and addLLVMCompilerUsed methods to CIRGenModule (PR #188189)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 31 00:23:17 PDT 2026
================
@@ -658,13 +658,33 @@ void CIRGenModule::setCommonAttributes(GlobalDecl gd, mlir::Operation *gv) {
if (isa_and_nonnull<NamedDecl>(d))
setGVProperties(gv, dyn_cast<NamedDecl>(d));
assert(!cir::MissingFeatures::defaultVisibility());
- assert(!cir::MissingFeatures::opGlobalUsedOrCompilerUsed());
+
+ if (auto gvi = mlir::dyn_cast<cir::CIRGlobalValueInterface>(gv)) {
+ if (d && d->hasAttr<UsedAttr>())
+ addUsedOrCompilerUsedGlobal(gvi);
+
+ if (const auto *vd = dyn_cast_if_present<VarDecl>(d);
+ vd && ((codeGenOpts.KeepPersistentStorageVariables &&
+ (vd->getStorageDuration() == SD_Static ||
+ vd->getStorageDuration() == SD_Thread)) ||
+ (codeGenOpts.KeepStaticConsts &&
+ vd->getStorageDuration() == SD_Static &&
+ vd->getType().isConstQualified())))
+ addUsedOrCompilerUsedGlobal(gvi);
----------------
skc7 wrote:
Thanks for feedback. Added this test.
https://github.com/llvm/llvm-project/pull/188189
More information about the cfe-commits
mailing list