Skip to content

Assertion !isValueDependent() && "Expression evaluator can't be called on a dependent expression."' failed. #89013

Closed
@rupprecht

Description

@rupprecht

Live repro: https://godbolt.org/z/xdoYaYTTW

Clang at trunk crashes with this assertion:

clang++: /root/llvm-project/clang/lib/AST/ExprConstant.cpp:15828:
bool clang::Expr::EvaluateAsConstantExpr(clang::Expr::EvalResult&, const clang::ASTContext&, clang::Expr::ConstantExprKind) const:
Assertion !isValueDependent() && "Expression evaluator can't be called on a dependent expression."' failed.`

Possible dupe of #49570. This seems to be recently worse, as LLVM 18.1 does not crash -- it does, however, reject as invalid. I'm not sure if it would still crash if it were made valid.

#include <concepts>

// CRTP
template <typename T, typename ConcreteClass>
class Base {
   protected:
    Base() = default;
    ~Base() = default;
};

template <typename T>
class Derived final : public Base<T, Derived<T>> {};

template <typename T, typename D>
    requires std::derived_from<D, Base<T, D>>
class Foo {
   public:
    explicit Foo(D* d) {}
};

// CTAD
template <typename T, typename D>
Foo(Base<T, D>*) -> Foo<T, D>;

template <typename T>
using SpecialFoo = Foo<T, Derived<T>>;

SpecialFoo<int> Doit() { return SpecialFoo(new Derived<int>); }

Activity

added
clangClang issues not falling into any other category
crashPrefer [crash-on-valid] or [crash-on-invalid]
on Apr 17, 2024
added
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"
and removed
clangClang issues not falling into any other category
on Apr 17, 2024
llvmbot

llvmbot commented on Apr 17, 2024

@llvmbot
Member

@llvm/issue-subscribers-clang-frontend

Author: Jordan Rupprecht (rupprecht)

Live repro: https://godbolt.org/z/xdoYaYTTW

Clang at trunk crashes with this: clang++: /root/llvm-project/clang/lib/AST/ExprConstant.cpp:15828: bool clang::Expr::EvaluateAsConstantExpr(clang::Expr::EvalResult&amp;, const clang::ASTContext&amp;, clang::Expr::ConstantExprKind) const: Assertion !isValueDependent() &amp;&amp; "Expression evaluator can't be called on a dependent expression."' failed.

Possible dupe of #49570. This seems to be recently worse, as LLVM 18.1 does not crash -- it does, however, reject as invalid. I'm not sure if it would still crash if it were made valid.

#include &lt;concepts&gt;

// CRTP
template &lt;typename T, typename ConcreteClass&gt;
class Base {
   protected:
    Base() = default;
    ~Base() = default;
};

template &lt;typename T&gt;
class Derived final : public Base&lt;T, Derived&lt;T&gt;&gt; {};

template &lt;typename T, typename D&gt;
    requires std::derived_from&lt;D, Base&lt;T, D&gt;&gt;
class Foo {
   public:
    explicit Foo(D* d) {}
};

// CTAD
template &lt;typename T, typename D&gt;
Foo(Base&lt;T, D&gt;*) -&gt; Foo&lt;T, D&gt;;

template &lt;typename T&gt;
using SpecialFoo = Foo&lt;T, Derived&lt;T&gt;&gt;;

SpecialFoo&lt;int&gt; Doit() { return SpecialFoo(new Derived&lt;int&gt;); }
llvmbot

llvmbot commented on Apr 17, 2024

@llvmbot
Member

@llvm/issue-subscribers-c-20

Author: Jordan Rupprecht (rupprecht)

Live repro: https://godbolt.org/z/xdoYaYTTW

Clang at trunk crashes with this: clang++: /root/llvm-project/clang/lib/AST/ExprConstant.cpp:15828: bool clang::Expr::EvaluateAsConstantExpr(clang::Expr::EvalResult&amp;, const clang::ASTContext&amp;, clang::Expr::ConstantExprKind) const: Assertion !isValueDependent() &amp;&amp; "Expression evaluator can't be called on a dependent expression."' failed.

Possible dupe of #49570. This seems to be recently worse, as LLVM 18.1 does not crash -- it does, however, reject as invalid. I'm not sure if it would still crash if it were made valid.

#include &lt;concepts&gt;

// CRTP
template &lt;typename T, typename ConcreteClass&gt;
class Base {
   protected:
    Base() = default;
    ~Base() = default;
};

template &lt;typename T&gt;
class Derived final : public Base&lt;T, Derived&lt;T&gt;&gt; {};

template &lt;typename T, typename D&gt;
    requires std::derived_from&lt;D, Base&lt;T, D&gt;&gt;
class Foo {
   public:
    explicit Foo(D* d) {}
};

// CTAD
template &lt;typename T, typename D&gt;
Foo(Base&lt;T, D&gt;*) -&gt; Foo&lt;T, D&gt;;

template &lt;typename T&gt;
using SpecialFoo = Foo&lt;T, Derived&lt;T&gt;&gt;;

SpecialFoo&lt;int&gt; Doit() { return SpecialFoo(new Derived&lt;int&gt;); }
zyn0217

zyn0217 commented on Apr 17, 2024

@zyn0217
Contributor
shafik

shafik commented on Apr 17, 2024

@shafik
Collaborator

Backtrace:

PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 -stdlib=libc++ <source>
1.	<source>:28:61: current parser token ';'
2.	<source>:28:24: parsing function body 'Doit'
3.	<source>:28:24: in compound statement ('{}')
 #0 0x000000000393d208 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x393d208)
 #1 0x000000000393aeec llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x393aeec)
 #2 0x0000000003880fb8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f5f5a642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f5f5a6969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007f5f5a642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007f5f5a6287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007f5f5a62871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007f5f5a639e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x00000000074b27e8 clang::Expr::EvaluateAsConstantExpr(clang::Expr::EvalResult&, clang::ASTContext const&, clang::Expr::ConstantExprKind) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x74b27e8)
#10 0x00000000064bc5be clang::ActionResult<clang::Expr*, true> calculateConstraintSatisfaction<calculateConstraintSatisfaction(clang::Sema&, clang::NamedDecl const*, clang::SourceLocation, clang::MultiLevelTemplateArgumentList const&, clang::Expr const*, clang::ConstraintSatisfaction&)::'lambda'(clang::Expr const*)>(clang::Sema&, clang::Expr const*, clang::ConstraintSatisfaction&, calculateConstraintSatisfaction(clang::Sema&, clang::NamedDecl const*, clang::SourceLocation, clang::MultiLevelTemplateArgumentList const&, clang::Expr const*, clang::ConstraintSatisfaction&)::'lambda'(clang::Expr const*)&&) SemaConcept.cpp:0:0
#11 0x00000000064bcda2 CheckConstraintSatisfaction(clang::Sema&, clang::NamedDecl const*, llvm::ArrayRef<clang::Expr const*>, llvm::SmallVectorImpl<clang::Expr*>&, clang::MultiLevelTemplateArgumentList const&, clang::SourceRange, clang::ConstraintSatisfaction&) SemaConcept.cpp:0:0
#12 0x00000000064bd3da clang::Sema::CheckConstraintSatisfaction(clang::NamedDecl const*, llvm::ArrayRef<clang::Expr const*>, llvm::SmallVectorImpl<clang::Expr*>&, clang::MultiLevelTemplateArgumentList const&, clang::SourceRange, clang::ConstraintSatisfaction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x64bd3da)
#13 0x00000000064be49b clang::Sema::CheckInstantiatedFunctionTemplateConstraints(clang::SourceLocation, clang::FunctionDecl*, llvm::ArrayRef<clang::TemplateArgument>, clang::ConstraintSatisfaction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x64be49b)
#14 0x0000000006d44207 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 ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d44207)
#15 0x0000000006d459ea void llvm::function_ref<void ()>::callback_fn<clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool, bool, clang::QualType, clang::Expr::Classification, llvm::function_ref<bool (llvm::ArrayRef<clang::QualType>)>)::'lambda1'()>(long) SemaTemplateDeduction.cpp:0:0
#16 0x0000000006354461 clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6354461)
#17 0x0000000006d50262 clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool, bool, clang::QualType, clang::Expr::Classification, llvm::function_ref<bool (llvm::ArrayRef<clang::QualType>)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d50262)
#18 0x0000000006b3a53e clang::Sema::AddTemplateOverloadCandidate(clang::FunctionTemplateDecl*, clang::DeclAccessPair, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool, bool, bool, clang::CallExpr::ADLCallKind, clang::OverloadCandidateParamOrder, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b3a53e)
#19 0x0000000006999836 clang::Sema::DeduceTemplateSpecializationFromInitializer(clang::TypeSourceInfo*, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>)::'lambda0'(bool)::operator()(bool) const SemaInit.cpp:0:0
#20 0x000000000699a6df clang::Sema::DeduceTemplateSpecializationFromInitializer(clang::TypeSourceInfo*, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x699a6df)
#21 0x000000000689593d clang::Sema::BuildCXXTypeConstructExpr(clang::TypeSourceInfo*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x689593d)
#22 0x000000000692230d clang::Sema::ActOnCXXTypeConstructExpr(clang::OpaquePtr<clang::QualType>, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x692230d)
#23 0x0000000006281eb5 clang::Parser::ParseCXXTypeConstructExpression(clang::DeclSpec const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6281eb5)
#24 0x0000000006264db5 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6264db5)
#25 0x000000000626398a clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x626398a)
#26 0x00000000062669ca clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x62669ca)
#27 0x0000000006266b69 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6266b69)
#28 0x000000000626b4d9 clang::Parser::ParseExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x626b4d9)
#29 0x00000000062d9fa2 clang::Parser::ParseReturnStatement() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x62d9fa2)
#30 0x00000000062dd29a clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x62dd29a)
#31 0x00000000062de7f7 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x62de7f7)
#32 0x00000000062df701 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x62df701)
#33 0x00000000062e101a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x62e101a)
#34 0x00000000061fc691 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x61fc691)
#35 0x00000000062335fc clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x62335fc)
#36 0x00000000061f074e clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x61f074e)
#37 0x00000000061f0f43 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x61f0f43)
#38 0x00000000061f8466 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x61f8466)
#39 0x00000000061f930d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x61f930d)
#40 0x00000000061ebf5a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x61ebf5a)
#41 0x00000000041edcb8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41edcb8)
#42 0x000000000446d3c9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x446d3c9)
#43 0x00000000043f624e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43f624e)
#44 0x000000000455062e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x455062e)
#45 0x0000000000c45f8c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc45f8c)
#46 0x0000000000c3f21a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#47 0x0000000004230cd9 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
#48 0x0000000003881464 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3881464)
#49 0x00000000042312cf 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
#50 0x00000000041f7605 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41f7605)
#51 0x00000000041f806d 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+++0x41f806d)
#52 0x00000000041ffdf5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41ffdf5)
#53 0x0000000000c43425 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc43425)
#54 0x0000000000b26064 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xb26064)
#55 0x00007f5f5a629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#56 0x00007f5f5a629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#57 0x0000000000c3ed0e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc3ed0e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
shafik

shafik commented on Apr 18, 2024

@shafik
Collaborator

Reduced a bit: https://godbolt.org/z/c75YnMfde

#include <concepts>

class Base {};

template <typename T>
class Derived final : public Base {};

template <typename T, typename D>
    requires std::derived_from<D, Base>
struct Foo {
    explicit Foo(D) {}
};

template <typename T>
using SpecialFoo = Foo<int, Derived<T>>;

void Doit() {  SpecialFoo(Derived<int>{}); }
self-assigned this
on Apr 19, 2024

4 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

c++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"conceptsC++20 conceptscrashPrefer [crash-on-valid] or [crash-on-invalid]

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @rupprecht@hokein@shafik@EugeneZelenko@llvmbot

    Issue actions

      Assertion !isValueDependent() && "Expression evaluator can't be called on a dependent expression."' failed. · Issue #89013 · llvm/llvm-project