[clang] [llvm] [ThinLTO] Support dead RTTI data elimination under -fno-split-lto-unit (PR #126336)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 13 22:20:19 PST 2025
================
@@ -573,14 +574,29 @@ static void dropDeadSymbols(Module &Mod, const GVSummaryMapTy &DefinedGlobals,
convertToDeclaration(GV);
}
+ Triple TT(Mod.getTargetTriple());
+ std::unique_ptr<CXXABI> ABI = CXXABI::Create(TT);
+
// Now that all dead bodies have been dropped, delete the actual objects
// themselves when possible.
for (GlobalValue *GV : DeadGVs) {
GV->removeDeadConstantUsers();
- // Might reference something defined in native object (i.e. dropped a
- // non-prevailing IR def, but we need to keep the declaration).
- if (GV->use_empty())
+
+ // The RTTI data consists of both type information and the type name string.
+ // Although they are considered dead, there are still users that reference them.
+ // For example, the type information might be used by a vtable, and the type name
+ // string might be used by the type info.
+ // Therefore, we need to replace these uses to null pointer before erasing them.
+ if (ABI && (ABI->isTypeInfo(GV->getName()) ||
+ ABI->isTypeName(GV->getName()))) {
+ GV->replaceAllUsesWith(
----------------
luxufan wrote:
Although the RTTI GlobalVariable has been inferred as dead, the vtable still references it. Without this change, the RTTI GlobalVariable cannot be eliminated.
https://github.com/llvm/llvm-project/pull/126336
More information about the cfe-commits
mailing list