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

clang-12 crashes on clang::Expr::EvaluateForOverflow #53742

Closed
Badhi opened this issue Feb 11, 2022 · 4 comments
Closed

clang-12 crashes on clang::Expr::EvaluateForOverflow #53742

Badhi opened this issue Feb 11, 2022 · 4 comments
Labels
bug Indicates an unexpected problem or unintended behavior clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party

Comments

@Badhi
Copy link

Badhi commented Feb 11, 2022

clang crashes for the following code

struct Data {
    char* a;
    char* b;
    bool* c;
};

int main()
{
    Data in;
    in.a = new char[]();
    in.c = new bool[100]();
    in.b = new char[100]();
}

clang-12 output

./test.cpp:10:16: error: cannot determine allocated array size from initializer
    in.a = new char[]();
               ^
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: /usr/lib/llvm-12/bin/clang -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib/llvm-12/lib/clang/12.0.0 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/x86_64-linux-gnu/c++/9 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/x86_64-linux-gnu/c++/9 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-12/lib/clang/12.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /home/usr -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -faddrsig -o /tmp/test-174b8a.o -x c++ ./test.cpp
1.      ./test.cpp:11:5: current parser token 'in'
2.      ./test.cpp:8:1: parsing function body 'main'
3.      ./test.cpp:8:1: in compound statement ('{}')
 #0 0x00007fcc52698ef3 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib/x86_64-linux-gnu/libLLVM-12.so.1+0xbd8ef3)
 #1 0x00007fcc52697210 llvm::sys::RunSignalHandlers() (/lib/x86_64-linux-gnu/libLLVM-12.so.1+0xbd7210)
 #2 0x00007fcc5269955f (/lib/x86_64-linux-gnu/libLLVM-12.so.1+0xbd955f)
 #3 0x00007fcc59ee13c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
 #4 0x00007fcc57e8b4c7 (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0xc0b4c7)
 #5 0x00007fcc57e7a9e5 (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0xbfa9e5)
 #6 0x00007fcc57e784b3 (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0xbf84b3)
 #7 0x00007fcc57e68c7d (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0xbe8c7d)
 #8 0x00007fcc57e6bcea (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0xbebcea)
 #9 0x00007fcc57e68aee (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0xbe8aee)
#10 0x00007fcc57e6675f (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0xbe675f)
#11 0x00007fcc57e66a45 clang::Expr::EvaluateForOverflow(clang::ASTContext const&) const (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0xbe6a45)
#12 0x00007fcc582652cd clang::Sema::CheckForIntOverflow(clang::Expr*) (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0xfe52cd)
#13 0x00007fcc58265919 clang::Sema::CheckCompletedExpr(clang::Expr*, clang::SourceLocation, bool) (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0xfe5919)
#14 0x00007fcc584cbf3b clang::Sema::ActOnFinishFullExpr(clang::Expr*, clang::SourceLocation, bool, bool) (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x124bf3b)
#15 0x00007fcc5864cf81 clang::Sema::ActOnExprStmt(clang::ActionResult<clang::Expr*, true>, bool) (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x13ccf81)
#16 0x00007fcc57c4d33d clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x9cd33d)
#17 0x00007fcc57c4c18d clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x9cc18d)
#18 0x00007fcc57c4b3df clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x9cb3df)
#19 0x00007fcc57c53250 clang::Parser::ParseCompoundStatementBody(bool) (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x9d3250)
#20 0x00007fcc57c540b5 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x9d40b5)
#21 0x00007fcc57c6b6d1 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x9eb6d1)
#22 0x00007fcc57bce4ef clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x94e4ef)
#23 0x00007fcc57c6a95d clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x9ea95d)
#24 0x00007fcc57c6a36c clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x9ea36c)
#25 0x00007fcc57c6950f clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x9e950f)
#26 0x00007fcc57c67cff clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x9e7cff)
#27 0x00007fcc57bb8e3d clang::ParseAST(clang::Sema&, bool, bool) (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x938e3d)
#28 0x00007fcc5914e118 clang::FrontendAction::Execute() (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x1ece118)
#29 0x00007fcc590dbdd1 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x1e5bdd1)
#30 0x00007fcc591b0502 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x1f30502)
#31 0x0000000000412782 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/lib/llvm-12/bin/clang+0x412782)
#32 0x0000000000410afe (/usr/lib/llvm-12/bin/clang+0x410afe)
#33 0x000000000041090e main (/usr/lib/llvm-12/bin/clang+0x41090e)
#34 0x00007fcc515770b3 __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:342:3
#35 0x000000000040dcbe _start (/usr/lib/llvm-12/bin/clang+0x40dcbe)
clang: error: unable to execute command: Segmentation fault (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
Ubuntu clang version 12.0.0-3ubuntu1~20.04.4
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang: note: diagnostic msg:
********************

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

********************

logs:
clang_crash.zip

clang-12 -v output

Ubuntu clang version 12.0.0-3ubuntu1~20.04.4
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

(also reproduced in clang version 14.0.0 (524758d1a75e21a9133b597ea649237d75a46abb) )

@EugeneZelenko EugeneZelenko added bug Indicates an unexpected problem or unintended behavior clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party and removed new issue labels Feb 11, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 11, 2022

@llvm/issue-subscribers-clang-frontend

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 11, 2022

@llvm/issue-subscribers-bug

@EugeneZelenko
Copy link
Contributor

Also crashes in main: https://godbolt.org/z/MM5TaoMMr.

@tbaederr
Copy link
Contributor

Potential fix at https://reviews.llvm.org/D119525

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party
Projects
None yet
Development

No branches or pull requests

4 participants