Issue 244974
Summary [clang] Assertion failure when mixing variable template partial specialization + constrained specialization across modules
Labels clang
Assignees
Reporter davidstone
    Given the following valid C++ program:

`header.hpp`:
```c++
template<typename> inline constexpr bool x = true;
template<typename T> requires true inline constexpr bool x<T> = true;
```

`a.cpp`
```c++
module;
#include "header.hpp"
export module a;
static_assert(x<void>);
```

`b.cpp`
```c++
#include "header.hpp"
import a;

template<typename = void>
struct s;

template<typename T>
constexpr bool x<s<T>> = true;

static_assert(x<s<void>>);
```

clang crashes with

```console
Step cmake returned: 0
-- The CXX compiler identification is Clang 24.0.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (0.3s)
-- Generating done (0.0s)
-- Build files have been written to: /app/build
Step build returned: 1
[1/6] Scanning /app/b.cpp for CXX dependencies
[2/6] Scanning /app/a.cpp for CXX dependencies
[3/6] Generating CXX dyndep file CMakeFiles/crash.dir/CXX.dd
[4/6] Building CXX object CMakeFiles/crash.dir/a.cpp.o
[5/6] Building CXX object CMakeFiles/crash.dir/b.cpp.o
FAILED: CMakeFiles/crash.dir/b.cpp.o 
/opt/compiler-explorer/clang-assertions-trunk/bin/clang++ --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot   -fcolor-diagnostics -fno-crash-diagnostics -std=c++23 -MD -MT CMakeFiles/crash.dir/b.cpp.o -MF CMakeFiles/crash.dir/b.cpp.o.d @CMakeFiles/crash.dir/b.cpp.o.modmap -o CMakeFiles/crash.dir/b.cpp.o -c /app/b.cpp
clang++: /root/llvm-project/llvm/tools/clang/lib/Sema/SemaTemplateDeduction.cpp:6667: clang::VarTemplatePartialSpecializationDecl* clang::Sema::getMoreSpecializedPartialSpecialization(clang::VarTemplatePartialSpecializationDecl*, clang::VarTemplatePartialSpecializationDecl*, clang::SourceLocation): Assertion `PS1->getSpecializedTemplate() == PS2->getSpecializedTemplate() && "the partial specializations being compared should specialize" " the same template."' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++23 -MD -MT CMakeFiles/crash.dir/b.cpp.o -MF CMakeFiles/crash.dir/b.cpp.o.d @CMakeFiles/crash.dir/b.cpp.o.modmap -o CMakeFiles/crash.dir/b.cpp.o -c /app/b.cpp
1.	/app/b.cpp:10:25: current parser token ')'
 #0 0x0000000004f94f78 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f94f78)
 #1 0x0000000004f921d4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f921d4)
 #2 0x0000000004f9280c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f9280c)
 #3 0x0000000004ecb7c8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #4 0x000075367c045330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
 #5 0x000075367c09ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
 #6 0x000075367c04527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
 #7 0x000075367c0288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
 #8 0x000075367c02881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
 #9 0x000075367c03b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x0000000009bde1fb clang::Sema::getMoreSpecializedPartialSpecialization(clang::VarTemplatePartialSpecializationDecl*, clang::VarTemplatePartialSpecializationDecl*, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x9bde1fb)
#11 0x0000000009b633df clang::Sema::CheckVarTemplateId(clang::VarTemplateDecl*, clang::SourceLocation, clang::SourceLocation, clang::TemplateArgumentListInfo const&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x9b633df)
#12 0x0000000009b63d44 clang::Sema::CheckVarTemplateId(clang::CXXScopeSpec const&, clang::DeclarationNameInfo const&, clang::VarTemplateDecl*, clang::NamedDecl*, clang::SourceLocation, clang::TemplateArgumentListInfo const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x9b63d44)
#13 0x0000000009b63fad clang::Sema::BuildTemplateIdExpr(clang::CXXScopeSpec const&, clang::SourceLocation, clang::LookupResult&, bool, clang::TemplateArgumentListInfo const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x9b63fad)
#14 0x000000000967fb80 clang::Sema::ActOnIdExpression(clang::Scope*, clang::CXXScopeSpec&, clang::SourceLocation, clang::UnqualifiedId&, bool, bool, clang::CorrectionCandidateCallback*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x967fb80)
#15 0x000000000916d003 clang::Parser::tryParseCXXIdExpression(clang::CXXScopeSpec&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x916d003)
#16 0x000000000916d3ae clang::Parser::ParseCXXIdExpression(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x916d3ae)
#17 0x000000000914aa99 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x914aa99)
#18 0x0000000009149f80 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x9149f80)
#19 0x00000000091572fe clang::Parser::ParseConstantExpressionInExprEvalContext(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x91572fe)
#20 0x000000000912e1e6 clang::Parser::ParseStaticAssertDeclaration(clang::SourceLocation&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x912e1e6)
#21 0x00000000091253c6 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x91253c6)
#22 0x00000000090d9430 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x90d9430)
#23 0x00000000090da325 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x90da325)
#24 0x00000000090b62ca clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x90b62ca)
#25 0x0000000005a9d078 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5a9d078)
#26 0x0000000005dc7e58 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5dc7e58)
#27 0x0000000005d543bd clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5d543bd)
#28 0x0000000005e9e403 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e9e403)
#29 0x00000000017248f8 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x17248f8)
#30 0x000000000171b7fa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#31 0x000000000171b983 int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#32 0x0000000005b168f9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#33 0x0000000004ecbbc4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ecbbc4)
#34 0x0000000005b17465 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#35 0x0000000005ad4282 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ad4282)
#36 0x0000000005ad753c clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ad753c)
#37 0x0000000005ae3a35 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ae3a35)
#38 0x0000000001720f4a clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1720f4a)
#39 0x00000000016ac803 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x16ac803)
#40 0x000075367c02a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#41 0x000075367c02a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#42 0x000000000171b1a5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x171b1a5)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Aborted (core dumped)
ninja: build stopped: subcommand failed.
```

See it live: https://godbolt.org/z/j1e4hq7Kj
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to