Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Assertion failure '!VD->mightBeUsableInConstantExpressions' in Clang #45834

Open Quuxplusone opened 4 years ago

Quuxplusone commented 4 years ago
Bugzilla Link PR46865
Status NEW
Importance P normal
Reported by Sunil Srivastava (sunil_srivastava@playstation.sony.com)
Reported on 2020-07-27 13:29:45 -0700
Last modified on 2020-08-26 12:10:25 -0700
Version trunk
Hardware PC Linux
CC blitzrakete@gmail.com, dgregor@apple.com, erich.keane@intel.com, erik.pilkington@gmail.com, hokein@google.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk, warren_ristow@playstation.sony.com
Fixed by commit(s)
Attachments c6.cpp (2392 bytes, text/plain)
c6-62bb79.cpp (2422 bytes, text/plain)
c6-62bb79.sh (1966 bytes, text/plain)
Blocks
Blocked by
See also
Created attachment 23776
Source

The attached test case, trimmed from a larger test case, gives an assertion
failure as shown below.

This run is with x86_64-unknown-linux-gnu triple on Linux.

This first started shows up in commit
https://github.com/llvm/llvm-project/commit/00068c452a599c328986e8,
but recent commits also gives same assertion.

$ clang -c -std=c++17 c6.cpp
clang: /home/sunil/CLANG-GIT/llvm-project/clang/lib/AST/ExprConstant.cpp:3079:
bool evaluateVarDeclInit({anonymous}::EvalInfo&, const clang::Expr*, const
clang::VarDecl*, {anonymous}::CallStackFrame*, clang::APValue*&, const
{anonymous}::LValue*): Assertion `!VD-
>mightBeUsableInConstantExpressions(Info.Ctx)' 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/sunil/CLANG-ARCHIVE/g23206/bin/clang -c -std=c++17
c6.cpp
1.  c6.cpp:66:1: current parser token '}'
2.  c6.cpp:55:67: parsing function body
'bottom_level_bvh_builder::compute_entire_bounding_box'
3.  c6.cpp:55:67: in compound statement ('{}')
 #0 0x000055f08b072b6a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x6cc9b6a)
 #1 0x000055f08b070794 llvm::sys::RunSignalHandlers() (/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x6cc7794)
 #2 0x000055f08b070a05 llvm::sys::CleanupOnSignal(unsigned long) (/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x6cc7a05)
 #3 0x000055f08afd5a98 CrashRecoverySignalHandler(int) (/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x6c2ca98)
 #4 0x00007ffb24b798a0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x128a0)
 #5 0x00007ffb2382af47 raise /build/glibc-2ORdQG/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #6 0x00007ffb2382c8b1 abort /build/glibc-2ORdQG/glibc-2.27/stdlib/abort.c:81:0
 #7 0x00007ffb2381c42a __assert_fail_base /build/glibc-2ORdQG/glibc-2.27/assert/assert.c:89:0
 #8 0x00007ffb2381c4a2 (/lib/x86_64-linux-gnu/libc.so.6+0x304a2)
 #9 0x000055f08d6a0bbe (/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x92f7bbe)
#10 0x000055f08d6be79f (anonymous
namespace)::LValueExprEvaluator::VisitVarDecl(clang::Expr const*,
clang::VarDecl const*) (/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x931579f)
#11 0x000055f08d6ebde1 (anonymous
namespace)::LValueExprEvaluator::VisitDeclRefExpr(clang::DeclRefExpr const*)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x9342de1)
#12 0x000055f08d6d1a84 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous
namespace)::LValueExprEvaluator, bool>::Visit(clang::Stmt const*)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x9328a84)
#13 0x000055f08d6ebdf5 (anonymous
namespace)::LValueExprEvaluator::VisitDeclRefExpr(clang::DeclRefExpr const*)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x9342df5)
#14 0x000055f08d6d1a84 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous
namespace)::LValueExprEvaluator, bool>::Visit(clang::Stmt const*)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x9328a84)
#15 0x000055f08d6d3630 EvaluateLValue(clang::Expr const*, (anonymous
namespace)::LValue&, (anonymous namespace)::EvalInfo&, bool) (/home/sunil/CLANG-
ARCHIVE/g23206/bin/clang+0x932a630)
#16 0x000055f08d6e72c1 (anonymous
namespace)::IntExprEvaluator::VisitCastExpr(clang::CastExpr const*)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x933e2c1)
#17 0x000055f08d6c040d clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous
namespace)::IntExprEvaluator, bool>::Visit(clang::Stmt const*)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x931740d)
#18 0x000055f08d6b5015 Evaluate(clang::APValue&, (anonymous
namespace)::EvalInfo&, clang::Expr const*) (/home/sunil/CLANG-
ARCHIVE/g23206/bin/clang+0x930c015)
#19 0x000055f08d6d2977 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous
namespace)::LValueExprEvaluator, bool>::Visit(clang::Stmt const*)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x9329977)
#20 0x000055f08d6d3630 EvaluateLValue(clang::Expr const*, (anonymous
namespace)::LValue&, (anonymous namespace)::EvalInfo&, bool) (/home/sunil/CLANG-
ARCHIVE/g23206/bin/clang+0x932a630)
#21 0x000055f08d6b4c31 Evaluate(clang::APValue&, (anonymous
namespace)::EvalInfo&, clang::Expr const*) (/home/sunil/CLANG-
ARCHIVE/g23206/bin/clang+0x930bc31)
#22 0x000055f08d6badae EvaluateAsRValue((anonymous namespace)::EvalInfo&,
clang::Expr const*, clang::APValue&) (/home/sunil/CLANG-
ARCHIVE/g23206/bin/clang+0x9311dae)
#23 0x000055f08d6bb366 clang::Expr::EvaluateForOverflow(clang::ASTContext
const&) const (/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x9312366)
#24 0x000055f08cc4387e clang::Sema::CheckForIntOverflow(clang::Expr*)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x889a87e)
#25 0x000055f08cc7b369 clang::Sema::CheckCompletedExpr(clang::Expr*,
clang::SourceLocation, bool) (/home/sunil/CLANG-
ARCHIVE/g23206/bin/clang+0x88d2369)
#26 0x000055f08cfeae9c clang::Sema::ActOnFinishFullExpr(clang::Expr*,
clang::SourceLocation, bool, bool) (/home/sunil/CLANG-
ARCHIVE/g23206/bin/clang+0x8c41e9c)
#27 0x000055f08d1bf034
clang::Sema::ActOnExprStmt(clang::ActionResult<clang::Expr*, true>, bool)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x8e16034)
#28 0x000055f08cafd463
clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x8754463)
#29 0x000055f08cafdf17
clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*,
32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*,
clang::Parser::ParsedAttributesWithRange&) (/home/sunil/CLANG-
ARCHIVE/g23206/bin/clang+0x8754f17)
#30 0x000055f08cafe771
clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*,
32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x8755771)
#31 0x000055f08cb02039 clang::Parser::ParseCompoundStatementBody(bool)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x8759039)
#32 0x000055f08cb0445b clang::Parser::ParseFunctionStatementBody(clang::Decl*,
clang::Parser::ParseScope&) (/home/sunil/CLANG-
ARCHIVE/g23206/bin/clang+0x875b45b)
#33 0x000055f08cae5bf4
clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&,
clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x873cbf4)
#34 0x000055f08cb7f048
clang::Parser::ParseSingleDeclarationAfterTemplate(clang::DeclaratorContext,
clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject&,
clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x87d6048)
#35 0x000055f08cb7fb1e
clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext,
clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x87d6b1e)
#36 0x000055f08cb7ff69
clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext,
clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x87d6f69)
#37 0x000055f08cb1bbc6
clang::Parser::ParseDeclaration(clang::DeclaratorContext,
clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&,
clang::SourceLocation*) (/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x8772bc6)
#38 0x000055f08cae6e7d
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*) (/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x873de7d)
#39 0x000055f08cae8209
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x873f209)
#40 0x000055f08cade259 clang::ParseAST(clang::Sema&, bool, bool)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x8735259)
#41 0x000055f08bac0618 clang::CodeGenAction::ExecuteAction() (/home/sunil/CLANG-
ARCHIVE/g23206/bin/clang+0x7717618)
#42 0x000055f08b9c8529 clang::FrontendAction::Execute() (/home/sunil/CLANG-
ARCHIVE/g23206/bin/clang+0x761f529)
#43 0x000055f08b92c482
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x7583482)
#44 0x000055f08ba93ea6
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/sunil/CLANG-
ARCHIVE/g23206/bin/clang+0x76eaea6)
#45 0x000055f088ebd35c cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x4b1435c)
#46 0x000055f088eb6339 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x4b0d339)
#47 0x000055f08b808bf5 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) (/home/sunil/CLANG-
ARCHIVE/g23206/bin/clang+0x745fbf5)
#48 0x000055f08afd5b73
llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x6c2cb73)
#49 0x000055f08b809538
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.146) (/home/sunil/CLANG-
ARCHIVE/g23206/bin/clang+0x7460538)
#50 0x000055f08b7e2175
clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&,
clang::driver::Command const*&) const (/home/sunil/CLANG-
ARCHIVE/g23206/bin/clang+0x7439175)
#51 0x000055f08b7e2c1f
clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&,
llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x7439c1f)
#52 0x000055f08b7eb5d9
clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&,
llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&)
(/home/sunil/CLANG-ARCHIVE/g23206/bin/clang+0x74425d9)
#53 0x000055f088eb9d0f main (/home/sunil/CLANG-
ARCHIVE/g23206/bin/clang+0x4b10d0f)
#54 0x00007ffb2380db97 __libc_start_main /build/glibc-2ORdQG/glibc-
2.27/csu/../csu/libc-start.c:344:0
#55 0x000055f088eb5b0a _start (/home/sunil/CLANG-
ARCHIVE/g23206/bin/clang+0x4b0cb0a)
clang-11: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 11.0.0 (https://github.com/llvm/llvm-project.git
00068c452a599c328986e8afcbb3311331d09d26)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/sunil/CLANG-ARCHIVE/g23206/bin
clang-11: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-11: note: diagnostic msg: /tmp/c6-62bb79.cpp
clang-11: note: diagnostic msg: /tmp/c6-62bb79.sh
clang-11: note: diagnostic msg:

********************
Quuxplusone commented 4 years ago

Attached c6.cpp (2392 bytes, text/plain): Source

Quuxplusone commented 4 years ago

Attached c6-62bb79.cpp (2422 bytes, text/plain): Preprocessed source file.

Quuxplusone commented 4 years ago

Attached c6-62bb79.sh (1966 bytes, text/plain): Clang generated shell script

Quuxplusone commented 4 years ago
I believe this is the same bug I ran into:

Reproducer:
template <class T> struct A {
        static T x;
        static T&& y;
};
template <class T> T A<T>::x = 59;
template <class T> T&& A<T>::y = x;
int z = A<wchar_t>::y;

Diagnostic (note, file names/line numbers removed):
error: rvalue reference to type 'wchar_t' cannot bind to lvalue of type
'wchar_t'
template <class T> T&& A<T>::y = x;
 note: in instantiation of static data member 'A<wchar_t>::y' requested here
int z = A<wchar_t>::y;

Assert log:
clang: /iusers/ekeane1/workspaces/llvm-
project/clang/lib/AST/ExprConstant.cpp:3079: bool
evaluateVarDeclInit({anonymous}::EvalInfo&, const clang::Expr*, const
clang::VarDecl*, {anonymous}::CallStackFrame*, clang::APValue*&, const
{anonymous}::LValue*): Assertion `!VD-
>mightBeUsableInConstantExpressions(Info.Ctx)' 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: ./bin/clang -cc1 cls_static03.cpp
1.      cls_static03.cpp:14:22: current parser token ';'
 #0 0x0000000004ba981c llvm::sys::PrintStackTrace(llvm::raw_ostream&) /iusers/ekeane1/workspaces/llvm-project/llvm/lib/Support/Unix/Signals.inc:564:22
 #1 0x0000000004ba98af PrintStackTraceSignalHandler(void*) /iusers/ekeane1/workspaces/llvm-project/llvm/lib/Support/Unix/Signals.inc:625:1
 #2 0x0000000004ba7941 llvm::sys::RunSignalHandlers() /iusers/ekeane1/workspaces/llvm-project/llvm/lib/Support/Signals.cpp:68:20
 #3 0x0000000004ba925f SignalHandler(int) /iusers/ekeane1/workspaces/llvm-project/llvm/lib/Support/Unix/Signals.inc:406:1
 #4 0x00007fbad340c5e0 __restore_rt (/lib64/libpthread.so.0+0xf5e0)
 #5 0x00007fbad1f851f7 raise (/lib64/libc.so.6+0x351f7)
 #6 0x00007fbad1f868e8 abort (/lib64/libc.so.6+0x368e8)
 #7 0x00007fbad1f7e266 __assert_fail_base (/lib64/libc.so.6+0x2e266)
 #8 0x00007fbad1f7e312 (/lib64/libc.so.6+0x2e312)
 #9 0x0000000008c2eca2 evaluateVarDeclInit((anonymous namespace)::EvalInfo&, clang::Expr const*, clang::VarDecl const*, (anonymous namespace)::CallStackFrame*, clang::APValue*&, (anonymous namespace)::LValue const*) /iusers/ekeane1/workspaces/llvm-project/clang/lib/AST/ExprConstant.cpp:3080:51
#10 0x0000000008c3f922 (anonymous
namespace)::LValueExprEvaluator::VisitVarDecl(clang::Expr const*,
clang::VarDecl const*) /iusers/ekeane1/workspaces/llvm-
project/clang/lib/AST/ExprConstant.cpp:7830:7
#11 0x0000000008c3f42e (anonymous
namespace)::LValueExprEvaluator::VisitDeclRefExpr(clang::DeclRefExpr const*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/AST/ExprConstant.cpp:7762:30
#12 0x0000000008c68a6a clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous
namespace)::LValueExprEvaluator, bool>::Visit(clang::Stmt const*)
/iusers/ekeane1/workspaces/llvm-project/build/tools/clang/include/clang/AST/StmtNodes.inc:979:1
#13 0x0000000008c3f38a EvaluateLValue(clang::Expr const*, (anonymous
namespace)::LValue&, (anonymous namespace)::EvalInfo&, bool)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/AST/ExprConstant.cpp:7755:66
#14 0x0000000008c5a8bf Evaluate(clang::APValue&, (anonymous
namespace)::EvalInfo&, clang::Expr const*) /iusers/ekeane1/workspaces/llvm-
project/clang/lib/AST/ExprConstant.cpp:13950:9
#15 0x0000000008c5b447 EvaluateAsRValue((anonymous namespace)::EvalInfo&,
clang::Expr const*, clang::APValue&) /iusers/ekeane1/workspaces/llvm-
project/clang/lib/AST/ExprConstant.cpp:14065:9
#16 0x0000000008c5b812 EvaluateAsRValue(clang::Expr const*,
clang::Expr::EvalResult&, clang::ASTContext const&, (anonymous
namespace)::EvalInfo&) /iusers/ekeane1/workspaces/llvm-
project/clang/lib/AST/ExprConstant.cpp:14122:46
#17 0x0000000008c5ba37 clang::Expr::EvaluateAsRValue(clang::Expr::EvalResult&,
clang::ASTContext const&, bool) const /iusers/ekeane1/workspaces/llvm-
project/clang/lib/AST/ExprConstant.cpp:14168:28
#18 0x00000000079ba287 GetExprRange(clang::ASTContext&, clang::Expr const*,
unsigned int, bool) /iusers/ekeane1/workspaces/llvm-
project/clang/lib/Sema/SemaChecking.cpp:10269:3
#19 0x00000000079baedd GetExprRange(clang::ASTContext&, clang::Expr const*,
bool) /iusers/ekeane1/workspaces/llvm-
project/clang/lib/Sema/SemaChecking.cpp:10491:1
#20 0x00000000079c143b CheckImplicitConversion(clang::Sema&, clang::Expr*,
clang::QualType, clang::SourceLocation, bool*, bool)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/SemaChecking.cpp:11878:76
#21 0x00000000079c25a6 AnalyzeImplicitConversions(clang::Sema&, (anonymous
namespace)::AnalyzeImplicitConversionsWorkItem,
llvm::SmallVectorImpl<(anonymous
namespace)::AnalyzeImplicitConversionsWorkItem>&)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/SemaChecking.cpp:12123:57
#22 0x00000000079c2d2b AnalyzeImplicitConversions(clang::Sema&, clang::Expr*,
clang::SourceLocation, bool) /iusers/ekeane1/workspaces/llvm-
project/clang/lib/Sema/SemaChecking.cpp:12208:3
#23 0x00000000079c3fc6 clang::Sema::CheckImplicitConversions(clang::Expr*,
clang::SourceLocation) /iusers/ekeane1/workspaces/llvm-
project/clang/lib/Sema/SemaChecking.cpp:12488:29
#24 0x00000000079c6dd1 clang::Sema::CheckCompletedExpr(clang::Expr*,
clang::SourceLocation, bool) /iusers/ekeane1/workspaces/llvm-
project/clang/lib/Sema/SemaChecking.cpp:13389:35
#25 0x0000000007f06327 clang::Sema::ActOnFinishFullExpr(clang::Expr*,
clang::SourceLocation, bool, bool) /iusers/ekeane1/workspaces/llvm-
project/clang/lib/Sema/SemaExprCXX.cpp:8362:19
#26 0x0000000007ae1f34 clang::Sema::AddInitializerToDecl(clang::Decl*,
clang::Expr*, bool) /iusers/ekeane1/workspaces/llvm-
project/clang/lib/Sema/SemaDecl.cpp:12147:73
#27 0x000000000781e3ae
clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&,
clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Parse/ParseDecl.cpp:2257:37
#28 0x000000000781d0c4 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&,
clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Parse/ParseDecl.cpp:1987:35
#29 0x00000000077ffa7e
clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec&, clang::AccessSpecifier)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Parse/Parser.cpp:1100:1
#30 0x00000000077ffb38
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*, clang::AccessSpecifier)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Parse/Parser.cpp:1115:57
#31 0x00000000077ff01a
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*) (.localalias.1) /iusers/ekeane1/workspaces/llvm-
project/clang/lib/Parse/Parser.cpp:935:58
#32 0x00000000077fe149
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Parse/Parser.cpp:683:42
#33 0x00000000077f9d4b clang::ParseAST(clang::Sema&, bool, bool)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Parse/ParseAST.cpp:158:37
#34 0x00000000056e7209 clang::ASTFrontendAction::ExecuteAction()
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1057:11
#35 0x00000000056e6b71 clang::FrontendAction::Execute()
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Frontend/FrontendAction.cpp:954:38
#36 0x0000000005681192
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:984:42
#37 0x000000000585d17c
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:278:38
#38 0x0000000002170cd6 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) /iusers/ekeane1/workspaces/llvm-
project/clang/tools/driver/cc1_main.cpp:240:40
#39 0x0000000002166c47 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&)
/iusers/ekeane1/workspaces/llvm-project/clang/tools/driver/driver.cpp:330:20
#40 0x0000000002167348 main /iusers/ekeane1/workspaces/llvm-
project/clang/tools/driver/driver.cpp:407:26
#41 0x00007fbad1f71c05 __libc_start_main (/lib64/libc.so.6+0x21c05)
#42 0x00000000021654e9 _start (./bin/clang+0x21654e9)
Aborted (core dumped)

The offending commit:
commit 00068c452a599c328986e8afcbb3311331d09d26
Author: Richard Smith <richard@metafoo.co.uk>
Date: Wed Jul 8 16:26:01 2020 -0700

Improve diagnostics for constant evaluation that fails because a
variable's initializer is not known.

The hope is that a better diagnostic for this case will reduce the rate
at which duplicates of non-bug PR41093 are reported.

Note, this MIGHT be a dupe of 46865
Quuxplusone commented 4 years ago
At the time of the crash:

(gdb) p VD->dump()
VarDecl 0x10faf700 parent 0x10f851f8 prev 0x10faf5a0 <cls_static03.cpp:12:20,
col:34> col:30 used y 'wchar_t &&' cinit
`-RecoveryExpr 0x10fafcd8 <col:34> '<dependent type>' contains-errors lvalue
  `-DeclRefExpr 0x10faf870 <col:34> 'wchar_t':'wchar_t' lvalue Var 0x10faf4b0 'x' 'wchar_t':'wchar_t'
$1 = void
(gdb) p Init->dump()
RecoveryExpr 0x10fafcd8 '<dependent type>' contains-errors lvalue
`-DeclRefExpr 0x10faf870 'wchar_t':'wchar_t' lvalue Var 0x10faf4b0 'x'
'wchar_t':'wchar_t'
$2 = void

This looks like another case where we aren't properly handling a RecoveryExpr.

I applied https://reviews.llvm.org/D84637 and the problem still exists.
Presumably we need to bail out of evaluating the VarDeclInit if the Init is
invalid.
Quuxplusone commented 4 years ago
Ok, so the original report doesn't have anything to do with .  It doesn't
involve recovery-exprs at all:

(gdb) p VD->dump()
VarDecl 0x10fc2630 <c6.cpp:63:15> col:15 implicit referenced box_chunk_size
'std::tuple_element<0, const std::tuple<unsigned int, unsigned int>>::type &'
cinit
`-CallExpr 0x10fc1a48 <col:15> 'const typename tuple_element<0UL,
tuple<unsigned int, unsigned int>>::type':'const unsigned int' lvalue adl
  |-ImplicitCastExpr 0x10fc1a30 <col:15> 'const typename tuple_element<0UL, tuple<unsigned int, unsigned int>>::type &(*)(const tuple<unsigned int, unsigned int> &) noexcept' <FunctionToPointerDecay>
  | `-DeclRefExpr 0x10fc1968 <col:15> 'const typename tuple_element<0UL, tuple<unsigned int, unsigned int>>::type &(const tuple<unsigned int, unsigned int> &) noexcept' lvalue Function 0x10fc1850 'get' 'const typename tuple_element<0UL, tuple<unsigned int, unsigned int>>::type &(const tuple<unsigned int, unsigned int> &) noexcept' (FunctionTemplate 0x10fb8190 'get')
  `-ImplicitCastExpr 0x10fbe4c8 <col:15> 'const std::tuple<unsigned int, unsigned int>':'const std::tuple<unsigned int, unsigned int>' xvalue <NoOp>
    `-DeclRefExpr 0x10fbe4a8 <col:15> 'const std::tuple<unsigned int, unsigned int>':'const std::tuple<unsigned int, unsigned int>' lvalue Decomposition 0x10fbc750 '' 'const std::tuple<unsigned int, unsigned int>':'const std::tuple<unsigned int, unsigned int>'
$1 = void
(gdb) p Init->dump()
CallExpr 0x10fc1a48 'const typename tuple_element<0UL, tuple<unsigned int,
unsigned int> >::type':'const unsigned int' lvalue adl
|-ImplicitCastExpr 0x10fc1a30 'const typename tuple_element<0UL, tuple<unsigned
int, unsigned int> >::type &(*)(const tuple<unsigned int, unsigned int> &)
noexcept' <FunctionToPointerDecay>
| `-DeclRefExpr 0x10fc1968 'const typename tuple_element<0UL, tuple<unsigned
int, unsigned int> >::type &(const tuple<unsigned int, unsigned int> &)
noexcept' lvalue Function 0x10fc1850 'get' 'const typename tuple_element<0UL,
tuple<unsigned int, unsigned int> >::type &(const tuple<unsigned int, unsigned
int> &) noexcept' (FunctionTemplate 0x10fb8190 'get')
`-ImplicitCastExpr 0x10fbe4c8 'const class std::tuple<unsigned int, unsigned
int>':'const class std::tuple<unsigned int, unsigned int>' xvalue <NoOp>
  `-DeclRefExpr 0x10fbe4a8 'const class std::tuple<unsigned int, unsigned int>':'const class std::tuple<unsigned int, unsigned int>' lvalue Decomposition 0x10fbc750 '' 'const class std::tuple<unsigned int, unsigned int>':'const class std::tuple<unsigned int, unsigned int>'
$2 = void
(gdb)

This is valid in a constant expression because it is a reference.  SO something
else is wrong with this.

SO I guess there are two bugs here now :/
Quuxplusone commented 4 years ago

Well, sorry to spam... but depending on the fix, I'm not sure there ARE two bugs here. My example fails the assert because the RecoveryExpr is a reference type as well.

Quuxplusone commented 4 years ago

Proposed a patch to fix this crash: https://reviews.llvm.org/D86649