This is an archive of the discontinued LLVM Phabricator instance.

clang-cl crashes with -fprofile-instr-use flag
Needs ReviewPublic

Authored by yvvan on Jun 27 2017, 4:16 AM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

Reproduced while building llvm with clang-cl.
I have trained profdata file. When I tried to use it I got crash complaining of nullptr casted inside visitor.

Diff Detail

Event Timeline

yvvan created this revision.Jun 27 2017, 4:16 AM
yvvan retitled this revision from Fix clang-cl build -fprofile-instr-use flag to clang-cl crashes with -fprofile-instr-use flag.
yvvan added a comment.Jun 27 2017, 4:20 AM


Profdata which causes crash

vsk added a subscriber: vsk.Jun 28 2017, 11:15 AM

Do you know which function clang was processing when it crashed? That would help us find a test case.

yvvan added a comment.Jun 30 2017, 5:40 AM
In D34680#794135, @vsk wrote:

Do you know which function clang was processing when it crashed? That would help us find a test case.

I have a trace:
#0 0x00007ff6942b777c HandleAbort d:\code\llvm_copy\lib\support\windows\signals.inc:405:0
#1 0x00007ffe1bfefe21 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x7fe21)
#2 0x00007ffe1bff1979 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x81979)
#3 0x00007ffe1bff6fcf (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x86fcf)
#4 0x00007ffe1bff4fc1 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x84fc1)
#5 0x00007ffe1bff77bf (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x877bf)
#6 0x00007ff6947b332c llvm::isa_impl_cl<class clang::BinaryOperator,class clang::Stmt const *>::doit(class clang::Stmt const *) d:\code\llvm_copy\include\llvm\support\casting.h:106:0
#7 0x00007ff6947beefb llvm::isa_impl_wrap<class clang::BinaryOperator,class clang::Stmt const *,class clang::Stmt const *>::doit(class clang::Stmt const * const &) d:\code\llvm_copy\include\llvm\support\casting.h:134:0
#8 0x00007ff694b06167 llvm::isa_impl_wrap<class clang::BinaryOperator,class clang::Stmt const * const,class clang::Stmt const *>::doit(class clang::Stmt const * const &) d:\code\llvm_copy\include\llvm\support\casting.h:126:0
#9 0x00007ff694af9e58 llvm::isa<class clang::BinaryOperator,class clang::Stmt const *>(class clang::Stmt const * const &) d:\code\llvm_copy\include\llvm\support\casting.h:145:0
#10 0x00007ff694af9a68 llvm::dyn_cast<class clang::BinaryOperator,class clang::Stmt const >(class clang::Stmt const *) d:\code\llvm_copy\include\llvm\support\casting.h:334:0
#11 0x00007ff694b8002d clang::StmtVisitorBase<clang::make_const_ptr,`anonymous namespace'::ComputeRegionCounts,void>::Visit d:\code\llvm_copy\tools\clang\include\clang\ast\stmtvisitor.h:45:0
#12 0x00007ff694b87292 `anonymous namespace'::ComputeRegionCounts::VisitFunctionDecl d:\code\llvm_copy\tools\clang\lib\codegen\codegenpgo.cpp:255:0
#13 0x00007ff694b2b214 clang::CodeGen::CodeGenPGO::computeRegionCounts(class clang::Decl const *) d:\code\llvm_copy\tools\clang\lib\codegen\codegenpgo.cpp:723:0
#14 0x00007ff694b2a533 clang::CodeGen::CodeGenPGO::assignRegionCounters(class clang::GlobalDecl,class llvm::Function *) d:\code\llvm_copy\tools\clang\lib\codegen\codegenpgo.cpp:648:0
#15 0x00007ff694b0ba8b clang::CodeGen::CodeGenFunction::GenerateCode(class clang::GlobalDecl,class llvm::Function *,class clang::CodeGen::CGFunctionInfo const &) d:\code\llvm_copy\tools\clang\lib\codegen\codegenfunction.cpp:1168:0
#16 0x00007ff694a9e5f9 clang::CodeGen::CodeGenModule::codegenCXXStructor(class clang::CXXMethodDecl const *,enum clang::CodeGen::StructorType) d:\code\llvm_copy\tools\clang\lib\codegen\cgcxx.cpp:234:0
#17 0x00007ff694c1a1f7 emitCXXDestructor d:\code\llvm_copy\tools\clang\lib\codegen\microsoftcxxabi.cpp:3822:0
#18 0x00007ff694c14ef9 `anonymous namespace'::MicrosoftCXXABI::emitCXXStructor d:\code\llvm_copy\tools\clang\lib\codegen\microsoftcxxabi.cpp:3834:0
#19 0x00007ff694859c7e clang::CodeGen::CodeGenModule::EmitGlobalDefinition(class clang::GlobalDecl,class llvm::GlobalValue *) d:\code\llvm_copy\tools\clang\lib\codegen\codegenmodule.cpp:2007:0
#20 0x00007ff69485c6bd clang::CodeGen::CodeGenModule::EmitDeferred(void) d:\code\llvm_copy\tools\clang\lib\codegen\codegenmodule.cpp:1438:0
#21 0x00007ff69485c704 clang::CodeGen::CodeGenModule::EmitDeferred(void) d:\code\llvm_copy\tools\clang\lib\codegen\codegenmodule.cpp:1440:0
#22 0x00007ff69485c704 clang::CodeGen::CodeGenModule::EmitDeferred(void) d:\code\llvm_copy\tools\clang\lib\codegen\codegenmodule.cpp:1440:0
#23 0x00007ff69485c704 clang::CodeGen::CodeGenModule::EmitDeferred(void) d:\code\llvm_copy\tools\clang\lib\codegen\codegenmodule.cpp:1440:0
#24 0x00007ff69484c80a clang::CodeGen::CodeGenModule::Release(void) d:\code\llvm_copy\tools\clang\lib\codegen\codegenmodule.cpp:386:0
#25 0x00007ff69931e3ad `anonymous namespace'::CodeGeneratorImpl::HandleTranslationUnit d:\code\llvm_copy\tools\clang\lib\codegen\modulebuilder.cpp:261:0
#26 0x00007ff699317a57 clang::BackendConsumer::HandleTranslationUnit(class clang::ASTContext &) d:\code\llvm_copy\tools\clang\lib\codegen\codegenaction.cpp:206:0
#27 0x00007ff696b0bc71 clang::ParseAST(class clang::Sema &,bool,bool) d:\code\llvm_copy\tools\clang\lib\parse\parseast.cpp:161:0
#28 0x00007ff6951ad08b clang::ASTFrontendAction::ExecuteAction(void) d:\code\llvm_copy\tools\clang\lib\frontend\frontendaction.cpp:996:0
#29 0x00007ff69930c632 clang::CodeGenAction::ExecuteAction(void) d:\code\llvm_copy\tools\clang\lib\codegen\codegenaction.cpp:990:0
#30 0x00007ff6951acae7 clang::FrontendAction::Execute(void) d:\code\llvm_copy\tools\clang\lib\frontend\frontendaction.cpp:897:0
#31 0x00007ff695115bc0 clang::CompilerInstance::ExecuteAction(class clang::FrontendAction &) d:\code\llvm_copy\tools\clang\lib\frontend\compilerinstance.cpp:977:0
#32 0x00007ff69535c116 clang::ExecuteCompilerInvocation(class clang::CompilerInstance *) d:\code\llvm_copy\tools\clang\lib\frontendtool\executecompilerinvocation.cpp:250:0
#33 0x00007ff690e9f174 cc1_main(class llvm::ArrayRef<char const *>,char const *,void *) d:\code\llvm_copy\tools\clang\tools\driver\cc1_main.cpp:221:0
#34 0x00007ff690e8500d ExecuteCC1Tool d:\code\llvm_copy\tools\clang\tools\driver\driver.cpp:306:0
#35 0x00007ff690e858bc main d:\code\llvm_copy\tools\clang\tools\driver\driver.cpp:387:0
#36 0x00007ff699089024 invoke_main f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:65:0
#37 0x00007ff699088ee7 scrt_common_main_seh f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:259:0
#38 0x00007ff699088dae
scrt_common_main f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:302:0
#39 0x00007ff699089049 mainCRTStartup f:\dd\vctools\crt\vcstartup\src\startup\exe_main.cpp:17:0
#40 0x00007ffe5ce82774 (C:\WINDOWS\System32\KERNEL32.DLL+0x12774)
#41 0x00007ffe5d820d61 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x70d61)

vsk added a comment.Jun 30 2017, 2:06 PM

Thanks for the stack trace. Clang shouldn't ever be assigning counters to decls without bodies. As far as I can tell, this has only been happening when the microsoft ABI is in use, which may explain why we don't hit the issue more often. The fix required changing the way we assign and use profile counters (r306883). Give it a try and let us know how it goes.