================
@@ -7421,3 +7421,67 @@ void Sema::PerformDependentDiagnostics(const DeclContext 
*Pattern,
     }
   }
 }
+
+static bool isMappedLocalDecl(const Decl *D) {
+  if (const auto *VD = dyn_cast<VarDecl>(D)) {
+    return VD->isLocalVarDeclOrParm() && !isa<ParmVarDecl>(VD);
+  }
+  return isa<BindingDecl>(D);
+}
+
+const Decl *Sema::getCanonicalLocalDecl(const Decl *D) {
+  if (isa<ParmVarDecl>(D)) {
+    return D;
+  }
+
+  const auto *VD = dyn_cast<VarDecl>(D);
+  const auto *BD = dyn_cast<BindingDecl>(D);
+  if (!VD && !BD) {
+    return D;
+  }
+
+  if (VD && !VD->isLocalVarDeclOrParm()) {
+    return D;
+  }
+
+  const DeclContext *DC = VD ? VD->getDeclContext() : BD->getDeclContext();
+  const auto *FD = dyn_cast<FunctionDecl>(DC);
+  if (!FD) {
+    return D;
+  }
+
+  const auto *CanonFD = FD->getCanonicalDecl();
----------------
jyknight wrote:

We need the canonical _definition_, not just a decl, in order to be able to 
iterate `decls()` on it. Probably `FD->getDefinition()`? I think that's 
guaranteed to use return a canonical definition.

That'll end up with this using a different decl than the ParamVar mapping, 
which uses the  `getCanonicalDecl`. But maybe that's fine?

https://github.com/llvm/llvm-project/pull/202248
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to