================
@@ -664,6 +665,26 @@ ItaniumMangleContextImpl::getEffectiveDeclContext(const 
Decl *D) {
       if (ParmVarDecl *ContextParam =
               dyn_cast_or_null<ParmVarDecl>(RD->getLambdaContextDecl()))
         return ContextParam->getDeclContext();
+
+    // A lambda in the condition of an enable_if/diagnose_if attribute is
+    // instantiated with the function as its DeclContext, but the ABI treats it
+    // like the dependent pattern: it lives in the function's parent context.
+    // Mangling it relative to the function would recurse forever, since the
+    // function's encoding includes the attribute condition.
+    if (RD->isLambda() && !RD->getLambdaContextDecl())
+      if (const auto *FD = dyn_cast<FunctionDecl>(RD->getDeclContext())) {
+        const SourceManager &SM = getASTContext().getSourceManager();
+        SourceLocation Loc = RD->getLocation();
+        for (const Attr *A : FD->attrs()) {
+          if (!isa<EnableIfAttr, DiagnoseIfAttr>(A))
+            continue;
+          SourceRange R = A->getRange();
+          if (R.isValid() && Loc.isValid() &&
+              !SM.isBeforeInTranslationUnit(Loc, R.getBegin()) &&
+              !SM.isBeforeInTranslationUnit(R.getEnd(), Loc))
----------------
zwuis wrote:

Comparing `SourceLocation` is definitely wrong when macros come into play.

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

Reply via email to