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

Compiler crash when using -ftime-trace after 27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf #58551

Closed
dyung opened this issue Oct 23, 2022 · 5 comments
Assignees
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@dyung
Copy link
Collaborator

dyung commented Oct 23, 2022

Internally we have tests that attempt to collect information about the compilation by using -ftime-trace and suddenly several of them started to fail with crashes. I bisected the failure back to commit 27d8eed, and reduced the failure to the following:

struct {
  short quantval[4]
};

Here is the crash backtrace when compiling the above code with -c -ftime-trace:

$ ~/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang -c -ftime-trace repro.c
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: /home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang -c -ftime-trace repro.c
1.      repro.c:3:1: current parser token '}'                                                                             
2.      repro.c:1:1: parsing struct/union body 'struct (unnamed at repro.c:1:1)'
 #0 0x0000555a4e525df4 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x0000555a4e523b8c llvm::sys::CleanupOnSignal(unsigned long) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x3f19b8c)
 #2 0x0000555a4e45a938 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f316ad91420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x0000555a4e88ec24 clang::SourceLocation::print(llvm::raw_ostream&, clang::SourceManager const&) const (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x4284c24)
 #5 0x0000555a4e88f09f clang::SourceLocation::printToString[abi:cxx11](clang::SourceManager const&) const (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x428509f)
 #6 0x0000555a517461d3 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> llvm::function_ref<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> ()>::callback_fn<clang::Expr::isIntegerConst
antExpr(clang::ASTContext const&, clang::SourceLocation*) const::'lambda'()>(long) ExprConstant.cpp:0:0
 #7 0x0000555a4e4a8570 llvm::timeTraceProfilerBegin(llvm::StringRef, llvm::function_ref<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> ()>) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux
/bin/clang+0x3e9e570)                
 #8 0x0000555a5177d4ed clang::Expr::isIntegerConstantExpr(clang::ASTContext const&, clang::SourceLocation*) const (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x71734ed)
 #9 0x0000555a50c63aaf clang::Sema::VerifyIntegerConstantExpression(clang::Expr*, llvm::APSInt*, clang::Sema::VerifyICEDiagnoser&, clang::Sema::AllowFoldKind) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x
6659aaf)
#10 0x0000555a51290ebb clang::Sema::BuildArrayType(clang::QualType, clang::ArrayType::ArraySizeModifier, clang::Expr*, unsigned int, clang::SourceRange, clang::DeclarationName) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-
linux/bin/clang+0x6c86ebb)
#11 0x0000555a512add03 GetFullTypeForDeclarator((anonymous namespace)::TypeProcessingState&, clang::QualType, clang::TypeSourceInfo*) SemaType.cpp:0:0
#12 0x0000555a512b251e clang::Sema::GetTypeForDeclarator(clang::Declarator&, clang::Scope*) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x6ca851e)
#13 0x0000555a50a62500 clang::Sema::HandleField(clang::Scope*, clang::RecordDecl*, clang::SourceLocation, clang::Declarator&, clang::Expr*, clang::InClassInitStyle, clang::AccessSpecifier) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225f
fa1ff04cccf-linux/bin/clang+0x6458500)
#14 0x0000555a50a62cf5 clang::Sema::ActOnField(clang::Scope*, clang::Decl*, clang::SourceLocation, clang::Declarator&, clang::Expr*) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x6458cf5)
#15 0x0000555a50759695 void llvm::function_ref<void (clang::ParsingFieldDeclarator&)>::callback_fn<clang::Parser::ParseStructUnionBody(clang::SourceLocation, clang::TypeSpecifierType, clang::RecordDecl*)::'lambda'(clang::ParsingFieldDeclarator&
)>(long, clang::ParsingFieldDeclarator&) ParseDecl.cpp:0:0
#16 0x0000555a50771223 clang::Parser::ParseStructDeclaration(clang::ParsingDeclSpec&, llvm::function_ref<void (clang::ParsingFieldDeclarator&)>) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x6167223)
#17 0x0000555a50771b23 clang::Parser::ParseStructUnionBody(clang::SourceLocation, clang::TypeSpecifierType, clang::RecordDecl*) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x6167b23)
#18 0x0000555a50798bf6 clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::ParsedAttri
butes&) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x618ebf6)
#19 0x0000555a5076d636 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, clang::ImplicitTypenameCont
ext) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x6163636)
#20 0x0000555a5073ffc2 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x6135fc2)
#21 0x0000555a50740890 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#22 0x0000555a5074604b clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x613c04b)
#23 0x0000555a50746eda clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x613ceda)
#24 0x0000555a50747314 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x613d314)
#25 0x0000555a5073b27a clang::ParseAST(clang::Sema&, bool, bool) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x613127a)
#26 0x0000555a4f84c3f8 clang::CodeGenAction::ExecuteAction() (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x52423f8)
#27 0x0000555a4f0e0719 clang::FrontendAction::Execute() (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x4ad6719)
#28 0x0000555a4f0678be clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x4a5d8be)
#29 0x0000555a4f1c5bd3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x4bbbbd3)
#30 0x0000555a4b9c8844 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x13be844)
#31 0x0000555a4b9c1958 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#32 0x0000555a4eed4869 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) con
st::'lambda'()>(long) Job.cpp:0:0
#33 0x0000555a4e45b0da llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x3e510da)
#34 0x0000555a4eed50bf clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#35 0x0000555a4ee9e589 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x4894589)          
#36 0x0000555a4ee9f00d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-
linux/bin/clang+0x489500d)                                                                                                                                                                                                                          
#37 0x0000555a4eea862c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/cl
ang+0x489e62c)                                            
#38 0x0000555a4b9c6c83 clang_main(int, char**) (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x13bcc83)                                                                                                  
#39 0x00007f316a83f083 __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:342:3                                                                                                                                               
#40 0x0000555a4b9c155e _start (/home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin/clang+0x13b755e)                                                                                                                         
clang-16: error: clang frontend command failed with exit code 139 (use -v to see invocation)         
clang version 16.0.0 (https://github.com/llvm/llvm-project.git 27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf)                                                                                                                                            
Target: x86_64-unknown-linux-gnu                                                                                          
Thread model: posix                                                                                                                                                                                                                                 
InstalledDir: /home/dyung/src/upstream/27d8eedd5a3cd7fd644be4f06225ffa1ff04cccf-linux/bin
@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 Oct 23, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Oct 23, 2022

@llvm/issue-subscribers-clang-frontend

@Izaron Izaron self-assigned this Oct 23, 2022
@Izaron
Copy link
Member

Izaron commented Oct 23, 2022

Hi, it was my commit that broke the code. I'll make a fix.

P. S. I have a silly question =) Your example isn't going to compile? I see there is lack of semicolon after array declaration. Do you test compilation on code with syntaxical errors?

@dyung
Copy link
Collaborator Author

dyung commented Oct 23, 2022

Hi, it was my commit that broke the code. I'll make a fix.

P. S. I have a silly question =) Your example isn't going to compile? I see there is lack of semicolon after array declaration. Do you test compilation on code with syntaxical errors?

Yes, I realize it doesn't compile, but this is what the reducer came up with. :)

@dyung
Copy link
Collaborator Author

dyung commented Oct 23, 2022

Hi, it was my commit that broke the code. I'll make a fix.
P. S. I have a silly question =) Your example isn't going to compile? I see there is lack of semicolon after array declaration. Do you test compilation on code with syntaxical errors?

Yes, I realize it doesn't compile, but this is what the reducer came up with. :)

A little more detail if you are curious, but the original code that failed was from several micro-benchmarks and real-world code-bases that we build internally.

@Izaron
Copy link
Member

Izaron commented Oct 23, 2022

Thanks! This compilable sample:

struct {
  short quantval[4];
} value;

also failed with segfault.

I made a patch here - https://reviews.llvm.org/D136549, please review it if you have time =)

@Izaron Izaron closed this as completed in 2bb50a5 Oct 23, 2022
sid8123 pushed a commit to sid8123/llvm-project that referenced this issue Oct 25, 2022
The time profiler in `Expr::isIntegerConstantExpr` used to
call `Loc->printToString`, it was inconsistent with other time
profiles in the file and caused segfaults if `Loc` was `nullptr`.

Fixes llvm#58551

Reviewed By: dyung, jloser

Differential Revision: https://reviews.llvm.org/D136549
virnarula pushed a commit to virnarula/llvm-project that referenced this issue Nov 2, 2022
The time profiler in `Expr::isIntegerConstantExpr` used to
call `Loc->printToString`, it was inconsistent with other time
profiles in the file and caused segfaults if `Loc` was `nullptr`.

Fixes llvm#58551

Reviewed By: dyung, jloser

Differential Revision: https://reviews.llvm.org/D136549
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" crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

No branches or pull requests

4 participants