This is an archive of the discontinued LLVM Phabricator instance.

[MS] Add metadata for __declspec(allocator)
ClosedPublic

Authored by akhuang on Apr 3 2019, 3:55 PM.

Diff Detail

Event Timeline

akhuang created this revision.Apr 3 2019, 3:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 3 2019, 3:55 PM
rnk added inline comments.Apr 3 2019, 4:33 PM
clang/lib/CodeGen/CGAtomic.cpp
1691 ↗(On Diff #193620)

I don't have an issue with these changes if you want to make them, but they should be committed separately.

clang/lib/CodeGen/CGCall.cpp
4384–4385

I think we should make CGDebugInfo responsible for calling setMetadata. In some sense, "heapallocsite" metadata is debug info, so it makes sense that it would be documented there. Also, if there are other places where we need to add this metadata, we won't have to duplicate this string literal.

So, CGDebugInfo should have some new method addHeapAllocSiteMetadata(Instruction *CallSite, QualType Ty), and that can call the private getOrCreateType method. Sound good?

clang/test/CodeGen/debug-info-codeview-heapallocsite.c
14

We should expect this test case to grow, so it would be good to add more context around here. Something like:

CHECK-LABEL: define{{.*}} @call_alloc
CHECK: call i8* @myalloc(i64 1) {{.*}} !heapallocsite ...
akhuang updated this revision to Diff 193751.Apr 4 2019, 11:07 AM
akhuang marked 2 inline comments as done.
akhuang marked an inline comment as done.
akhuang added inline comments.
clang/lib/CodeGen/CGAtomic.cpp
1691 ↗(On Diff #193620)

Whoops, these were supposed to be a separate test commit but I guess they ended up in here too.

clang/lib/CodeGen/CGCall.cpp
4384–4385

Makes sense.

rnk added inline comments.Apr 4 2019, 1:00 PM
clang/lib/CodeGen/CGCall.cpp
4382–4383

I think you can combine the ifs: !DisableDebugInfo && TargetDecl ...

clang/lib/CodeGen/CGDebugInfo.cpp
1965

This method takes the type in, so I think it's better to put the FIXME in CGCall.cpp. It should also be capitalized like a complete sentence (https://llvm.org/docs/CodingStandards.html#commenting).

clang/test/CodeGen/debug-info-codeview-heapallocsite.c
5

I think it would be interesting to add an allocator that returns a pointer to a struct, so something like:

struct Foo { int x; };
__declspec(allocator) Foo *alloc_foo();
Foo *call_alloc_foo() { return alloc_foo(); }

Then we can check for the right DICompositeType.

akhuang updated this revision to Diff 193792.Apr 4 2019, 3:32 PM
akhuang marked 3 inline comments as done.

-added struct case to test
-style fixes

rnk accepted this revision.Apr 5 2019, 4:05 PM

lgtm, with some suggestions to improve the test

clang/test/CodeGen/debug-info-codeview-heapallocsite.c
17–20

Personally, I think it's nicer to leave the allocator undefined, because then clang doesn't generate IR for it, and FileCheck doesn't have to scan through it. When these tests fail, humans have to generate the IR, read it, and try to understand it, and the less there is, the easier it is to understand.

29

I think you want to look for call_alloc_foo in this CHECK.

This revision is now accepted and ready to land.Apr 5 2019, 4:05 PM
akhuang updated this revision to Diff 194164.Apr 8 2019, 10:15 AM
akhuang marked 2 inline comments as done.

Fixes to test case

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptApr 8 2019, 10:56 AM

This patch caused the Windows sanitizer bot to break: http://lab.llvm.org:8011/builders/sanitizer-windows/builds/44238

Please take a look.

FAILED: projects/compiler-rt/lib/fuzzer/tests/FuzzerTestObjects.gtest-all.cc.x86_64.o 
cmd.exe /C "cd /D C:\b\slave\sanitizer-windows\build\build\stage1\projects\compiler-rt\lib\fuzzer\tests && C:\b\slave\sanitizer-windows\build\build\stage1\.\bin\clang.exe -DWIN32 -D_WINDOWS -Wno-unknown-warning-option -DGTEST_NO_LLVM_RAW_OSTREAM=1 -DGTEST_HAS_RTTI=0 -IC:/b/slave/sanitizer-windows/build/llvm.src/utils/unittest/googletest/include -IC:/b/slave/sanitizer-windows/build/llvm.src/utils/unittest/googletest -Wno-deprecated-declarations -IC:/b/slave/sanitizer-windows/build/llvm.src/projects/compiler-rt/lib/fuzzer -fno-rtti -O2 -c -o FuzzerTestObjects.gtest-all.cc.x86_64.o C:/b/slave/sanitizer-windows/build/llvm.src/utils/unittest/googletest/src/gtest-all.cc"
Stack dump:

0.	Program arguments: C:\b\slave\sanitizer-windows\build\build\stage1\bin\clang.exe -cc1 -triple x86_64-pc-windows-msvc19.16.27026 -emit-obj -mincremental-linker-compatible -disable-free -main-file-name gtest-all.cc -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -momit-leaf-frame-pointer -coverage-notes-file C:\b\slave\sanitizer-windows\build\build\stage1\projects\compiler-rt\lib\fuzzer\tests\FuzzerTestObjects.gtest-all.cc.x86_64.gcno -resource-dir C:\b\slave\sanitizer-windows\build\build\stage1\lib\clang\9.0.0 -D WIN32 -D _WINDOWS -D GTEST_NO_LLVM_RAW_OSTREAM=1 -D GTEST_HAS_RTTI=0 -I C:/b/slave/sanitizer-windows/build/llvm.src/utils/unittest/googletest/include -I C:/b/slave/sanitizer-windows/build/llvm.src/utils/unittest/googletest -I C:/b/slave/sanitizer-windows/build/llvm.src/projects/compiler-rt/lib/fuzzer -internal-isystem C:\b\slave\sanitizer-windows\build\build\stage1\lib\clang\9.0.0\include -internal-isystem C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\ATLMFC\include -internal-isystem C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include -internal-isystem C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um -internal-isystem C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt -internal-isystem C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared -internal-isystem C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um -internal-isystem C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt -internal-isystem C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt -O2 -Wno-unknown-warning-option -Wno-deprecated-declarations -fdeprecated-macro -fdebug-compilation-dir C:\b\slave\sanitizer-windows\build\build\stage1\projects\compiler-rt\lib\fuzzer\tests -ferror-limit 19 -fmessage-length 0 -fno-rtti -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.16.27026 -std=c++14 -fdelayed-template-parsing -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -vectorize-loops -vectorize-slp -o FuzzerTestObjects.gtest-all.cc.x86_64.o -x c++ C:/b/slave/sanitizer-windows/build/llvm.src/utils/unittest/googletest/src/gtest-all.cc -faddrsig 

1.	C:/b/slave/sanitizer-windows/build/llvm.src/utils/unittest/googletest\src/gtest-death-test.cc:79:1: current parser token 'namespace'

2.	C:/b/slave/sanitizer-windows/build/llvm.src/utils/unittest/googletest\src/gtest.cc:149:11: LLVM IR generation of declaration 'testing'

3.	C:/b/slave/sanitizer-windows/build/llvm.src/utils/unittest/googletest\src/gtest.cc:361:15: Generating code for declaration 'testing::internal::AssertHelper::AssertHelper'

 #0 0x00007ff761d1de49 clang::CodeGen::CGDebugInfo::addHeapAllocSiteMetadata(class llvm::Instruction *,class clang::QualType,class clang::SourceLocation) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\cgdebuginfo.cpp:1967:0

 #1 0x00007ff761d9d462 clang::CodeGen::CodeGenFunction::EmitCall(class clang::CodeGen::CGFunctionInfo const &,class clang::CodeGen::CGCallee const &,class clang::CodeGen::ReturnValueSlot,class clang::CodeGen::CallArgList const &,class llvm::CallBase * *,class clang::SourceLocation) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\cgcall.cpp:4392:0

 #2 0x00007ff76202a144 EmitNewDeleteCall c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\cgexprcxx.cpp:1288:0

 #3 0x00007ff762026a55 clang::CodeGen::CodeGenFunction::EmitCXXNewExpr(class clang::CXXNewExpr const *) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\cgexprcxx.cpp:1617:0

 #4 0x00007ff761fdf0a6 clang::StmtVisitorBase<std::add_pointer,`anonymous namespace'::ScalarExprEmitter,llvm::Value *>::Visit c:\b\slave\sanitizer-windows\build\build\stage1\tools\clang\include\clang\ast\stmtnodes.inc:699:0

 #5 0x00007ff761fdb1e8 clang::CodeGen::CodeGenFunction::EmitScalarExpr(class clang::Expr const *,bool) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\cgexprscalar.cpp:4472:0

 #6 0x00007ff761de3a53 clang::CodeGen::CodeGenFunction::EmitScalarInit(class clang::Expr const *,class clang::ValueDecl const *,class clang::CodeGen::LValue,bool) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\cgdecl.cpp:748:0

 #7 0x00007ff761de20f9 clang::CodeGen::CodeGenFunction::EmitExprAsInit(class clang::Expr const *,class clang::ValueDecl const *,class clang::CodeGen::LValue,bool) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\cgdecl.cpp:1951:0

 #8 0x00007ff761fb35ce clang::CodeGen::CodeGenFunction::EmitInitializerForField(class clang::FieldDecl *,class clang::CodeGen::LValue,class clang::Expr *) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\cgclass.cpp:669:0

 #9 0x00007ff761fb4d3b EmitMemberInitializer c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\cgclass.cpp:660:0

#10 0x00007ff761fb1cfe clang::CodeGen::CodeGenFunction::EmitCtorPrologue(class clang::CXXConstructorDecl const *,enum clang::CXXCtorType,class clang::CodeGen::FunctionArgList &) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\cgclass.cpp:1318:0

#11 0x00007ff761fb121d clang::CodeGen::CodeGenFunction::EmitConstructorBody(class clang::CodeGen::FunctionArgList &) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\cgclass.cpp:854:0

#12 0x00007ff761e2cb16 clang::CodeGen::CodeGenFunction::GenerateCode(class clang::GlobalDecl,class llvm::Function *,class clang::CodeGen::CGFunctionInfo const &) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\codegenfunction.cpp:1356:0

#13 0x00007ff761ddc2e6 clang::CodeGen::CodeGenModule::codegenCXXStructor(class clang::GlobalDecl) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\cgcxx.cpp:214:0

#14 0x00007ff761ece3a7 `anonymous namespace'::MicrosoftCXXABI::emitCXXStructor c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\microsoftcxxabi.cpp:3824:0

#15 0x00007ff761d3a654 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(class clang::GlobalDecl,class llvm::GlobalValue *) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\codegenmodule.cpp:2499:0

#16 0x00007ff761d3a063 clang::CodeGen::CodeGenModule::EmitGlobal(class clang::GlobalDecl) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\codegenmodule.cpp:2265:0

#17 0x00007ff761ec485e `anonymous namespace'::MicrosoftCXXABI::EmitCXXConstructors c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\microsoftcxxabi.cpp:1202:0

#18 0x00007ff761d3d61f clang::CodeGen::CodeGenModule::EmitTopLevelDecl(class clang::Decl *) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\codegenmodule.cpp:4919:0

#19 0x00007ff761d38e71 clang::CodeGen::CodeGenModule::EmitDeclContext(class clang::DeclContext const *) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\codegenmodule.cpp:4822:0

#20 0x00007ff761d3d3ce clang::CodeGen::CodeGenModule::EmitTopLevelDecl(class clang::Decl *) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\codegenmodule.cpp:4875:0

#21 0x00007ff761d38e71 clang::CodeGen::CodeGenModule::EmitDeclContext(class clang::DeclContext const *) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\codegenmodule.cpp:4822:0

#22 0x00007ff761d3d3ce clang::CodeGen::CodeGenModule::EmitTopLevelDecl(class clang::Decl *) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\codegenmodule.cpp:4875:0

#23 0x00007ff76392c3ff `anonymous namespace'::CodeGeneratorImpl::HandleTopLevelDecl c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\modulebuilder.cpp:162:0

#24 0x00007ff763928b14 clang::BackendConsumer::HandleTopLevelDecl(class clang::DeclGroupRef) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\codegen\codegenaction.cpp:172:0

#25 0x00007ff762c6b916 clang::ParseAST(class clang::Sema &,bool,bool) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\parse\parseast.cpp:162:0

#26 0x00007ff7621bfbed clang::ASTFrontendAction::ExecuteAction(void) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\frontend\frontendaction.cpp:1037:0

#27 0x00007ff7621bfa87 clang::FrontendAction::Execute(void) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\frontend\frontendaction.cpp:938:0

#28 0x00007ff76218783b clang::CompilerInstance::ExecuteAction(class clang::FrontendAction &) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\frontend\compilerinstance.cpp:951:0

#29 0x00007ff76221d5e3 clang::ExecuteCompilerInvocation(class clang::CompilerInstance *) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\lib\frontendtool\executecompilerinvocation.cpp:271:0

#30 0x00007ff760f380dd cc1_main(class llvm::ArrayRef<char const *>,char const *,void *) c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\tools\driver\cc1_main.cpp:226:0

#31 0x00007ff760f33245 ExecuteCC1Tool c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\tools\driver\driver.cpp:319:0

#32 0x00007ff760f355b5 main c:\b\slave\sanitizer-windows\build\llvm.src\tools\clang\tools\driver\driver.cpp:381:0

#33 0x00007ff7637051dc __scrt_common_main_seh d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288:0

#34 0x00007ffe67bf13d2 (C:\windows\system32\KERNEL32.DLL+0x13d2)

#35 0x00007ffe687154f4 (C:\windows\SYSTEM32\ntdll.dll+0x154f4)

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

clang version 9.0.0 (trunk 357928)

Target: x86_64-pc-windows-msvc

Thread model: posix

InstalledDir: C:\b\slave\sanitizer-windows\build\build\stage1\.\bin

clang: note: diagnostic msg: PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.

clang: note: diagnostic msg: 

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