Open gburgessiv opened 7 years ago
@llvm/issue-subscribers-clang-frontend
I've marked this [clang:frontend] because I believe the placeholder type is not supposed to be making it all the way into the codegen stage. Yesterday I discovered a similar problem with an UnknownAny
placeholder making it further than it should. My test case won't reproduce on trunk; you have to edit getLValueReferenceType
to include assert(!T->isPlaceholderType() && "Unresolved placeholder type")
as its first line. But I claim (and @rjmccall in D118552 seemed to agree) that this should never happen.
extern __unknown_anytype var;
double *d = (double*)&var;
Clang says:
$ bin/clang++ -c -Xclang -funknown-anytype x.cpp
Assertion failed: (!T->isPlaceholderType() && "Unresolved placeholder type"), function getLValueReferenceType, file /tmp/llvm-project/clang/lib/AST/ASTContext.cpp, line 3375.
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: bin/clang++ -c -Xclang -funknown-anytype x.cpp
1. x.cpp:2:26: current parser token ';'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 clang++ 0x000000010d9564cd llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 61
1 clang++ 0x000000010d956a4b PrintStackTraceSignalHandler(void*) + 27
2 clang++ 0x000000010d95496a llvm::sys::RunSignalHandlers() + 138
3 clang++ 0x000000010d955d4e llvm::sys::CleanupOnSignal(unsigned long) + 110
4 clang++ 0x000000010d7e1b50 (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) + 192
5 clang++ 0x000000010d7e1f43 CrashRecoverySignalHandler(int) + 195
6 libsystem_platform.dylib 0x00007fff677255fd _sigtramp + 29
7 libsystem_platform.dylib 0x00007ffee629e940 _sigtramp + 18446744071540544352
8 libsystem_c.dylib 0x00007fff675fb808 abort + 120
9 libsystem_c.dylib 0x00007fff675faac6 err + 0
10 clang++ 0x0000000112cbf78f clang::ASTContext::getLValueReferenceType(clang::QualType, bool) const + 127
11 clang++ 0x00000001131ae04f (anonymous namespace)::getStorageType(clang::ASTContext const&, clang::Expr const*) + 95
12 clang++ 0x00000001131ad8aa clang::Expr::EvaluateAsConstantExpr(clang::Expr::EvalResult&, clang::ASTContext const&, clang::Expr::ConstantExprKind) const + 634
13 clang++ 0x0000000113023d03 clang::computeDependence(clang::UnaryOperator*, clang::ASTContext const&) + 275
14 clang++ 0x000000011319361b clang::UnaryOperator::UnaryOperator(clang::ASTContext const&, clang::Expr*, clang::UnaryOperatorKind, clang::QualType, clang::ExprValueKind, clang::ExprObjectKind, clang::SourceLocation, bool, clang::FPOptionsOverride) + 251
15 clang++ 0x000000011319370d clang::UnaryOperator::UnaryOperator(clang::ASTContext const&, clang::Expr*, clang::UnaryOperatorKind, clang::QualType, clang::ExprValueKind, clang::ExprObjectKind, clang::SourceLocation, bool, clang::FPOptionsOverride) + 125
16 clang++ 0x000000011319380e clang::UnaryOperator::Create(clang::ASTContext const&, clang::Expr*, clang::UnaryOperatorKind, clang::QualType, clang::ExprValueKind, clang::ExprObjectKind, clang::SourceLocation, bool, clang::FPOptionsOverride) + 238
17 clang++ 0x0000000111d95806 clang::Sema::CreateBuiltinUnaryOp(clang::SourceLocation, clang::UnaryOperatorKind, clang::Expr*) + 5062
18 clang++ 0x0000000111d8b622 clang::Sema::BuildUnaryOp(clang::Scope*, clang::SourceLocation, clang::UnaryOperatorKind, clang::Expr*) + 434
19 clang++ 0x0000000111dbf573 clang::Sema::ActOnUnaryOp(clang::Scope*, clang::SourceLocation, clang::tok::TokenKind, clang::Expr*) + 83
20 clang++ 0x000000011151f560 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) + 12784
21 clang++ 0x0000000111518cc9 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) + 89
22 clang++ 0x0000000111522d7a clang::Parser::ParseParenExpression(clang::Parser::ParenParseOption&, bool, bool, clang::OpaquePtr<clang::QualType>&, clang::SourceLocation&) + 5354
23 clang++ 0x000000011151c52c clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) + 444
24 clang++ 0x0000000111518cc9 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) + 89
25 clang++ 0x0000000111517158 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) + 280
26 clang++ 0x000000011150296a clang::Parser::ParseInitializer() + 58
Hmm. In this case, I think it would probably be difficult to refactor the constant evaluator to avoid building a reference type, and it might be easier to just relax the assertion to allow this specific placeholder type. I don't love that because of the possibilities it creates for "escapes", but it's probably a more resilient approach than trying to chase down all the places in C++ type-checking that try to build reference types from expression types. But thank you for chasing this down; the example and stack trace was instrumentally helpful.
@llvm/issue-subscribers-clang-codegen
The issue still reproduces as of Clang 16.0.0: https://godbolt.org/z/v8McTGdjY
Extended Description
Repro on trunk: