[clang] [modules] Avoid redefinition errors when access modular header as non-modular. (PR #214345)

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 7 01:04:12 PDT 2026


================
@@ -1597,3 +1597,25 @@ void Sema::checkReferenceToTULocalFromOtherTU(
   PendingCheckReferenceForTULocal.push_back(
       std::make_pair(FD, PointOfInstantiation));
 }
+
+bool Sema::isFromSameSingleIncludeHeader(const Decl *PrevD,
+                                         SourceLocation NewLoc) {
+  if (!PrevD->isFromASTFile())
+    return false;
+  SourceLocation PrevLoc = PrevD->getLocation();
+  if (!PrevLoc.isValid() || !NewLoc.isValid())
+    return false;
+  SourceManager &SM = getSourceManager();
+  auto [PrevFileID, PrevOffset] = SM.getDecomposedExpansionLoc(PrevLoc);
+  auto [NewFileID, NewOffset] = SM.getDecomposedExpansionLoc(NewLoc);
+  if (PrevOffset != NewOffset)
----------------
ChuanqiXu9 wrote:

I  don't think it is good to use source location to judge  identicality. This is a just workaroud. As the summary said, it can't work with the real ODR issues caused by preprocessors.

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


More information about the cfe-commits mailing list