[all-commits] [llvm/llvm-project] bc73ef: PR60985: Fix merging of lambda closure types acros...

Richard Smith via All-commits all-commits at lists.llvm.org
Thu Mar 30 14:23:02 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: bc73ef0031b50f7443615fef614fb4ecaaa4bd11
      https://github.com/llvm/llvm-project/commit/bc73ef0031b50f7443615fef614fb4ecaaa4bd11
  Author: Richard Smith <richard at metafoo.co.uk>
  Date:   2023-03-30 (Thu, 30 Mar 2023)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/AST/Decl.h
    M clang/include/clang/AST/DeclCXX.h
    M clang/include/clang/AST/ExternalASTSource.h
    M clang/include/clang/AST/MangleNumberingContext.h
    M clang/include/clang/AST/Stmt.h
    M clang/include/clang/Sema/ExternalSemaSource.h
    M clang/include/clang/Sema/MultiplexExternalSemaSource.h
    M clang/include/clang/Sema/Sema.h
    M clang/include/clang/Serialization/ASTReader.h
    M clang/lib/AST/ASTContext.cpp
    M clang/lib/AST/ASTImporter.cpp
    M clang/lib/AST/Decl.cpp
    M clang/lib/AST/DeclCXX.cpp
    M clang/lib/AST/ODRDiagsEmitter.cpp
    M clang/lib/Sema/MultiplexExternalSemaSource.cpp
    M clang/lib/Sema/SemaExprCXX.cpp
    M clang/lib/Sema/SemaLambda.cpp
    M clang/lib/Sema/TreeTransform.h
    M clang/lib/Serialization/ASTReader.cpp
    M clang/lib/Serialization/ASTReaderDecl.cpp
    M clang/lib/Serialization/ASTReaderStmt.cpp
    M clang/lib/Serialization/ASTWriter.cpp
    M clang/lib/Serialization/ASTWriterDecl.cpp
    M clang/lib/Serialization/ASTWriterStmt.cpp
    A clang/test/Modules/lambda-in-variable.cpp
    M clang/test/OpenMP/parallel_master_taskloop_simd_codegen.cpp

  Log Message:
  -----------
  PR60985: Fix merging of lambda closure types across modules.

Previously, distinct lambdas would get merged, and multiple definitions
of the same lambda would not get merged, because we attempted to
identify lambdas by their ordinal position within their lexical
DeclContext. This failed for lambdas within namespace-scope variables
and within variable templates, where the lexical position in the context
containing the variable didn't uniquely identify the lambda.

In this patch, we instead identify lambda closure types by index within
their context declaration, which does uniquely identify them in a way
that's consistent across modules.

This change causes a deserialization cycle between the type of a
variable with deduced type and a lambda appearing as the initializer of
the variable -- reading the variable's type requires reading and merging
the lambda, and reading the lambda requires reading and merging the
variable. This is addressed by deferring loading the deduced type of a
variable until after we finish recursive deserialization.

This also exposes a pre-existing subtle issue where loading a
variable declaration would trigger immediate loading of its initializer,
which could recursively refer back to properties of the variable. This
particularly causes problems if the initializer contains a
lambda-expression, but can be problematic in general. That is addressed
by switching to lazily loading the initializers of variables rather than
always loading them with the variable declaration. As well as fixing a
deserialization cycle, that should improve laziness of deserialization
in general.

LambdaDefinitionData had 63 spare bits in it, presumably caused by an
off-by-one-error in some previous change. This change claims 32 of those bits
as a counter for the lambda within its context. We could probably move the
numbering to separate storage, like we do for the device-side mangling number,
to optimize the likely-common case where all three numbers (host-side mangling
number, device-side mangling number, and index within the context declaration)
are zero, but that's not done in this change.

Fixes #60985.

Reviewed By: #clang-language-wg, aaron.ballman

Differential Revision: https://reviews.llvm.org/D145737




More information about the All-commits mailing list