Skip to content

[Clang] Crash when LogicalErrorHandler::hasActiveDiagnostics is true #63092

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

Closed
hazohelet opened this issue Jun 3, 2023 · 3 comments
Closed
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party crash Prefer [crash-on-valid] or [crash-on-invalid] duplicate Resolved as duplicate

Comments

@hazohelet
Copy link
Member

Reproducer:

struct Y {
    ~Y();
};

void test() {
    goto end;
    Y y;
end:;
}

Live demo: https://godbolt.org/z/jv871z7jM

Another, which causes assertion failure elsewhere

void test() {
    for (;; ({ continue; })) {}
}

Live demo: https://godbolt.org/z/rdMozhhMe

This crash seems to happen when LogicalErrorHandler::hasActiveDiagnostics evaluates true, which means that -Wtautological-overlap-compare or -Wtautological-bitwise-compare is enabled.

Both reproducers are reduced from clang test codes.

Note:
On the second code, GCC emits an error, while Clang does not.
GCC output:

<source>:2:16: error: continue statement not within a loop
    2 |     for (;; ({ continue; })) {
@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 Jun 3, 2023
@llvmbot
Copy link
Member

llvmbot commented Jun 3, 2023

@llvm/issue-subscribers-clang-frontend

@shafik
Copy link
Collaborator

shafik commented Jun 4, 2023

Confirmed: https://godbolt.org/z/EhfoTsooj

Assertion:

clang++: /root/llvm-project/clang/lib/Analysis/CFG.cpp:337:
int {anonymous}::LocalScope::const_iterator::distance({anonymous}::LocalScope::const_iterator):
Assertion `F != const_iterator() && "L iterator is not reachable from F iterator."' failed.

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 -fms-compatibility -Wtautological-bitwise-compare <source>
1.	<eof> parser at end of file
2.	<source>:5:13: parsing function body 'test'
 #0 0x00005622122258cf llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c108cf)
 #1 0x000056221222363c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c0e63c)
 #2 0x000056221216ccb8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f79bc266420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f79bbd3300b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007f79bbd12859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007f79bbd12729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007f79bbd23fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x00005622156c3154 (anonymous namespace)::CFGBuilder::addAutomaticObjHandling((anonymous namespace)::LocalScope::const_iterator, (anonymous namespace)::LocalScope::const_iterator, clang::Stmt*) (.isra.0) CFG.cpp:0:0
 #9 0x00005622156c463c (anonymous namespace)::CFGBuilder::VisitGotoStmt(clang::GotoStmt*) CFG.cpp:0:0
#10 0x00005622156cd42d (anonymous namespace)::CFGBuilder::VisitCompoundStmt(clang::CompoundStmt*, bool) CFG.cpp:0:0
#11 0x00005622156cf36c (anonymous namespace)::CFGBuilder::buildCFG(clang::Decl const*, clang::Stmt*) CFG.cpp:0:0
#12 0x00005622156d0b57 clang::CFG::buildCFG(clang::Decl const*, clang::Stmt*, clang::ASTContext*, clang::CFG::BuildOptions const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x70bbb57)
#13 0x00005622156745b0 clang::AnalysisDeclContext::getCFG() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x705f5b0)
#14 0x00005622155d0bd1 clang::sema::AnalysisBasedWarnings::IssueWarnings(clang::sema::AnalysisBasedWarnings::Policy, clang::sema::FunctionScopeInfo*, clang::Decl const*, clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6fbbbd1)
#15 0x0000562214ad7cc6 clang::Sema::PopFunctionScopeInfo(clang::sema::AnalysisBasedWarnings::Policy const*, clang::Decl const*, clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x64c2cc6)
#16 0x0000562214cd73bc clang::Sema::ActOnFinishFunctionBody(clang::Decl*, clang::Stmt*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66c23bc)
#17 0x0000562214a5475d clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x643f75d)
#18 0x000056221497f491 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x636a491)
#19 0x00005622149a6360 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6391360)
#20 0x0000562214972d31 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x635dd31)
#21 0x00005622149735ef clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#22 0x0000562214979f91 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6364f91)
#23 0x000056221497a906 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6365906)
#24 0x000056221496e6ca clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x63596ca)
#25 0x0000562213472738 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e5d738)
#26 0x0000562212cca8d9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x46b58d9)
#27 0x0000562212c4eda6 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4639da6)
#28 0x0000562212dad476 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4798476)
#29 0x000056220f6e311d cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x10ce11d)
#30 0x000056220f6dee1a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#31 0x0000562212ab6d6d 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
#32 0x000056221216d1c0 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b581c0)
#33 0x0000562212ab738f 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
#34 0x0000562212a7eabc clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4469abc)
#35 0x0000562212a7f54d 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+++0x446a54d)
#36 0x0000562212a8762d clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x447262d)
#37 0x000056220f6e137a clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x10cc37a)
#38 0x000056220f5e81f5 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xfd31f5)
#39 0x00007f79bbd14083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#40 0x000056220f6d9bfe _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x10c4bfe)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134

@shafik
Copy link
Collaborator

shafik commented Jun 4, 2023

The first one is almost identical to: #13325

Please file a second bug report for the second piece of code since they have different causes it seems.

@shafik shafik added duplicate Resolved as duplicate confirmed Verified by a second party labels Jun 4, 2023
@shafik shafik closed this as completed Jun 4, 2023
@EugeneZelenko EugeneZelenko closed this as not planned Won't fix, can't repro, duplicate, stale Jun 4, 2023
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 Prefer [crash-on-valid] or [crash-on-invalid] duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

4 participants