[clang] [Clang][ItaniumMangle] Fix infinite recursion mangling a lambda in an enable_if condition (PR #234686)
Yanzuo Liu via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 22 11:00:25 PDT 2026
================
@@ -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
More information about the cfe-commits
mailing list