Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clang] ICE at clang::Expr::EvaluateAsConstantExpr() #62362

Closed
alimpfard opened this issue Apr 25, 2023 · 9 comments
Closed

[Clang] ICE at clang::Expr::EvaluateAsConstantExpr() #62362

alimpfard opened this issue Apr 25, 2023 · 9 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party crash-on-valid

Comments

@alimpfard
Copy link

alimpfard commented Apr 25, 2023

clang: ../../clang/lib/AST/ExprConstant.cpp:15331: 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.
ICE Error Output
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: /home/test/Documents/oss/llvm-project/out/gn/bin/clang -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -main-file-name hpack.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/tmp -resource-dir /home/test/Documents/oss/llvm-project/out/gn/lib/clang/17 -internal-isystem /usr/lib64/gcc/x86_64-pc-linux-gnu/12.2.1/../../../../include/c++/12.2.1 -internal-isystem /usr/lib64/gcc/x86_64-pc-linux-gnu/12.2.1/../../../../include/c++/12.2.1/x86_64-pc-linux-gnu -internal-isystem /usr/lib64/gcc/x86_64-pc-linux-gnu/12.2.1/../../../../include/c++/12.2.1/backward -internal-isystem /home/test/Documents/oss/llvm-project/out/gn/lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /usr/lib64/gcc/x86_64-pc-linux-gnu/12.2.1/../../../../x86_64-pc-linux-gnu/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++20 -fdeprecated-macro -fdebug-compilation-dir=/tmp -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/hpack-1654b4.o -x c++ hpack.cpp
1.	hpack.cpp:17:17: current parser token ';'
2.	hpack.cpp:16:12: parsing function body 'foo'
3.	hpack.cpp:16:12: in compound statement ('{}')
 #0 0x000055c8c16a6992 PrintStackTraceSignalHandler(void*) (.llvm.15242681962188963970) Signals.cpp:0:0
 #1 0x000055c8c16a43d0 llvm::sys::RunSignalHandlers() (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x3a673d0)
 #2 0x000055c8c16a6d3d SignalHandler(int) Signals.cpp:0:0
 #3 0x00007fcd7fd69f50 (/usr/lib/libc.so.6+0x38f50)
 #4 0x00007fcd7fdb88ec (/usr/lib/libc.so.6+0x878ec)
 #5 0x00007fcd7fd69ea8 raise (/usr/lib/libc.so.6+0x38ea8)
 #6 0x00007fcd7fd5353d abort (/usr/lib/libc.so.6+0x2253d)
 #7 0x00007fcd7fd5345c (/usr/lib/libc.so.6+0x2245c)
 #8 0x00007fcd7fd629f6 (/usr/lib/libc.so.6+0x319f6)
 #9 0x000055c8c1f7ec6f clang::Expr::EvaluateAsConstantExpr(clang::Expr::EvalResult&, clang::ASTContext const&, clang::Expr::ConstantExprKind) const (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x4341c6f)
#10 0x000055c8c295748e clang::ActionResult<clang::Expr*, true> calculateConstraintSatisfaction<calculateConstraintSatisfaction(clang::Sema&, clang::NamedDecl const*, clang::SourceLocation, clang::MultiLevelTemplateArgumentList const&, clang::Expr const*, clang::ConstraintSatisfaction&)::$_7>(clang::Sema&, clang::Expr const*, clang::ConstraintSatisfaction&, calculateConstraintSatisfaction(clang::Sema&, clang::NamedDecl const*, clang::SourceLocation, clang::MultiLevelTemplateArgumentList const&, clang::Expr const*, clang::ConstraintSatisfaction&)::$_7&&) SemaConcept.cpp:0:0
#11 0x000055c8c295072e 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 0x000055c8c295024b clang::Sema::CheckConstraintSatisfaction(clang::NamedDecl const*, llvm::ArrayRef<clang::Expr const*>, llvm::SmallVectorImpl<clang::Expr*>&, clang::MultiLevelTemplateArgumentList const&, clang::SourceRange, clang::ConstraintSatisfaction&) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x4d1324b)
#13 0x000055c8c29524af clang::Sema::CheckFunctionConstraints(clang::FunctionDecl const*, clang::ConstraintSatisfaction&, clang::SourceLocation, bool) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x4d154af)
#14 0x000055c8c2be68f7 clang::Sema::DiagnoseUseOfDecl(clang::NamedDecl*, llvm::ArrayRef<clang::SourceLocation>, clang::ObjCInterfaceDecl const*, bool, bool, clang::ObjCInterfaceDecl*, bool) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x4fa98f7)
#15 0x000055c8c2e874c2 PerformConstructorInitialization(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, clang::InitializationSequence::Step const&, bool&, bool, bool, clang::SourceLocation, clang::SourceLocation) SemaInit.cpp:0:0
#16 0x000055c8c2e801ef clang::InitializationSequence::Perform(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, clang::QualType*) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x52431ef)
#17 0x000055c8c2d849c6 clang::Sema::BuildCXXTypeConstructExpr(clang::TypeSourceInfo*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, bool) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x51479c6)
#18 0x000055c8c2d83def clang::Sema::ActOnCXXTypeConstructExpr(clang::OpaquePtr<clang::QualType>, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, bool) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x5146def)
#19 0x000055c8c260463c clang::Parser::ParseCXXTypeConstructExpression(clang::DeclSpec const&) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x49c763c)
#20 0x000055c8c25aa9be clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x496d9be)
#21 0x000055c8c25a3bf4 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x4966bf4)
#22 0x000055c8c2639317 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) ParseStmt.cpp:0:0
#23 0x000055c8c2638962 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x49fb962)
#24 0x000055c8c26440c3 clang::Parser::ParseCompoundStatementBody(bool) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x4a070c3)
#25 0x000055c8c2644fd0 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x4a07fd0)
#26 0x000055c8c2584332 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x4947332)
#27 0x000055c8c25d7f43 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x499af43)
#28 0x000055c8c2581d9d clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x4944d9d)
#29 0x000055c8c258157c clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x494457c)
#30 0x000055c8c2580274 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x4943274)
#31 0x000055c8c257e132 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x4941132)
#32 0x000055c8c2578afe clang::ParseAST(clang::Sema&, bool, bool) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x493bafe)
#33 0x000055c8c0a331e5 clang::CodeGenAction::ExecuteAction() (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x2df61e5)
#34 0x000055c8c09474dd clang::FrontendAction::Execute() (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x2d0a4dd)
#35 0x000055c8c089c30f clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x2c5f30f)
#36 0x000055c8c0a2e5dc clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x2df15dc)
#37 0x000055c8bff75825 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x2338825)
#38 0x000055c8bff898ad ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#39 0x000055c8bff87d4f clang_main(int, char**, llvm::ToolContext const&) (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x234ad4f)
#40 0x000055c8bff8bb32 main (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x234eb32)
#41 0x00007fcd7fd54790 (/usr/lib/libc.so.6+0x23790)
#42 0x00007fcd7fd5484a __libc_start_main (/usr/lib/libc.so.6+0x2384a)
#43 0x000055c8bff74a85 _start (/home/test/Documents/oss/llvm-project/out/gn/bin/clang+0x2337a85)
clang++: error: unable to execute command: Aborted (core dumped)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 17.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/test//Documents/oss/llvm-project/out/gn/bin

Triggered by:

template <typename T, typename U> inline constexpr bool IsSame = false;
template <typename T> inline constexpr bool IsSame<T, T> = true;

struct Empty {};

template <typename T> struct Test {
  Test()
    requires(IsSame<T, Empty>);
};

template <>
struct Test<void> : public Test<Empty> {
  using Test<Empty>::Test;
};

void foo() {
    Test<void>();
}

(while reducing code for #62361, might be related)

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Apr 25, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 25, 2023

@llvm/issue-subscribers-clang-frontend

@alimpfard
Copy link
Author

alimpfard commented Apr 25, 2023

Might be just because gn enables assertions by default, will update or close after I test with assertions disabled.

Update: Yep, turning assertions off makes it go back to being a test case for #62361.

@shafik
Copy link
Collaborator

shafik commented Apr 25, 2023

Confirmed, may be related to #62344

@shafik shafik added confirmed Verified by a second party crash-on-valid and removed crash Prefer [crash-on-valid] or [crash-on-invalid] labels Apr 25, 2023
@erichkeane
Copy link
Collaborator

So this and #62344 end up being really similar, so I combined them. The repro is essentially:

https://godbolt.org/z/MTxMvdxET

template<typename T>
concept C = true;

template <typename T> struct Test {
  Test()
    requires(C<T>);
};

struct Bar : public Test<int> {
    using Test<int>::Test;
};

template <>
struct Test<void> : public Test<int> {
  using Test<int>::Test;
};

void foo() {
    Bar();
    Test<void>();
}

The problem is that while picking up template arguments to instantiate the constraint on Test::Test() as inherited, we don't end up picking up the template arguments to Test, thus leave it uninstantiated/dependent.

In the case of Bar, the problem is that despite us having a Test constructor, its DeclContext is Bar, and I don't see a way to figure out that it came from the 'using'. We have a handful of ConstructorUsingShadowDecl, but they don't seem to be related to the constructor that is found (which is a normal looking CXXConstructorDecl). If we could figure this out, we could at least make the ClassTemplateSpecializationDecl the correct 'parent' here.

In the case of Test<void>(), we actually DO get to the ClassTemplateSpecializationDecl correctly, however we get caught here: https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaTemplateInstantiate.cpp#L143

That is in place, I believe, so that out of line definitions don't have their depth wrong. I'm not sure how to tell the right thing to do HERE either, and I think that'll block the Bar example as well.

@erichkeane
Copy link
Collaborator

erichkeane commented Apr 26, 2023

I THINK i have a hold on it? This patch seems to fix both minimal reproducers: https://reviews.llvm.org/D149264

EDIT: Apparently not! This ended up breaking the original reproducer of #62344 in a different way. I'll have to work on another reduction.

@alimpfard
Copy link
Author

alimpfard commented Apr 26, 2023

That patch fixes the original non-reduced reproducer I have as well (that is, the code that #62361's repro is based on).

@zygoloid
Copy link
Collaborator

I just landed a fix for #62361, not noticing this issue existed! This too is fixed by 1e43349.

@erichkeane
Copy link
Collaborator

Confirm that @zygoloid 's patch fixes this, as well as the original repro of #62344 . Closing.

@nico
Copy link
Contributor

nico commented Apr 27, 2023

ref f539b6f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party crash-on-valid
Projects
None yet
Development

No branches or pull requests

7 participants