Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

clang crash while parsing a struct in C #40927

Open Quuxplusone opened 5 years ago

Quuxplusone commented 5 years ago
Bugzilla Link PR41957
Status CONFIRMED
Importance P normal
Reported by Nicola Zaghen (llvm@zaghen.it)
Reported on 2019-05-21 05:12:20 -0700
Last modified on 2020-04-08 10:00:20 -0700
Version trunk
Hardware PC Linux
CC blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, fwage73@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments clang_crash.c (119 bytes, text/x-csrc)
Blocks
Blocked by
See also
Created attachment 21979
Reduced testcase for the crash

The expected result would be clang complaining about "__packed" (which would
lead to a missing include). This issue was introduced after LLVM 3.7 and is
still present in latest clang trunk.

I attached a manually reduced testcase.
https://godbolt.org/z/jdmr5k

Stack dump:

0.  Program arguments: /opt/compiler-explorer/clang-trunk-20190521/bin/clang-9 -
cc1 -triple x86_64-unknown-linux-gnu -S -disable-free -disable-llvm-verifier -
discard-value-names -main-file-name example.c -mrelocation-model static -
mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-
aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -
debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -coverage-notes-
file /home/ubuntu/./output.gcno -resource-dir /opt/compiler-explorer/clang-
trunk-20190521/lib/clang/9.0.0 -internal-isystem /usr/local/include -internal-
isystem /opt/compiler-explorer/clang-trunk-20190521/lib/clang/9.0.0/include -
internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-
isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir
/home/ubuntu -ferror-limit 19 -fmessage-length 0 -fobjc-runtime=gcc -
fdiagnostics-show-option -fcolor-diagnostics -mllvm --x86-asm-syntax=intel -o
./output.s -x c <source> -faddrsig

1.  <source>:14:8: current parser token ';'

2.  <source>:2:1: parsing function body 'test'

3.  <source>:2:1: in compound statement ('{}')

4.  <source>:12:2: parsing struct/union body

 #0 0x00005616d7606cba llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/opt/compiler-explorer/clang-trunk-20190521/bin/clang-9+0x269bcba)

 #1 0x00005616d7604a84 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-trunk-20190521/bin/clang-9+0x2699a84)

 #2 0x00005616d7604bc2 SignalHandler(int) (/opt/compiler-explorer/clang-trunk-20190521/bin/clang-9+0x2699bc2)

 #3 0x00007f146901f890 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)

 #4 0x00005616d9398be1 clang::DeclContext::addHiddenDecl(clang::Decl*) (/opt/compiler-explorer/clang-trunk-20190521/bin/clang-9+0x442dbe1)

 #5 0x00005616d939ce79 clang::DeclContext::addDecl(clang::Decl*) (/opt/compiler-explorer/clang-trunk-20190521/bin/clang-9+0x4431e79)

 #6 0x00005616d8c9e06c clang::Sema::PushOnScopeChains(clang::NamedDecl*, clang::Scope*, bool) (/opt/compiler-explorer/clang-trunk-20190521/bin/clang-9+0x3d3306c)

 #7 0x00005616d8cb3cb0 clang::Sema::HandleField(clang::Scope*, clang::RecordDecl*, clang::SourceLocation, clang::Declarator&, clang::Expr*, clang::InClassInitStyle, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk-20190521/bin/clang-9+0x3d48cb0)

 #8 0x00005616d8cb3fdd clang::Sema::ActOnField(clang::Scope*, clang::Decl*, clang::SourceLocation, clang::Declarator&, clang::Expr*) (/opt/compiler-explorer/clang-trunk-20190521/bin/clang-9+0x3d48fdd)

 #9 0x00005616d8aed736 void llvm::function_ref<void (clang::ParsingFieldDeclarator&)>::callback_fn<clang::Parser::ParseStructUnionBody(clang::SourceLocation, unsigned int, clang::Decl*)::'lambda'(clang::ParsingFieldDeclarator&)>(long, clang::ParsingFieldDeclarator&) (/opt/compiler-explorer/clang-trunk-20190521/bin/clang-9+0x3b82736)

#10 0x00005616d8b05b65
clang::Parser::ParseStructDeclaration(clang::ParsingDeclSpec&,
llvm::function_ref<void (clang::ParsingFieldDeclarator&)>) (/opt/compiler-
explorer/clang-trunk-20190521/bin/clang-9+0x3b9ab65)

#11 0x00005616d8b09c15
clang::Parser::ParseStructUnionBody(clang::SourceLocation, unsigned int,
clang::Decl*) (/opt/compiler-explorer/clang-trunk-20190521/bin/clang-
9+0x3b9ec15)

#12 0x00005616d8b1c32c
clang::Parser::ParseClassSpecifier(clang::tok::TokenKind,
clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo
const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext,
clang::Parser::ParsedAttributesWithRange&) (/opt/compiler-explorer/clang-trunk-
20190521/bin/clang-9+0x3bb132c)

#13 0x00005616d8afe18e
clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&,
clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier,
clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*)
(/opt/compiler-explorer/clang-trunk-20190521/bin/clang-9+0x3b9318e)

#14 0x00005616d8b06494
clang::Parser::ParseSimpleDeclaration(clang::DeclaratorContext,
clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&, bool,
clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-trunk-
20190521/bin/clang-9+0x3b9b494)

#15 0x00005616d8b067fa
clang::Parser::ParseDeclaration(clang::DeclaratorContext,
clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&)
(/opt/compiler-explorer/clang-trunk-20190521/bin/clang-9+0x3b9b7fa)

#16 0x00005616d8b6c4c2
clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*,
32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*,
clang::Parser::ParsedAttributesWithRange&) (/opt/compiler-explorer/clang-trunk-
20190521/bin/clang-9+0x3c014c2)

#17 0x00005616d8b6daf9
clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*,
32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-
explorer/clang-trunk-20190521/bin/clang-9+0x3c02af9)

#18 0x00005616d8b71121 clang::Parser::ParseCompoundStatementBody(bool)
(/opt/compiler-explorer/clang-trunk-20190521/bin/clang-9+0x3c06121)

#19 0x00005616d8b741e3 clang::Parser::ParseFunctionStatementBody(clang::Decl*,
clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-trunk-
20190521/bin/clang-9+0x3c091e3)

#20 0x00005616d8ae1b68
clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&,
clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*)
(/opt/compiler-explorer/clang-trunk-20190521/bin/clang-9+0x3b76b68)

#21 0x00005616d8b02381 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&,
clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*)
(/opt/compiler-explorer/clang-trunk-20190521/bin/clang-9+0x3b97381)

#22 0x00005616d8adcad9
clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-
trunk-20190521/bin/clang-9+0x3b71ad9)

#23 0x00005616d8add7b1
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.207) (/opt/compiler-
explorer/clang-trunk-20190521/bin/clang-9+0x3b727b1)

#24 0x00005616d8ae4a06
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-trunk-20190521/bin/clang-
9+0x3b79a06)

#25 0x00005616d8ae5469
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool)
(/opt/compiler-explorer/clang-trunk-20190521/bin/clang-9+0x3b7a469)

#26 0x00005616d8ae5995
clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&)
(/opt/compiler-explorer/clang-trunk-20190521/bin/clang-9+0x3b7a995)

#27 0x00005616d8ad9246 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-
explorer/clang-trunk-20190521/bin/clang-9+0x3b6e246)

#28 0x00005616d832c017 clang::CodeGenAction::ExecuteAction() (/opt/compiler-
explorer/clang-trunk-20190521/bin/clang-9+0x33c1017)

#29 0x00005616d7cc8826 clang::FrontendAction::Execute() (/opt/compiler-
explorer/clang-trunk-20190521/bin/clang-9+0x2d5d826)

#30 0x00005616d7c8b41c
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-
explorer/clang-trunk-20190521/bin/clang-9+0x2d2041c)

#31 0x00005616d7d86eb3
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-
explorer/clang-trunk-20190521/bin/clang-9+0x2e1beb3)

#32 0x00005616d5bf9d90 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/opt/compiler-explorer/clang-trunk-20190521/bin/clang-9+0xc8ed90)

#33 0x00005616d5b5c3b2 main (/opt/compiler-explorer/clang-trunk-
20190521/bin/clang-9+0xbf13b2)

#34 0x00007f1467eddb97 __libc_start_main (/lib/x86_64-linux-
gnu/libc.so.6+0x21b97)

#35 0x00005616d5bf738a _start (/opt/compiler-explorer/clang-trunk-
20190521/bin/clang-9+0xc8c38a)

clang-9: error: unable to execute command: Segmentation fault (core dumped)

clang-9: error: clang frontend command failed due to signal (use -v to see
invocation)

Compiler returned: 254
Quuxplusone commented 5 years ago

Attached clang_crash.c (119 bytes, text/x-csrc): Reduced testcase for the crash