[clang] [ItaniumMangle] Fix `cp` versus `cl` call expression mangling for block scope (PR #114884)

John McCall via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 4 23:36:14 PST 2024


rjmccall wrote:

> > Can we find a way to re-use the code between this and the actual lookup code? Feels like we could have some sort of predicate like `doesLookupResultSuppressADL(NamedDecl*)`. Or are we forced to use slightly different predicates for some compatibility reason?
> 
> `Sema::UseArgumentDependentLookup` in `clang/lib/Sema/SemaExpr.cpp` seems to have similar logic; but, in the context of the name mangler, we take advantage of whether `Sema` created an `UnresolvedLookupExpr` (including whether `Sema` applied overload resolution to a case where the call is not dependent).

My point is that it's supposed to be the *exact same* logic, at least at the level of whether a specific declaration found by lookup suppresses ADL.  "Member and local declarations except for local using declarations of non-local declarations" isn't a completely trivial rule; the fact that we tried to implement it independently in two places but forgot the local declarations half in the mangler is exactly how we got this bug.

To spell it out, if `P(D)` is the "D is a member or local..." predicate:
- Sema wants to suppress ADL if the syntax prohibits it *or* unqualified lookup found a declaration D such that P(D).
- The name mangler wants to use `cp` if the syntax prohibits ADL, except that for stability it wants to keep using `cl` in any situation where it doesn't matter, such as if the name is resolved or if unqualified lookup suppressed ADL anyway by finding a declaration D such that P(D).  This ends up being equivalent to the callee operand being a (ignoring parens) ULE with ADL suppressed that doesn't contain a D such that P(D).

> Furthermore, considering the planned `ClangABICompat` change and the possible impact of CWG 2946 (e.g., mangling class-scope lookup results for friend declarations), I think the flow of the logic will diverge such that attempting to share a predicate now would not help.

I can certainly see how ABI compat might complicate re-use, but you could just pass a flag in saying whether this is for name mangling.  I can't speak to the potential impact of CWG 2946, though.

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


More information about the cfe-commits mailing list