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

Crash in ActOnStartOfSwitchStmt #311

Closed
sam-mccall opened this issue Mar 18, 2020 · 0 comments
Closed

Crash in ActOnStartOfSwitchStmt #311

sam-mccall opened this issue Mar 18, 2020 · 0 comments
Labels
bug Something isn't working

Comments

@sam-mccall
Copy link
Member

crash.cc:

#include "crash.h"

namespace b { template<typename> bool xxx(); }
namespace c { int* xxx; }

void crash() { switch (xxx) {} }

crash.h:

namespace a { namespace xxx {} }

Removing any one of the xxxs eliminates the crash. Moving the namespace out of the header eliminates the crash.

clangd: /usr/local/google/home/sammccall/src/llvm-mono/clang/lib/Sema/SemaStmt.cpp:737: clang::StmtResult clang::Sema::ActOnStartOfSwitchStmt(clang::SourceLocation, clang::Stmt *, clang::Sema::ConditionResult): Assertion `CondExpr->getType()->isIntegralOrEnumerationType() && "invalid condition type"' failed.
 #0 0x00000000004f8524 PrintStackTrace /usr/local/google/home/sammccall/src/llvm-mono/llvm/lib/Support/Unix/Signals.inc:564:13
 #1 0x00000000004f8524 PrintStackTraceSignalHandler(void*) /usr/local/google/home/sammccall/src/llvm-mono/llvm/lib/Support/Unix/Signals.inc:624:0
 #2 0x00000000004f626c llvm::sys::RunSignalHandlers() /usr/local/google/home/sammccall/src/llvm-mono/llvm/lib/Support/Signals.cpp:69:18
 #3 0x00000000004f872c SignalHandler(int) /usr/local/google/home/sammccall/src/llvm-mono/llvm/lib/Support/Unix/Signals.inc:396:3
 #4 0x00007fe44dc44520 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x13520)
 #5 0x00007fe44d714081 raise /build/glibc-G5rUEF/glibc-2.29/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #6 0x00007fe44d6ff535 abort /build/glibc-G5rUEF/glibc-2.29/stdlib/abort.c:81:7
 #7 0x00007fe44d6ff40f _nl_load_domain /build/glibc-G5rUEF/glibc-2.29/intl/loadmsgcat.c:1177:9
 #8 0x00007fe44d70cb92 (/lib/x86_64-linux-gnu/libc.so.6+0x32b92)
 #9 0x0000000001a8e8c3 clang::Sema::ActOnStartOfSwitchStmt(clang::SourceLocation, clang::Stmt*, clang::Sema::ConditionResult) /usr/local/google/home/sammccall/src/llvm-mono/clang/lib/Sema/SemaStmt.cpp:0:0
#10 0x0000000001341be9 clang::Parser::ParseSwitchStatement(clang::SourceLocation*) /usr/local/google/home/sammccall/src/llvm-mono/clang/lib/Parse/ParseStmt.cpp:1490:15
#11 0x000000000133ed6b clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) /usr/local/google/home/sammccall/src/llvm-mono/clang/lib/Parse/ParseStmt.cpp:257:12
#12 0x000000000133e3aa clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) /usr/local/google/home/sammccall/src/llvm-mono/clang/lib/Parse/ParseStmt.cpp:106:20
#13 0x00000000013463d1 clang::Parser::ParseCompoundStatementBody(bool) /usr/local/google/home/sammccall/src/llvm-mono/clang/lib/Parse/ParseStmt.cpp:1079:11
#14 0x0000000001347310 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) /usr/local/google/home/sammccall/src/llvm-mono/clang/lib/Parse/ParseStmt.cpp:2204:21
#15 0x00000000012a562d clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) /usr/local/google/home/sammccall/src/llvm-mono/clang/lib/Parse/Parser.cpp:0:0
#16 0x00000000012c086b clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) /usr/local/google/home/sammccall/src/llvm-mono/clang/lib/Parse/ParseDecl.cpp:2069:16
#17 0x00000000012a46b2 clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) /usr/local/google/home/sammccall/src/llvm-mono/clang/lib/Parse/Parser.cpp:1109:10
#18 0x00000000012a40f5 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) /usr/local/google/home/sammccall/src/llvm-mono/clang/lib/Parse/Parser.cpp:1125:12
#19 0x00000000012a31c0 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) /usr/local/google/home/sammccall/src/llvm-mono/clang/lib/Parse/Parser.cpp:945:12
#20 0x00000000012a0fb6 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) /usr/local/google/home/sammccall/src/llvm-mono/clang/lib/Parse/Parser.cpp:696:10
#21 0x000000000129c358 clang::ParseAST(clang::Sema&, bool, bool) /usr/local/google/home/sammccall/src/llvm-mono/clang/lib/Parse/ParseAST.cpp:157:5
#22 0x00000000010ffd80 clang::FrontendAction::Execute() /usr/local/google/home/sammccall/src/llvm-mono/clang/lib/Frontend/FrontendAction.cpp:944:10
#23 0x0000000000aafaf0 getPtr /usr/local/google/home/sammccall/src/llvm-mono/llvm/include/llvm/Support/Error.h:273:42
@sam-mccall sam-mccall added the bug Something isn't working label Mar 18, 2020
arichardson pushed a commit to arichardson/llvm-project that referenced this issue Apr 2, 2020
Summary:
After we parse the switch condition, we don't do the type check for
type-dependent expr (e.g. TypoExpr) (in Sema::CheckSwitchCondition), then the
TypoExpr is corrected to an invalid-type expr (in Sema::MakeFullExpr) and passed
to the ActOnStartOfSwitchStmt, which triggers the assertion.

Fix clangd/clangd#311

Reviewers: sammccall

Subscribers: ilya-biryukov, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76592
mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this issue Oct 7, 2022
Summary:
After we parse the switch condition, we don't do the type check for
type-dependent expr (e.g. TypoExpr) (in Sema::CheckSwitchCondition), then the
TypoExpr is corrected to an invalid-type expr (in Sema::MakeFullExpr) and passed
to the ActOnStartOfSwitchStmt, which triggers the assertion.

Fix clangd/clangd#311

Reviewers: sammccall

Subscribers: ilya-biryukov, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76592
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant