[all-commits] [llvm/llvm-project] 942032: [Clang] Fix a lambda pattern comparison mismatch a...

Younan Zhang via All-commits all-commits at lists.llvm.org
Tue Apr 15 15:54:36 PDT 2025


  Branch: refs/heads/release/20.x
  Home:   https://github.com/llvm/llvm-project
  Commit: 9420327ad7687df644c7dd876d23dd9c3ab7005b
      https://github.com/llvm/llvm-project/commit/9420327ad7687df644c7dd876d23dd9c3ab7005b
  Author: Younan Zhang <zyn7109 at gmail.com>
  Date:   2025-04-15 (Tue, 15 Apr 2025)

  Changed paths:
    M clang/lib/Sema/SemaConcept.cpp
    M clang/lib/Sema/SemaLambda.cpp
    M clang/test/SemaTemplate/concepts-lambda.cpp

  Log Message:
  -----------
  [Clang] Fix a lambda pattern comparison mismatch after ecc7e6ce4 (#133863)

In ecc7e6ce4, we tried to inspect the `LambdaScopeInfo` on stack to
recover the instantiating lambda captures. However, there was a mismatch
in how we compared the pattern declarations of lambdas: the constraint
instantiation used a tailored `getPatternFunctionDecl()` which is
localized in SemaLambda that finds the very primal template declaration
of a lambda, while `FunctionDecl::getTemplateInstantiationPattern` finds
the latest template pattern of a lambda. This difference causes issues
when lambdas are nested, as we always want the primary template
declaration.

This corrects that by moving `Sema::addInstantiatedCapturesToScope` from
SemaConcept to SemaLambda, allowing it to use the localized version of
`getPatternFunctionDecl`.

It is also worth exploring to coalesce the implementation of
`getPatternFunctionDecl` with
`FunctionDecl::getTemplateInstantiationPattern`. But I’m leaving that
for the future, as I’d like to backport this fix (ecc7e6ce4 made the
issue more visible in clang 20, sorry!), and changing Sema’s ABI would
not be suitable in that regards. Hence, no release note.

Fixes https://github.com/llvm/llvm-project/issues/133719

(cherry picked from commit dcc2182bce3d2ef0e0a991664c51b4b3bfcf7197)



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list