================
@@ -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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to