CTSRD-CHERI / llvm-project

Fork of LLVM adding CHERI support
48 stars 41 forks source link

llvm/ADT/FoldingSet: Assertion `Inserted == N && "Node already inserted!"' failed. #565

Open nwf opened 3 years ago

nwf commented 3 years ago

creduce minimized example:

// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu --mrelax-relocations -fmath-errno --compress-debug-sections=zlib -fcoverage-compilation-dir=/cheri/build/mainline/snmalloc2-native-build -std=gnu++20 -fno-signed-char -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o - -emit-llvm -O0 -Wimplicit-int  %s
     template<typename >
  concept a =
    requires
  {}template<typename b>
  concept c =
    a<b>
  class g 
  template<typename d>
  concept e =
    requires
    {
      d:f}template<e >
  class CoreAllocator  
  template<c >
  class h  {
    gCoreAllocator<h> i;
namespace using j = h<g>>;
  LocalAllocator<j>

Despite creduce's claimed command line, it reproduces with as little as

/cheri/out/mainline/sdk/bin/clang -cc1 -triple powerpc64le-unknown-linux-gnu -std=gnu++20 -o - -O0 /tmp/alloc1-c70889-pp-smaller-reduce.test.cpp

with the following crash:

clang: /cheri/source/mainline/llvm-project/llvm/include/llvm/ADT/FoldingSet.h:479: void llvm::FoldingSetImpl<llvm::ContextualFoldingSet<clang::ConstraintSatisfaction, const clang::ASTContext &>, clang::ConstraintSatisfaction>::InsertNode(T *) [Derived = llvm::ContextualFoldingSet<clang::ConstraintSatisfaction, const clang::ASTContext &>, T = clang::ConstraintSatisfaction]: Assertion `Inserted == N && "Node already inserted!"' failed.
PLEASE submit a bug report to https://github.com/CTSRD-CHERI/llvm-project/issues and include the crash backtrace, preprocessed source, and associated run script.
If you built clang from source, please provide a reduced test case by running:
        $LLVM_BUILD_DIR/bin/creduce_crash_testcase.py <reproducer>.sh
Stack dump:
0.      Program arguments: /cheri/out/mainline/sdk/bin/clang -cc1 -triple powerpc64le-unknown-linux-gnu --mrelax-relocations -fmath-errno --compress-debug-sections=zlib -fcoverage-compilation-dir=/cheri/build/mainline/snmalloc2-native-build -std=gnu++20 -fno-signed-char -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o - -emit-llvm -O0 -Wimplicit-int /tmp/alloc1-c70889-pp-smaller-reduce.test.cpp
1.      /tmp/alloc1-c70889-pp-smaller-reduce.test.cpp:19:3: at annotation token
 #0 0x00007fff8301fb04 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/cheri/out/mainline/sdk/bin/../lib/libLLVM-13git.so+0x232fb04)
 #1 0x00007fff8301ff04 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #2 0x00007fff8301cc78 llvm::sys::RunSignalHandlers() (/cheri/out/mainline/sdk/bin/../lib/libLLVM-13git.so+0x232cc78)
 #3 0x00007fff8302035c SignalHandler(int) Signals.cpp:0:0
 #4 0x00007fff8a010514 (linux-vdso64.so.1+0x514)
 #5 0x00007fff80727718 __libc_signal_restore_set ./signal/../sysdeps/unix/sysv/linux/internal-signals.h:86:3
 #6 0x00007fff80727718 raise ./signal/../sysdeps/unix/sysv/linux/raise.c:48:3
 #7 0x00007fff80707ce8 abort ./stdlib/abort.c:79:7
 #8 0x00007fff8071c2f0 __assert_fail_base ./assert/assert.c:92:3
 #9 0x00007fff8071c394 __assert_fail ./assert/assert.c:101:3
#10 0x00007fff882f307c clang::Sema::CheckConstraintSatisfaction(clang::NamedDecl const*, llvm::ArrayRef<clang::Expr const*>, llvm::ArrayRef<clang::TemplateArgument>, clang::SourceRange, clang::ConstraintSatisfaction&) (/cheri/out/mainline/sdk/bin/../lib/libclang-cpp.so.13git+0x1d9307c)
#11 0x00007fff8887ca24 clang::Sema::CheckConceptTemplateId(clang::CXXScopeSpec const&, clang::SourceLocation, clang::DeclarationNameInfo const&, clang::NamedDecl*, clang::ConceptDecl*, clang::TemplateArgumentListInfo const*) (/cheri/out/mainline/sdk/bin/../lib/libclang-cpp.so.13git+0x231ca24)
#12 0x00007fff889a6bc8 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformConceptSpecializationExpr(clang::ConceptSpecializationExpr*) SemaTemplateInstantiate.cpp:0:0
#13 0x00007fff88991a54 clang::Sema::SubstExpr(clang::Expr*, clang::MultiLevelTemplateArgumentList const&) (/cheri/out/mainline/sdk/bin/../lib/libclang-cpp.so.13git+0x2431a54)
#14 0x00007fff882f8f20 calculateConstraintSatisfaction(clang::Sema&, clang::NamedDecl const*, llvm::ArrayRef<clang::TemplateArgument>, clang::SourceLocation, clang::MultiLevelTemplateArgumentList&, clang::Expr const*, clang::ConstraintSatisfaction&)::$_5::operator()(clang::Expr const*) const SemaConcept.cpp:0:0
#15 0x00007fff882f85f0 bool calculateConstraintSatisfaction<calculateConstraintSatisfaction(clang::Sema&, clang::NamedDecl const*, llvm::ArrayRef<clang::TemplateArgument>, clang::SourceLocation, clang::MultiLevelTemplateArgumentList&, clang::Expr const*, clang::ConstraintSatisfaction&)::$_5>(clang::Sema&, clang::Expr const*, clang::ConstraintSatisfaction&, calculateConstraintSatisfaction(clang::Sema&, clang::NamedDecl const*, llvm::ArrayRef<clang::TemplateArgument>, clang::SourceLocation, clang::MultiLevelTemplateArgumentList&, clang::Expr const*, clang::ConstraintSatisfaction&)::$_5&&) SemaConcept.cpp:0:0
#16 0x00007fff882f2f00 clang::Sema::CheckConstraintSatisfaction(clang::NamedDecl const*, llvm::ArrayRef<clang::Expr const*>, llvm::ArrayRef<clang::TemplateArgument>, clang::SourceRange, clang::ConstraintSatisfaction&) (/cheri/out/mainline/sdk/bin/../lib/libclang-cpp.so.13git+0x1d92f00)
#17 0x00007fff882f37dc clang::Sema::EnsureTemplateArgumentListConstraints(clang::TemplateDecl*, llvm::ArrayRef<clang::TemplateArgument>, clang::SourceRange) (/cheri/out/mainline/sdk/bin/../lib/libclang-cpp.so.13git+0x1d937dc)
#18 0x00007fff88875cc0 clang::Sema::CheckTemplateArgumentList(clang::TemplateDecl*, clang::SourceLocation, clang::TemplateArgumentListInfo&, bool, llvm::SmallVectorImpl<clang::TemplateArgument>&, bool, bool*) (/cheri/out/mainline/sdk/bin/../lib/libclang-cpp.so.13git+0x2315cc0)
#19 0x00007fff888732fc clang::Sema::CheckTemplateIdType(clang::TemplateName, clang::SourceLocation, clang::TemplateArgumentListInfo&) (/cheri/out/mainline/sdk/bin/../lib/libclang-cpp.so.13git+0x23132fc)
#20 0x00007fff88876c94 clang::Sema::ActOnTemplateIdType(clang::Scope*, clang::CXXScopeSpec&, clang::SourceLocation, clang::OpaquePtr<clang::TemplateName>, clang::IdentifierInfo*, clang::SourceLocation, clang::SourceLocation, llvm::MutableArrayRef<clang::ParsedTemplateArgument>, clang::SourceLocation, bool, bool) (/cheri/out/mainline/sdk/bin/../lib/libclang-cpp.so.13git+0x2316c94)
#21 0x00007fff87840910 clang::Parser::AnnotateTemplateIdTokenAsType(clang::CXXScopeSpec&, bool) (/cheri/out/mainline/sdk/bin/../lib/libclang-cpp.so.13git+0x12e0910)
#22 0x00007fff8777a380 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*) (/cheri/out/mainline/sdk/bin/../lib/libclang-cpp.so.13git+0x121a380)
#23 0x00007fff878511cc clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/cheri/out/mainline/sdk/bin/../lib/libclang-cpp.so.13git+0x12f11cc)
#24 0x00007fff87850db8 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/cheri/out/mainline/sdk/bin/../lib/libclang-cpp.so.13git+0x12f0db8)
#25 0x00007fff8784fa70 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/cheri/out/mainline/sdk/bin/../lib/libclang-cpp.so.13git+0x12efa70)
#26 0x00007fff8784d6d4 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) (/cheri/out/mainline/sdk/bin/../lib/libclang-cpp.so.13git+0x12ed6d4)
#27 0x00007fff8775ee30 clang::ParseAST(clang::Sema&, bool, bool) (/cheri/out/mainline/sdk/bin/../lib/libclang-cpp.so.13git+0x11fee30)
#28 0x00007fff894607a8 clang::ASTFrontendAction::ExecuteAction() (/cheri/out/mainline/sdk/bin/../lib/libclang-cpp.so.13git+0x2f007a8)
#29 0x00007fff88dda930 clang::CodeGenAction::ExecuteAction() (/cheri/out/mainline/sdk/bin/../lib/libclang-cpp.so.13git+0x287a930)
#30 0x00007fff8945fd1c clang::FrontendAction::Execute() (/cheri/out/mainline/sdk/bin/../lib/libclang-cpp.so.13git+0x2effd1c)
#31 0x00007fff893cfdcc clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/cheri/out/mainline/sdk/bin/../lib/libclang-cpp.so.13git+0x2e6fdcc)
#32 0x00007fff894ee450 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/cheri/out/mainline/sdk/bin/../lib/libclang-cpp.so.13git+0x2f8e450)
#33 0x0000000010024ad4 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/cheri/out/mainline/sdk/bin/clang+0x10024ad4)
#34 0x00000000100220d4 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#35 0x0000000010021dd4 main (/cheri/out/mainline/sdk/bin/clang+0x10021dd4)
#36 0x00007fff8070814c generic_start_main ./csu/../csu/libc-start.c:308:16
#37 0x00007fff80708330 __libc_start_main ./csu/../sysdeps/unix/sysv/linux/powerpc/libc-start.c:98:10

FWIW, this does not reproduce against my host's clang, 11.0.1-2 from Debian. I don't happen to have an upstream clang laying around, but I can get one if it'd be useful.

jrtc27 commented 3 years ago

Hm, I can reproduce it but it produces a bunch of (legitimate) errors first, could you please reduce the original source to something that is valid C++ to make it easier to work with?

jrtc27 commented 3 years ago

Seems to be an upstream bug though that's still there https://godbolt.org/z/rjnhMYnzf (sadly all the other Clang targets have assertions disabled...)

nwf commented 3 years ago

I haven't yet tickled this assertion with something that doesn't also throw errors for one reason or another, but yes, if I do, I'll update.

jrtc27 commented 3 years ago

Oh, interesting