Issue 170059
Summary clang trunk: crash in ComplexExprEvaluator::VisitUnaryOperator during constant-_expression_ overflow check
Labels clang
Assignees
Reporter Theaamadu
    ## Compiler Explorer: https://godbolt.org/z/xnsn3b68r

- It crashed on clang `Trunk`
- generated by fuzzer

## Console
```console

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 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source>
1.	<source>:24:1: current parser token '}'
2.	<source>:8:40: parsing function body 'foo'
3.	<source>:8:40: in compound statement ('{}')
 #0 0x0000000004279728 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4279728)
 #1 0x0000000004276b54 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4276b54)
 #2 0x00000000041ba888 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x000078cfd5042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x000078cfd50969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x000078cfd5042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x000078cfd50287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00000000041c655a (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x41c655a)
 #8 0x0000000007c86b3b (anonymous namespace)::ComplexExprEvaluator::VisitCastExpr(clang::CastExpr const*) ExprConstant.cpp:0:0
 #9 0x0000000007c849af clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::ComplexExprEvaluator, bool>::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#10 0x0000000007c86138 (anonymous namespace)::ComplexExprEvaluator::VisitUnaryOperator(clang::UnaryOperator const*) ExprConstant.cpp:0:0
#11 0x0000000007c858a3 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::ComplexExprEvaluator, bool>::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#12 0x0000000007c86138 (anonymous namespace)::ComplexExprEvaluator::VisitUnaryOperator(clang::UnaryOperator const*) ExprConstant.cpp:0:0
#13 0x0000000007c858eb clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::ComplexExprEvaluator, bool>::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#14 0x0000000007c86073 EvaluateComplex(clang::Expr const*, (anonymous namespace)::ComplexValue&, (anonymous namespace)::EvalInfo&) ExprConstant.cpp:0:0
#15 0x0000000007c28b74 Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) ExprConstant.cpp:0:0
#16 0x0000000007c2959b EvaluateAsRValue((anonymous namespace)::EvalInfo&, clang::Expr const*, clang::APValue&) ExprConstant.cpp:0:0
#17 0x0000000007c2db2e clang::Expr::EvaluateForOverflow(clang::ASTContext const&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7c2db2e)
#18 0x0000000006bb1276 clang::Sema::CheckForIntOverflow(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6bb1276)
#19 0x0000000006bf5e0c clang::Sema::CheckCompletedExpr(clang::Expr*, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6bf5e0c)
#20 0x0000000006f96ec7 clang::Sema::ActOnFinishFullExpr(clang::Expr*, clang::SourceLocation, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6f96ec7)
#21 0x00000000072b333e clang::Sema::ActOnExprStmt(clang::ActionResult<clang::Expr*, true>, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x72b333e)
#22 0x0000000006a7bcc4 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6a7bcc4)
#23 0x0000000006a732b2 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 24u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6a732b2)
#24 0x0000000006a73c76 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 24u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6a73c76)
#25 0x0000000006a7c3fe clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6a7c3fe)
#26 0x0000000006a7cc4a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6a7cc4a)
#27 0x0000000006982aab clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6982aab)
#28 0x00000000069b8ecd clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x69b8ecd)
#29 0x000000000697625e clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x697625e)
#30 0x00000000069769ff clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x69769ff)
#31 0x000000000697e2b3 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x697e2b3)
#32 0x000000000697f1c5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x697f1c5)
#33 0x00000000069607aa clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x69607aa)
#34 0x0000000004bc8be8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4bc8be8)
#35 0x0000000004eb4455 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4eb4455)
#36 0x0000000004e3460e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4e3460e)
#37 0x0000000004fad48d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4fad48d)
#38 0x0000000000dc7780 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xdc7780)
#39 0x0000000000dbe1fa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#40 0x0000000000dbe37d int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#41 0x0000000004c313d9 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
#42 0x00000000041bad24 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x41bad24)
#43 0x0000000004c319ef 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
#44 0x0000000004bf21e2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4bf21e2)
#45 0x0000000004bf318e 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+0x4bf318e)
#46 0x0000000004bfa5c5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4bfa5c5)
#47 0x0000000000dc3ba1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xdc3ba1)
#48 0x0000000000c72574 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc72574)
#49 0x000078cfd5029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#50 0x000078cfd5029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#51 0x0000000000dbdc95 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xdbdc95)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```

## Code
```c
double _Complex f();
double _Complex p[10];

double _Complex foo(double _Complex x) {
 ++x;            /* { dg-bogus "value computed is not used" } */
  --x; /* { dg-bogus "value computed is not used" } */
  x += 1; /* { dg-bogus "value computed is not used" } */
  x += 1.0iF;     /* { dg-bogus "value computed is not used" } */
  x++;            /* { dg-bogus "value computed is not used" } */
  x--;            /* { dg-bogus "value computed is not used" } */
  x + 1;          /* { dg-warning "value computed is not used" } */
  (void)(x + 1);  /* { dg-bogus "value computed is not used" } */
  1 + f();        /* { dg-warning "value computed is not used" } */
  f() + f();      /* { dg-warning "value computed is not used" } */
  f() + f(), f(); /* { dg-warning "value computed is not used" } */
 f();
  (void)f();
  *p++; /* { dg-warning "value computed is not used" } */
  ++*p; /* { dg-bogus "value computed is not used" } */
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to