[clang] [C++20] [Modules] Introduce -fgen-reduced-bmi (PR #85050)
koplas wrote: Using `-fgen-reduced-bmi` currently fails for me with a case that looks like this: ```C++ // a.hpp template void ignore(T const &) noexcept {} inline void resultCheck(char const *message) { ignore(message); } // b.cppm module; #include "a.hpp" export module b; export { using ignore; using resultCheck; } // c.cppm export module c; import b; export void test() { resultCheck(nullptr); } ``` This will result in this linker error: `undefined reference to void ignore(char const* const&)`. Removing `-fgen-reduced-bmi` will result in linking without errors. Do I need to pass certain flags to CMake? https://github.com/llvm/llvm-project/pull/85050 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] [Modules] Introduce -fgen-reduced-bmi (PR #85050)
koplas wrote: Do I miss something? The performance and file size is similar with and without `-fgen-reduced-bmi`. To reproduce clone https://github.com/koplas/clang-modules-test and run `build.sh` and `build_thin_bmi.sh`. https://github.com/llvm/llvm-project/pull/85050 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PATCH] [clang][modules] Fix serialization and de-serialization of PCH module file refs (#105994) (PR #132802)
https://github.com/koplas created https://github.com/llvm/llvm-project/pull/132802 The File ID is incorrectly calculated, resulting in an out-of-bounds access. The test code is more complex because the File fetching only happens in specific scenarios. >From cad802f9c91f12b8db26bc63eef13097474d9165 Mon Sep 17 00:00:00 2001 From: koplas Date: Mon, 24 Mar 2025 19:20:52 +0100 Subject: [PATCH] [PATCH] [clang][modules] Fix serialization and de-serialization of PCH module file refs (#105994) Co-authored-by: ShaderKeeper --- clang/lib/Serialization/ASTReader.cpp| 4 +- clang/test/Modules/MixedModulePrecompile.cpp | 49 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 clang/test/Modules/MixedModulePrecompile.cpp diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 2728e93c69516..7540ff5a3a95c 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -9615,7 +9615,7 @@ ModuleFile *ASTReader::getLocalModuleFile(ModuleFile &M, unsigned ID) const { // It's a prefix (preamble, PCH, ...). Look it up by index. unsigned IndexFromEnd = ID >> 1; assert(IndexFromEnd && "got reference to unknown module file"); -return getModuleManager().pch_modules().end()[-IndexFromEnd]; +return getModuleManager().pch_modules().end()[-static_cast(IndexFromEnd)]; } } @@ -9633,7 +9633,7 @@ unsigned ASTReader::getModuleFileID(ModuleFile *M) { auto PCHModules = getModuleManager().pch_modules(); auto I = llvm::find(PCHModules, M); assert(I != PCHModules.end() && "emitting reference to unknown file"); - return (I - PCHModules.end()) << 1; + return std::distance(I, PCHModules.end()) << 1; } std::optional ASTReader::getSourceDescriptor(unsigned ID) { diff --git a/clang/test/Modules/MixedModulePrecompile.cpp b/clang/test/Modules/MixedModulePrecompile.cpp new file mode 100644 index 0..a800498cd2670 --- /dev/null +++ b/clang/test/Modules/MixedModulePrecompile.cpp @@ -0,0 +1,49 @@ +// Tests mixed usage of precompiled headers and modules. +// +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t +// +// RUN: %clang_cc1 -std=c++20 -x c++-header -emit-pch %t/a.hpp \ +// RUN: -o %t/a.pch + +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part1.cppm \ +// RUN: -include-pch %t/a.pch -o %t/Part1.pcm +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part2.cppm \ +// RUN: -include-pch %t/a.pch -o %t/Part2.pcm +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part3.cppm \ +// RUN: -include-pch %t/a.pch -o %t/Part3.pcm +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part4.cppm \ +// RUN: -include-pch %t/a.pch -o %t/Part4.pcm + +// RUN: %clang_cc1 -std=c++20 -emit-module-interface -fprebuilt-module-path=%t -fprebuilt-implicit-modules %t/Mod.cppm \ +// RUN: -include-pch %t/a.pch -o %t/Mod.pcm + + +//--- a.hpp +#pragma once + +class a { + virtual ~a(); + a() {} +}; + +//--- Part1.cppm +export module mod:part1; + +//--- Part2.cppm +export module mod:part2; + +//--- Part3.cppm +export module mod:part3; + +//--- Part4.cppm +export module mod:part4; + +//--- Mod.cppm +export module mod; +export import :part1; +export import :part2; +export import :part3; +export import :part4; + ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PATCH] [clang][modules] Fix serialization and de-serialization of PCH module file refs (#105994) (PR #132802)
https://github.com/koplas updated https://github.com/llvm/llvm-project/pull/132802 >From 2d143ca15476df04063e9e7e2c5fd1938c4f705b Mon Sep 17 00:00:00 2001 From: koplas Date: Mon, 24 Mar 2025 19:20:52 +0100 Subject: [PATCH 1/2] [PATCH] [clang][modules] Fix serialization and de-serialization of PCH module file refs (#105994) Co-authored-by: ShaderKeeper --- clang/lib/Serialization/ASTReader.cpp| 4 +- clang/test/Modules/MixedModulePrecompile.cpp | 63 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 clang/test/Modules/MixedModulePrecompile.cpp diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 2728e93c69516..7540ff5a3a95c 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -9615,7 +9615,7 @@ ModuleFile *ASTReader::getLocalModuleFile(ModuleFile &M, unsigned ID) const { // It's a prefix (preamble, PCH, ...). Look it up by index. unsigned IndexFromEnd = ID >> 1; assert(IndexFromEnd && "got reference to unknown module file"); -return getModuleManager().pch_modules().end()[-IndexFromEnd]; +return getModuleManager().pch_modules().end()[-static_cast(IndexFromEnd)]; } } @@ -9633,7 +9633,7 @@ unsigned ASTReader::getModuleFileID(ModuleFile *M) { auto PCHModules = getModuleManager().pch_modules(); auto I = llvm::find(PCHModules, M); assert(I != PCHModules.end() && "emitting reference to unknown file"); - return (I - PCHModules.end()) << 1; + return std::distance(I, PCHModules.end()) << 1; } std::optional ASTReader::getSourceDescriptor(unsigned ID) { diff --git a/clang/test/Modules/MixedModulePrecompile.cpp b/clang/test/Modules/MixedModulePrecompile.cpp new file mode 100644 index 0..473817ef71de6 --- /dev/null +++ b/clang/test/Modules/MixedModulePrecompile.cpp @@ -0,0 +1,63 @@ +// Tests mixed usage of precompiled headers and modules. +// +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t +// +// RUN: %clang_cc1 -std=c++20 -x c++-header -emit-pch %t/a.hpp \ +// RUN: -o %t/a.pch + +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part1.cppm \ +// RUN: -include-pch %t/a.pch -o %t/Part1.pcm +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part2.cppm \ +// RUN: -include-pch %t/a.pch -o %t/Part2.pcm +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part3.cppm \ +// RUN: -include-pch %t/a.pch -o %t/Part3.pcm +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part4.cppm \ +// RUN: -include-pch %t/a.pch -o %t/Part4.pcm + +// RUN: %clang_cc1 -std=c++20 -emit-module-interface \ +// RUN: -fmodule-file=mod:part1=%t/Part1.pcm \ +// RUN: -fmodule-file=mod:part2=%t/Part2.pcm \ +// RUN: -fmodule-file=mod:part3=%t/Part3.pcm \ +// RUN: -fmodule-file=mod:part4=%t/Part4.pcm \ +// RUN: %t/Mod.cppm \ +// RUN: -include-pch %t/a.pch -o %t/Mod.pcm + +// RUN: %clang_cc1 -std=c++20 -emit-obj \ +// RUN: -main-file-name Mod.cppm \ +// RUN: -fmodule-file=mod:part1=%t/Part1.pcm \ +// RUN: -fmodule-file=mod:part2=%t/Part2.pcm \ +// RUN: -fmodule-file=mod:part3=%t/Part3.pcm \ +// RUN: -fmodule-file=mod:part4=%t/Part4.pcm \ +// RUN: -x pcm %t/Mod.pcm \ +// RUN: -include-pch %t/a.pch -o %t/Mod.o + + +//--- a.hpp +#pragma once + +class a { + virtual ~a(); + a() {} +}; + +//--- Part1.cppm +export module mod:part1; + +//--- Part2.cppm +export module mod:part2; + +//--- Part3.cppm +export module mod:part3; + +//--- Part4.cppm +export module mod:part4; + +//--- Mod.cppm +export module mod; +export import :part1; +export import :part2; +export import :part3; +export import :part4; + >From 5dff7f9854c412f803d9b3e1931612f2dd2192f6 Mon Sep 17 00:00:00 2001 From: Paul Schwabauer Date: Tue, 25 Mar 2025 06:18:28 +0100 Subject: [PATCH 2/2] Address comment Co-authored-by: Chuanqi Xu --- clang/lib/Serialization/ASTReader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 7540ff5a3a95c..0cd2cedb48dd9 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -9613,7 +9613,7 @@ ModuleFile *ASTReader::getLocalModuleFile(ModuleFile &M, unsigned ID) const { return I == GlobalSubmoduleMap.end() ? nullptr : I->second; } else { // It's a prefix (preamble, PCH, ...). Look it up by index. -unsigned IndexFromEnd = ID >> 1; + int IndexFromEnd = static_cast(ID >> 1); assert(IndexFromEnd && "got reference to unknown module file"); return getModuleManager().pch_modules().end()[-static_cast(IndexFromEnd)]; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PATCH] [clang][frontend] Fix AllocKind retrieving for `CXXConstructorDecl` refs #132794 (PR #133077)
@@ -2601,10 +2601,11 @@ class CXXConstructorDecl final void anchor() override; size_t numTrailingObjects(OverloadToken) const { -return CXXConstructorDeclBits.IsInheritingConstructor; +return getCanonicalDecl()->CXXConstructorDeclBits.IsInheritingConstructor; } size_t numTrailingObjects(OverloadToken) const { -return CXXConstructorDeclBits.HasTrailingExplicitSpecifier; +return getCanonicalDecl() +->CXXConstructorDeclBits.HasTrailingExplicitSpecifier; koplas wrote: Done https://github.com/llvm/llvm-project/pull/133077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PATCH] [clang][frontend] Fix AllocKind retrieving for `CXXConstructorDecl` refs #132794 (PR #133077)
https://github.com/koplas edited https://github.com/llvm/llvm-project/pull/133077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PATCH] [clang][frontend] Fix AllocKind retrieving for `CXXConstructorDecl` refs #132794 (PR #133077)
https://github.com/koplas edited https://github.com/llvm/llvm-project/pull/133077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PATCH] [clang][frontend] Fix AllocKind retrieving for `CXXConstructorDecl` refs #132794 (PR #133077)
https://github.com/koplas created https://github.com/llvm/llvm-project/pull/133077 When getting the `ExplicitSpecifier` of the `CXXConstructorDecl`, one of the canonical declaration is returned. When writing the declaration record with `ExplicitSpecifier`, the `AllocKind` of the canonical declaration has to be used. If this is not done, it will later crash when on deserialization. TODO: Add reduced test from #132794. >From 98e6c674244099fd15e13026081caac9102f7c3d Mon Sep 17 00:00:00 2001 From: koplas Date: Wed, 26 Mar 2025 13:49:44 +0100 Subject: [PATCH] [PATCH] [clang][frontend] Fix AllocKind retrieving for `CXXConstructorDecl` refs #132794 When getting the `ExplicitSpecifier` of the `CXXConstructorDecl`, one of the canonical declaration is returned. When writing the declaration record with `ExplicitSpecifier`, the `AllocKind` of the canonical declaration has to be used. If this is not done it will later crash when on deserialization. --- clang/include/clang/AST/DeclCXX.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index dbd02ef7f8011..eaa9d9c526000 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -2601,10 +2601,10 @@ class CXXConstructorDecl final void anchor() override; size_t numTrailingObjects(OverloadToken) const { -return CXXConstructorDeclBits.IsInheritingConstructor; +return getCanonicalDecl()->CXXConstructorDeclBits.IsInheritingConstructor; } size_t numTrailingObjects(OverloadToken) const { -return CXXConstructorDeclBits.HasTrailingExplicitSpecifier; +return getCanonicalDecl()->CXXConstructorDeclBits.HasTrailingExplicitSpecifier; } ExplicitSpecifier getExplicitSpecifierInternal() const { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PATCH] [clang][frontend] Fix AllocKind retrieving for `CXXConstructorDecl` refs #132794 (PR #133077)
https://github.com/koplas updated https://github.com/llvm/llvm-project/pull/133077 >From d2da89cb6d2438b31ad25a05ec87d5f039e79064 Mon Sep 17 00:00:00 2001 From: koplas Date: Wed, 26 Mar 2025 13:49:44 +0100 Subject: [PATCH] [PATCH] [clang][frontend] Fix AllocKind retrieving for `CXXConstructorDecl` refs #132794 When getting the `ExplicitSpecifier` of the `CXXConstructorDecl`, one of the canonical declaration is returned. When writing the declaration record with `ExplicitSpecifier`, the `AllocKind` of the canonical declaration has to be used. If this is not done it will later crash when on deserialization. --- clang/include/clang/AST/DeclCXX.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index dbd02ef7f8011..7728669b3bcec 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -2601,10 +2601,11 @@ class CXXConstructorDecl final void anchor() override; size_t numTrailingObjects(OverloadToken) const { -return CXXConstructorDeclBits.IsInheritingConstructor; +return getCanonicalDecl()->CXXConstructorDeclBits.IsInheritingConstructor; } size_t numTrailingObjects(OverloadToken) const { -return CXXConstructorDeclBits.HasTrailingExplicitSpecifier; +return getCanonicalDecl() +->CXXConstructorDeclBits.HasTrailingExplicitSpecifier; } ExplicitSpecifier getExplicitSpecifierInternal() const { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PATCH] [clang][frontend] Fix AllocKind retrieving for `CXXConstructorDecl` refs #132794 (PR #133077)
https://github.com/koplas updated https://github.com/llvm/llvm-project/pull/133077 >From 86033b4b698ad11cf358b929e950f0b01e50390e Mon Sep 17 00:00:00 2001 From: koplas Date: Wed, 26 Mar 2025 13:49:44 +0100 Subject: [PATCH] [PATCH] [clang][frontend] Fix AllocKind retrieval for CXXConstructorDecl (refs #132794) When retrieving the ExplicitSpecifier from a CXXConstructorDecl, one of its canonical declarations is returned. To correctly write the declaration record with the ExplicitSpecifier, the AllocKind of that canonical declaration must be used. Failing to do so results in a crash during deserialization. --- clang/include/clang/AST/DeclCXX.h | 5 ++- .../test/Modules/ComplexExplicitSpecifier.cpp | 45 +++ 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 clang/test/Modules/ComplexExplicitSpecifier.cpp diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index dbd02ef7f8011..7728669b3bcec 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -2601,10 +2601,11 @@ class CXXConstructorDecl final void anchor() override; size_t numTrailingObjects(OverloadToken) const { -return CXXConstructorDeclBits.IsInheritingConstructor; +return getCanonicalDecl()->CXXConstructorDeclBits.IsInheritingConstructor; } size_t numTrailingObjects(OverloadToken) const { -return CXXConstructorDeclBits.HasTrailingExplicitSpecifier; +return getCanonicalDecl() +->CXXConstructorDeclBits.HasTrailingExplicitSpecifier; } ExplicitSpecifier getExplicitSpecifierInternal() const { diff --git a/clang/test/Modules/ComplexExplicitSpecifier.cpp b/clang/test/Modules/ComplexExplicitSpecifier.cpp new file mode 100644 index 0..33501ba264cc6 --- /dev/null +++ b/clang/test/Modules/ComplexExplicitSpecifier.cpp @@ -0,0 +1,45 @@ +// Tests complex explicit constructor across modules. +// +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t + +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Foo.cppm \ +// RUN: -o %t/Foo.pcm + +// RUN: %clang_cc1 -std=c++20 -emit-module-interface \ +// RUN: -fmodule-file=Foo=%t/Foo.pcm \ +// RUN: %t/Bar.cppm \ +// RUN: -o %t/Bar.pcm + +// RUN: %clang_cc1 -std=c++20 -emit-obj \ +// RUN: -main-file-name Bar.cppm \ +// RUN: -fmodule-file=Foo=%t/Foo.pcm \ +// RUN: -x pcm %t/Bar.pcm \ +// RUN: -o %t/Bar.o + +//--- Foo.cppm +export module Foo; + +export { +template +class Foo { + public: +template +explicit (sizeof...(Args) == 1) Foo(Args&&... args); +}; +} + +template +template +inline Foo::Foo(Args&&... args) {} + +//--- Bar.cppm +export module Bar; +import Foo; + +struct Bar {}; + +void a() { + auto foo = Foo{}; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PATCH] [clang][frontend] Fix AllocKind retrieving for `CXXConstructorDecl` refs #132794 (PR #133077)
https://github.com/koplas edited https://github.com/llvm/llvm-project/pull/133077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PATCH] [clang][frontend] Fix AllocKind retrieving for `CXXConstructorDecl` refs #132794 (PR #133077)
https://github.com/koplas edited https://github.com/llvm/llvm-project/pull/133077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PATCH] [clang][frontend] Fix AllocKind retrieving for `CXXConstructorDecl` refs #132794 (PR #133077)
https://github.com/koplas updated https://github.com/llvm/llvm-project/pull/133077 >From 686a9a772400316e5597409c7bd14f4d73e353bf Mon Sep 17 00:00:00 2001 From: koplas Date: Wed, 26 Mar 2025 13:49:44 +0100 Subject: [PATCH] [PATCH] [clang][frontend] Fix AllocKind retrieving for `CXXConstructorDecl` refs #132794 When getting the `ExplicitSpecifier` of the `CXXConstructorDecl`, one of the canonical declaration is returned. When writing the declaration record with `ExplicitSpecifier`, the `AllocKind` of the canonical declaration has to be used. If this is not done it will later crash when on deserialization. --- clang/include/clang/AST/DeclCXX.h | 5 ++- .../test/Modules/ComplexExplicitSpecifier.cpp | 45 +++ 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 clang/test/Modules/ComplexExplicitSpecifier.cpp diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index dbd02ef7f8011..7728669b3bcec 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -2601,10 +2601,11 @@ class CXXConstructorDecl final void anchor() override; size_t numTrailingObjects(OverloadToken) const { -return CXXConstructorDeclBits.IsInheritingConstructor; +return getCanonicalDecl()->CXXConstructorDeclBits.IsInheritingConstructor; } size_t numTrailingObjects(OverloadToken) const { -return CXXConstructorDeclBits.HasTrailingExplicitSpecifier; +return getCanonicalDecl() +->CXXConstructorDeclBits.HasTrailingExplicitSpecifier; } ExplicitSpecifier getExplicitSpecifierInternal() const { diff --git a/clang/test/Modules/ComplexExplicitSpecifier.cpp b/clang/test/Modules/ComplexExplicitSpecifier.cpp new file mode 100644 index 0..33501ba264cc6 --- /dev/null +++ b/clang/test/Modules/ComplexExplicitSpecifier.cpp @@ -0,0 +1,45 @@ +// Tests complex explicit constructor across modules. +// +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t + +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Foo.cppm \ +// RUN: -o %t/Foo.pcm + +// RUN: %clang_cc1 -std=c++20 -emit-module-interface \ +// RUN: -fmodule-file=Foo=%t/Foo.pcm \ +// RUN: %t/Bar.cppm \ +// RUN: -o %t/Bar.pcm + +// RUN: %clang_cc1 -std=c++20 -emit-obj \ +// RUN: -main-file-name Bar.cppm \ +// RUN: -fmodule-file=Foo=%t/Foo.pcm \ +// RUN: -x pcm %t/Bar.pcm \ +// RUN: -o %t/Bar.o + +//--- Foo.cppm +export module Foo; + +export { +template +class Foo { + public: +template +explicit (sizeof...(Args) == 1) Foo(Args&&... args); +}; +} + +template +template +inline Foo::Foo(Args&&... args) {} + +//--- Bar.cppm +export module Bar; +import Foo; + +struct Bar {}; + +void a() { + auto foo = Foo{}; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PATCH] [clang][frontend] Fix AllocKind retrieving for `CXXConstructorDecl` refs #132794 (PR #133077)
https://github.com/koplas ready_for_review https://github.com/llvm/llvm-project/pull/133077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PATCH] [clang][frontend] Fix AllocKind retrieving for `CXXConstructorDecl` refs #132794 (PR #133077)
https://github.com/koplas updated https://github.com/llvm/llvm-project/pull/133077 >From 81df4736822848b35959aa067fc9d056ed868946 Mon Sep 17 00:00:00 2001 From: koplas Date: Thu, 27 Mar 2025 08:00:54 +0100 Subject: [PATCH 1/2] [PATCH] [clang][frontend] Fix serialization for CXXConstructorDecl (refs llvm#132794) When retrieving the ExplicitSpecifier from a CXXConstructorDecl, one of its canonical declarations is returned. To correctly write the declaration record the ExplicitSpecifier of the current declaration must be used. Failing to do so results in a crash during deserialization. --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Serialization/ASTWriterDecl.cpp | 2 +- .../test/Modules/ComplexExplicitSpecifier.cpp | 45 +++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 clang/test/Modules/ComplexExplicitSpecifier.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 04ec2cfef679c..6acbe7131461c 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -316,6 +316,7 @@ Bug Fixes in This Version - Fixed a modules crash where exception specifications were not propagated properly (#GH121245, relanded in #GH129982) - Fixed a problematic case with recursive deserialization within ``FinishedDeserializing()`` where ``PassInterestingDeclsToConsumer()`` was called before the declarations were safe to be passed. (#GH129982) +- Fixed a modules crash where an explicit Constructor was deserialized. (GH#132794) Bug Fixes to Compiler Builtins ^^ diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp index 7014d7d291a5d..a14b8cf201bba 100644 --- a/clang/lib/Serialization/ASTWriterDecl.cpp +++ b/clang/lib/Serialization/ASTWriterDecl.cpp @@ -1726,7 +1726,7 @@ void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { "CXXConstructorDeclBits"); Record.push_back(D->getTrailingAllocKind()); - addExplicitSpecifier(D->getExplicitSpecifier(), Record); + addExplicitSpecifier(D->getExplicitSpecifierInternal(), Record); if (auto Inherited = D->getInheritedConstructor()) { Record.AddDeclRef(Inherited.getShadowDecl()); Record.AddDeclRef(Inherited.getConstructor()); diff --git a/clang/test/Modules/ComplexExplicitSpecifier.cpp b/clang/test/Modules/ComplexExplicitSpecifier.cpp new file mode 100644 index 0..33501ba264cc6 --- /dev/null +++ b/clang/test/Modules/ComplexExplicitSpecifier.cpp @@ -0,0 +1,45 @@ +// Tests complex explicit constructor across modules. +// +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t + +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Foo.cppm \ +// RUN: -o %t/Foo.pcm + +// RUN: %clang_cc1 -std=c++20 -emit-module-interface \ +// RUN: -fmodule-file=Foo=%t/Foo.pcm \ +// RUN: %t/Bar.cppm \ +// RUN: -o %t/Bar.pcm + +// RUN: %clang_cc1 -std=c++20 -emit-obj \ +// RUN: -main-file-name Bar.cppm \ +// RUN: -fmodule-file=Foo=%t/Foo.pcm \ +// RUN: -x pcm %t/Bar.pcm \ +// RUN: -o %t/Bar.o + +//--- Foo.cppm +export module Foo; + +export { +template +class Foo { + public: +template +explicit (sizeof...(Args) == 1) Foo(Args&&... args); +}; +} + +template +template +inline Foo::Foo(Args&&... args) {} + +//--- Bar.cppm +export module Bar; +import Foo; + +struct Bar {}; + +void a() { + auto foo = Foo{}; +} >From 2241ab9b21d6cf5e332978e5f7877d09fa3235b4 Mon Sep 17 00:00:00 2001 From: Paul Schwabauer Date: Thu, 27 Mar 2025 10:49:04 +0100 Subject: [PATCH 2/2] Fix GitHub reference Co-authored-by: cor3ntin --- clang/docs/ReleaseNotes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 6acbe7131461c..af063901ed62d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -316,7 +316,7 @@ Bug Fixes in This Version - Fixed a modules crash where exception specifications were not propagated properly (#GH121245, relanded in #GH129982) - Fixed a problematic case with recursive deserialization within ``FinishedDeserializing()`` where ``PassInterestingDeclsToConsumer()`` was called before the declarations were safe to be passed. (#GH129982) -- Fixed a modules crash where an explicit Constructor was deserialized. (GH#132794) +- Fixed a modules crash where an explicit Constructor was deserialized. (#GH132794) Bug Fixes to Compiler Builtins ^^ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PATCH] [clang][frontend] Fix AllocKind retrieving for `CXXConstructorDecl` refs #132794 (PR #133077)
koplas wrote: > LGTM, Thanks! Will you need me to merge that for you? Yes, I don't have any permissions to merge this. https://github.com/llvm/llvm-project/pull/133077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PATCH] [clang][frontend] Fix AllocKind retrieving for `CXXConstructorDecl` refs #132794 (PR #133077)
https://github.com/koplas updated https://github.com/llvm/llvm-project/pull/133077 >From 81df4736822848b35959aa067fc9d056ed868946 Mon Sep 17 00:00:00 2001 From: koplas Date: Thu, 27 Mar 2025 08:00:54 +0100 Subject: [PATCH] [PATCH] [clang][frontend] Fix serialization for CXXConstructorDecl (refs llvm#132794) When retrieving the ExplicitSpecifier from a CXXConstructorDecl, one of its canonical declarations is returned. To correctly write the declaration record the ExplicitSpecifier of the current declaration must be used. Failing to do so results in a crash during deserialization. --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Serialization/ASTWriterDecl.cpp | 2 +- .../test/Modules/ComplexExplicitSpecifier.cpp | 45 +++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 clang/test/Modules/ComplexExplicitSpecifier.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 04ec2cfef679c..6acbe7131461c 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -316,6 +316,7 @@ Bug Fixes in This Version - Fixed a modules crash where exception specifications were not propagated properly (#GH121245, relanded in #GH129982) - Fixed a problematic case with recursive deserialization within ``FinishedDeserializing()`` where ``PassInterestingDeclsToConsumer()`` was called before the declarations were safe to be passed. (#GH129982) +- Fixed a modules crash where an explicit Constructor was deserialized. (GH#132794) Bug Fixes to Compiler Builtins ^^ diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp index 7014d7d291a5d..a14b8cf201bba 100644 --- a/clang/lib/Serialization/ASTWriterDecl.cpp +++ b/clang/lib/Serialization/ASTWriterDecl.cpp @@ -1726,7 +1726,7 @@ void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { "CXXConstructorDeclBits"); Record.push_back(D->getTrailingAllocKind()); - addExplicitSpecifier(D->getExplicitSpecifier(), Record); + addExplicitSpecifier(D->getExplicitSpecifierInternal(), Record); if (auto Inherited = D->getInheritedConstructor()) { Record.AddDeclRef(Inherited.getShadowDecl()); Record.AddDeclRef(Inherited.getConstructor()); diff --git a/clang/test/Modules/ComplexExplicitSpecifier.cpp b/clang/test/Modules/ComplexExplicitSpecifier.cpp new file mode 100644 index 0..33501ba264cc6 --- /dev/null +++ b/clang/test/Modules/ComplexExplicitSpecifier.cpp @@ -0,0 +1,45 @@ +// Tests complex explicit constructor across modules. +// +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t + +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Foo.cppm \ +// RUN: -o %t/Foo.pcm + +// RUN: %clang_cc1 -std=c++20 -emit-module-interface \ +// RUN: -fmodule-file=Foo=%t/Foo.pcm \ +// RUN: %t/Bar.cppm \ +// RUN: -o %t/Bar.pcm + +// RUN: %clang_cc1 -std=c++20 -emit-obj \ +// RUN: -main-file-name Bar.cppm \ +// RUN: -fmodule-file=Foo=%t/Foo.pcm \ +// RUN: -x pcm %t/Bar.pcm \ +// RUN: -o %t/Bar.o + +//--- Foo.cppm +export module Foo; + +export { +template +class Foo { + public: +template +explicit (sizeof...(Args) == 1) Foo(Args&&... args); +}; +} + +template +template +inline Foo::Foo(Args&&... args) {} + +//--- Bar.cppm +export module Bar; +import Foo; + +struct Bar {}; + +void a() { + auto foo = Foo{}; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PATCH] [clang][frontend] Fix serialization for CXXConstructorDecl (refs llvm#132794) (PR #133077)
https://github.com/koplas edited https://github.com/llvm/llvm-project/pull/133077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PATCH] [clang][frontend] Fix serialization for CXXConstructorDecl (refs llvm#132794) (PR #133077)
koplas wrote: @shafik, I updated the commit message based on the feedback of @cor3ntin. I have now updated the title and description to reflect the new commit message, to avoid further confusion. https://github.com/llvm/llvm-project/pull/133077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PATCH] [clang][frontend] Fix serialization for CXXConstructorDecl (refs llvm#132794) (PR #133077)
https://github.com/koplas edited https://github.com/llvm/llvm-project/pull/133077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PATCH] [clang][frontend] Fix serialization for CXXConstructorDecl (refs llvm#132794) (PR #133077)
https://github.com/koplas edited https://github.com/llvm/llvm-project/pull/133077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PATCH] [clang][frontend] Fix AllocKind retrieving for `CXXConstructorDecl` refs #132794 (PR #133077)
https://github.com/koplas edited https://github.com/llvm/llvm-project/pull/133077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits