[llvm-bugs] [Bug 49737] New: Generic lambdas lead to Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Mar 26 21:11:56 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=49737

            Bug ID: 49737
           Summary: Generic lambdas lead to Assertion `isa<X>(Val) &&
                    "cast<Ty>() argument of incompatible type!"' failed
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: davidfromonline at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

The following valid translation unit

```
template<int>
using type = bool;

constexpr void call(auto arg) {
        arg(0);
}

template<int>
struct integer {};

template<int iteration>
auto do_iteration(integer<iteration>) {
        constexpr int index = 0;
        auto lambda = [](auto) -> type<index> {
        };
        call(lambda);
};

template<int... indexes>
void do_all() {
        (..., do_iteration(integer<indexes>()));
}

void f() {
        do_all<1>();
}
```

crashes clang with

```
clang++: /home/david/llvm/llvm/include/llvm/Support/Casting.h:269: typename
llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X =
clang::sema::CapturingScopeInfo; Y = clang::sema::FunctionScopeInfo; typename
llvm::cast_retty<X, Y*>::ret_type = clang::sema::CapturingScopeInfo*]:
Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash
backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /home/david/llvm/build/bin/clang++ -std=c++20 -w -o
/dev/null -c /home/david/test/main.cpp
1.      <eof> parser at end of file
2.      /home/david/test/main.cpp:20:6: instantiating function definition
'do_all<1>'
3.      /home/david/test/main.cpp:12:6: instantiating function definition
'do_iteration<1>'
4.      /home/david/test/main.cpp:4:16: instantiating function definition
'call<(lambda at /home/david/test/main.cpp:14:16)>'
 #0 0x000055e4a41bd6cd llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
(/home/david/llvm/build/bin/clang+++0x1f6a6cd)
 #1 0x000055e4a41bb2e4 llvm::sys::RunSignalHandlers()
(/home/david/llvm/build/bin/clang+++0x1f682e4)
 #2 0x000055e4a411b0d8 CrashRecoverySignalHandler(int)
CrashRecoveryContext.cpp:0:0
 #3 0x00007f9cadecf960 __restore_rt sigaction.c:0:0
 #4 0x00007f9cad914ef5 raise (/usr/lib/libc.so.6+0x3cef5)
 #5 0x00007f9cad8fe862 abort (/usr/lib/libc.so.6+0x26862)
 #6 0x00007f9cad8fe747 _nl_load_domain.cold loadmsgcat.c:0:0
 #7 0x00007f9cad90d646 (/usr/lib/libc.so.6+0x35646)
 #8 0x000055e4a664ffb5 clang::Sema::tryCaptureVariable(clang::VarDecl*,
clang::SourceLocation, clang::Sema::TryCaptureKind, clang::SourceLocation,
bool, clang::QualType&, clang::QualType&, unsigned int const*)
(/home/david/llvm/build/bin/clang+++0x43fcfb5)
 #9 0x000055e4a6655d41 clang::Sema::getCapturedDeclRefType(clang::VarDecl*,
clang::SourceLocation) (/home/david/llvm/build/bin/clang+++0x4402d41)
#10 0x000055e4a6656320
clang::Sema::BuildDeclarationNameExpr(clang::CXXScopeSpec const&,
clang::DeclarationNameInfo const&, clang::NamedDecl*, clang::NamedDecl*,
clang::TemplateArgumentListInfo const*, bool)
(/home/david/llvm/build/bin/clang+++0x4403320)
#11 0x000055e4a6b35529 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformDeclRefExpr(clang::DeclRefExpr*)
SemaTemplateInstantiate.cpp:0:0
#12 0x000055e4a6b246fc clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformTemplateArgument(clang::TemplateArgumentLoc
const&, clang::TemplateArgumentLoc&, bool) SemaTemplateInstantiate.cpp:0:0
#13 0x000055e4a6b26860 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformTemplateSpecializationType(clang::TypeLocBuilder&,
clang::TemplateSpecializationTypeLoc, clang::TemplateName)
SemaTemplateInstantiate.cpp:0:0
#14 0x000055e4a6b1a5a7 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformType(clang::TypeLocBuilder&,
clang::TypeLoc) SemaTemplateInstantiate.cpp:0:0
#15 0x000055e4a6b30d11
clang::Sema::SubstFunctionDeclType(clang::TypeSourceInfo*,
clang::MultiLevelTemplateArgumentList const&, clang::SourceLocation,
clang::DeclarationName, clang::CXXRecordDecl*, clang::Qualifiers)
(/home/david/llvm/build/bin/clang+++0x48ddd11)
#16 0x000055e4a6b4c219
clang::TemplateDeclInstantiator::SubstFunctionType(clang::FunctionDecl*,
llvm::SmallVectorImpl<clang::ParmVarDecl*>&)
(/home/david/llvm/build/bin/clang+++0x48f9219)
#17 0x000055e4a6b68a5a
clang::TemplateDeclInstantiator::VisitCXXMethodDecl(clang::CXXMethodDecl*,
clang::TemplateParameterList*,
llvm::Optional<clang::ASTTemplateArgumentListInfo const*>,
clang::TemplateDeclInstantiator::RewriteKind)
(/home/david/llvm/build/bin/clang+++0x4915a5a)
#18 0x000055e4a6b6f984 void llvm::function_ref<void
()>::callback_fn<clang::Sema::SubstDecl(clang::Decl*, clang::DeclContext*,
clang::MultiLevelTemplateArgumentList const&)::'lambda'()>(long)
SemaTemplateInstantiateDecl.cpp:0:0
#19 0x000055e4a631de31
clang::Sema::runWithSufficientStackSpace(clang::SourceLocation,
llvm::function_ref<void ()>) (/home/david/llvm/build/bin/clang+++0x40cae31)
#20 0x000055e4a6b4c0d2 clang::Sema::SubstDecl(clang::Decl*,
clang::DeclContext*, clang::MultiLevelTemplateArgumentList const&)
(/home/david/llvm/build/bin/clang+++0x48f90d2)
#21 0x000055e4a6ae2ef7
clang::Sema::FinishTemplateArgumentDeduction(clang::FunctionTemplateDecl*,
llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, unsigned int,
clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&,
llvm::SmallVectorImpl<clang::Sema::OriginalCallArg> const*, bool,
llvm::function_ref<bool ()>) (/home/david/llvm/build/bin/clang+++0x488fef7)
#22 0x000055e4a6ae41ca void llvm::function_ref<void
()>::callback_fn<clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*,
clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>,
clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool,
llvm::function_ref<bool (llvm::ArrayRef<clang::QualType>)>)::'lambda1'()>(long)
SemaTemplateDeduction.cpp:0:0
#23 0x000055e4a631de31
clang::Sema::runWithSufficientStackSpace(clang::SourceLocation,
llvm::function_ref<void ()>) (/home/david/llvm/build/bin/clang+++0x40cae31)
#24 0x000055e4a6af8db6
clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*,
clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>,
clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool,
llvm::function_ref<bool (llvm::ArrayRef<clang::QualType>)>)
(/home/david/llvm/build/bin/clang+++0x48a5db6)
#25 0x000055e4a695b2f9
clang::Sema::AddMethodTemplateCandidate(clang::FunctionTemplateDecl*,
clang::DeclAccessPair, clang::CXXRecordDecl*, clang::TemplateArgumentListInfo*,
clang::QualType, clang::Expr::Classification, llvm::ArrayRef<clang::Expr*>,
clang::OverloadCandidateSet&, bool, bool, clang::OverloadCandidateParamOrder)
(/home/david/llvm/build/bin/clang+++0x47082f9)
#26 0x000055e4a695b90c clang::Sema::AddMethodCandidate(clang::DeclAccessPair,
clang::QualType, clang::Expr::Classification, llvm::ArrayRef<clang::Expr*>,
clang::OverloadCandidateSet&, bool, clang::OverloadCandidateParamOrder)
(/home/david/llvm/build/bin/clang+++0x470890c)
#27 0x000055e4a697094e clang::Sema::BuildCallToObjectOfClassType(clang::Scope*,
clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>,
clang::SourceLocation) (/home/david/llvm/build/bin/clang+++0x471d94e)
#28 0x000055e4a6682044 clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*,
clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>,
clang::SourceLocation, clang::Expr*)
(/home/david/llvm/build/bin/clang+++0x442f044)
#29 0x000055e4a6b15a4e clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformCallExpr(clang::CallExpr*)
SemaTemplateInstantiate.cpp:0:0
#30 0x000055e4a6b3ee4f clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*,
clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::StmtDiscardKind)
SemaTemplateInstantiate.cpp:0:0
#31 0x000055e4a6b40691 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*,
bool) SemaTemplateInstantiate.cpp:0:0
#32 0x000055e4a6b45385 clang::Sema::SubstStmt(clang::Stmt*,
clang::MultiLevelTemplateArgumentList const&)
(/home/david/llvm/build/bin/clang+++0x48f2385)
#33 0x000055e4a6b618f2
clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation,
clang::FunctionDecl*, bool, bool, bool)
(/home/david/llvm/build/bin/clang+++0x490e8f2)
#34 0x000055e4a631de31
clang::Sema::runWithSufficientStackSpace(clang::SourceLocation,
llvm::function_ref<void ()>) (/home/david/llvm/build/bin/clang+++0x40cae31)
#35 0x000055e4a664a63c
clang::Sema::MarkFunctionReferenced(clang::SourceLocation,
clang::FunctionDecl*, bool) (/home/david/llvm/build/bin/clang+++0x43f763c)
#36 0x000055e4a66516a2 MarkExprReferenced(clang::Sema&, clang::SourceLocation,
clang::Decl*, clang::Expr*, bool) SemaExpr.cpp:0:0
#37 0x000055e4a6655511 clang::Sema::BuildDeclRefExpr(clang::ValueDecl*,
clang::QualType, clang::ExprValueKind, clang::DeclarationNameInfo const&,
clang::NestedNameSpecifierLoc, clang::NamedDecl*, clang::SourceLocation,
clang::TemplateArgumentListInfo const*)
(/home/david/llvm/build/bin/clang+++0x4402511)
#38 0x000055e4a6945e3a
clang::Sema::FixOverloadedFunctionReference(clang::Expr*,
clang::DeclAccessPair, clang::FunctionDecl*)
(/home/david/llvm/build/bin/clang+++0x46f2e3a)
#39 0x000055e4a696d8fb FinishOverloadedCallExpr(clang::Sema&, clang::Scope*,
clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation,
llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*,
clang::OverloadCandidateSet*, clang::OverloadCandidate**,
clang::OverloadingResult, bool) SemaOverload.cpp:0:0
#40 0x000055e4a696ea19 clang::Sema::BuildOverloadedCallExpr(clang::Scope*,
clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation,
llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool,
bool) (/home/david/llvm/build/bin/clang+++0x471ba19)
#41 0x000055e4a6680f9f clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*,
clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>,
clang::SourceLocation, clang::Expr*, bool, bool)
(/home/david/llvm/build/bin/clang+++0x442df9f)
#42 0x000055e4a6682044 clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*,
clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>,
clang::SourceLocation, clang::Expr*)
(/home/david/llvm/build/bin/clang+++0x442f044)
#43 0x000055e4a6b15a4e clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformCallExpr(clang::CallExpr*)
SemaTemplateInstantiate.cpp:0:0
#44 0x000055e4a6b3ee4f clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*,
clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::StmtDiscardKind)
SemaTemplateInstantiate.cpp:0:0
#45 0x000055e4a6b40691 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*,
bool) SemaTemplateInstantiate.cpp:0:0
#46 0x000055e4a6b45385 clang::Sema::SubstStmt(clang::Stmt*,
clang::MultiLevelTemplateArgumentList const&)
(/home/david/llvm/build/bin/clang+++0x48f2385)
#47 0x000055e4a6b618f2
clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation,
clang::FunctionDecl*, bool, bool, bool)
(/home/david/llvm/build/bin/clang+++0x490e8f2)
#48 0x000055e4a631de31
clang::Sema::runWithSufficientStackSpace(clang::SourceLocation,
llvm::function_ref<void ()>) (/home/david/llvm/build/bin/clang+++0x40cae31)
#49 0x000055e4a6aaafd7 clang::Sema::DeduceReturnType(clang::FunctionDecl*,
clang::SourceLocation, bool) (/home/david/llvm/build/bin/clang+++0x4857fd7)
#50 0x000055e4a663d574 clang::Sema::DiagnoseUseOfDecl(clang::NamedDecl*,
llvm::ArrayRef<clang::SourceLocation>, clang::ObjCInterfaceDecl const*, bool,
bool, clang::ObjCInterfaceDecl*) (/home/david/llvm/build/bin/clang+++0x43ea574)
#51 0x000055e4a696dc5e FinishOverloadedCallExpr(clang::Sema&, clang::Scope*,
clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation,
llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*,
clang::OverloadCandidateSet*, clang::OverloadCandidate**,
clang::OverloadingResult, bool) SemaOverload.cpp:0:0
#52 0x000055e4a696ea19 clang::Sema::BuildOverloadedCallExpr(clang::Scope*,
clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation,
llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool,
bool) (/home/david/llvm/build/bin/clang+++0x471ba19)
#53 0x000055e4a6680f9f clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*,
clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>,
clang::SourceLocation, clang::Expr*, bool, bool)
(/home/david/llvm/build/bin/clang+++0x442df9f)
#54 0x000055e4a6682044 clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*,
clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>,
clang::SourceLocation, clang::Expr*)
(/home/david/llvm/build/bin/clang+++0x442f044)
#55 0x000055e4a6b15a4e clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformCallExpr(clang::CallExpr*)
SemaTemplateInstantiate.cpp:0:0
#56 0x000055e4a6b1469c clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformCXXFoldExpr(clang::CXXFoldExpr*)
SemaTemplateInstantiate.cpp:0:0
#57 0x000055e4a6b3ee4f clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*,
clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::StmtDiscardKind)
SemaTemplateInstantiate.cpp:0:0
#58 0x000055e4a6b40691 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*,
bool) SemaTemplateInstantiate.cpp:0:0
#59 0x000055e4a6b45385 clang::Sema::SubstStmt(clang::Stmt*,
clang::MultiLevelTemplateArgumentList const&)
(/home/david/llvm/build/bin/clang+++0x48f2385)
#60 0x000055e4a6b618f2
clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation,
clang::FunctionDecl*, bool, bool, bool)
(/home/david/llvm/build/bin/clang+++0x490e8f2)
#61 0x000055e4a6b5f79f clang::Sema::PerformPendingInstantiations(bool)
(/home/david/llvm/build/bin/clang+++0x490c79f)
#62 0x000055e4a633c3eb
clang::Sema::ActOnEndOfTranslationUnitFragment(clang::Sema::TUFragmentKind)
(.part.0) Sema.cpp:0:0
#63 0x000055e4a633cc56 clang::Sema::ActOnEndOfTranslationUnit()
(/home/david/llvm/build/bin/clang+++0x40e9c56)
#64 0x000055e4a6217dde
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool)
(/home/david/llvm/build/bin/clang+++0x3fc4dde)
#65 0x000055e4a620a119 clang::ParseAST(clang::Sema&, bool, bool)
(/home/david/llvm/build/bin/clang+++0x3fb7119)
#66 0x000055e4a4b4f319 clang::FrontendAction::Execute()
(/home/david/llvm/build/bin/clang+++0x28fc319)
#67 0x000055e4a4adfca6
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/home/david/llvm/build/bin/clang+++0x288cca6)
#68 0x000055e4a4c124d3
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/home/david/llvm/build/bin/clang+++0x29bf4d3)
#69 0x000055e4a2e2fbd1 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/home/david/llvm/build/bin/clang+++0xbdcbd1)
#70 0x000055e4a2e2b380 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&)
driver.cpp:0:0
#71 0x000055e4a4972b75 void llvm::function_ref<void
()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>
>, std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#72 0x000055e4a411b264
llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>)
(/home/david/llvm/build/bin/clang+++0x1ec8264)
#73 0x000055e4a4973d8b
clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>
>, std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >*, bool*) const (.part.0) Job.cpp:0:0
#74 0x000055e4a4946888
clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&,
clang::driver::Command const*&) const
(/home/david/llvm/build/bin/clang+++0x26f3888)
#75 0x000055e4a49473b9
clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&,
llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const
(/home/david/llvm/build/bin/clang+++0x26f43b9)
#76 0x000055e4a4953681
clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&,
llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&)
(/home/david/llvm/build/bin/clang+++0x2700681)
#77 0x000055e4a2d977b8 main (/home/david/llvm/build/bin/clang+++0xb447b8)
#78 0x00007f9cad8ffb25 __libc_start_main (/usr/lib/libc.so.6+0x27b25)
#79 0x000055e4a2e2acfe _start (/home/david/llvm/build/bin/clang+++0xbd7cfe)
clang-13: error: clang frontend command failed with exit code 134 (use -v to
see invocation)
clang version 13.0.0 (https://github.com/llvm/llvm-project.git
bba02afdf6917a0c4f82bc4e10010b5c9db76867)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/david/llvm/build/bin
clang-13: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-13: note: diagnostic msg: /tmp/main-406e21.cpp
clang-13: note: diagnostic msg: /tmp/main-406e21.sh
clang-13: note: diagnostic msg: 

********************
```

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210327/590d7317/attachment-0001.html>


More information about the llvm-bugs mailing list