[clang] [lldb] Serialize `#pragma redefine_extname` into precompiled headers. (PR #186755)

Paul Kirth via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 20 09:50:22 PDT 2026


================
@@ -6058,6 +6059,25 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema *SemaPtr, StringRef isysroot,
     }
   }
 
+  // Write the set of #pragma redefine_extname'd, undeclared identifiers. We
+  // always write the entire table, since later PCH files in a PCH chain are
+  // only interested in the results at the end of the chain.
+  RecordData ExtnameUndeclaredIdentifiers;
+  if (SemaPtr) {
+    ASTContext &Context = SemaPtr->Context;
+    ASTRecordWriter ExtnameUndeclaredIdentifiersWriter(
+        Context, *this, ExtnameUndeclaredIdentifiers);
+    for (const auto &ExtnameUndeclaredIdentifierList :
+         SemaPtr->ExtnameUndeclaredIdentifiers) {
+      const IdentifierInfo *const II = ExtnameUndeclaredIdentifierList.first;
+      const AsmLabelAttr *const AL = ExtnameUndeclaredIdentifierList.second;
+      ExtnameUndeclaredIdentifiersWriter.AddIdentifierRef(II);
+      ExtnameUndeclaredIdentifiersWriter.AddIdentifierRef(
+          &Context.Idents.get(AL->getLabel()));
+      ExtnameUndeclaredIdentifiersWriter.AddSourceLocation(AL->getLocation());
+    }
----------------
ilovepi wrote:

I think you can use structured decomposition here and things would be a little more drect/readable.

I didn't check this at all, but something like the following should work, modulo some small tweaks.
```suggestion
    for (const auto &[IdentifierInfo, AsmLabelAttr] :
         SemaPtr->ExtnameUndeclaredIdentifiers) {
      ExtnameUndeclaredIdentifiersWriter.AddIdentifierRef(II);
      ExtnameUndeclaredIdentifiersWriter.AddIdentifierRef(
          &Context.Idents.get(AL->getLabel()));
      ExtnameUndeclaredIdentifiersWriter.AddSourceLocation(AL->getLocation());
    }
```

https://github.com/llvm/llvm-project/pull/186755


More information about the cfe-commits mailing list