@@ -2398,6 +2398,12 @@ void AsmPrinter::emitRemarksSection(remarks::RemarkStreamer &RS) {
23982398 OutStreamer->emitBinaryData (Buf);
23992399}
24002400
2401+ static uint64_t globalSize (const llvm::GlobalVariable &G) {
2402+ const Constant *Initializer = G.getInitializer ();
2403+ return G.getParent ()->getDataLayout ().getTypeAllocSize (
2404+ Initializer->getType ());
2405+ }
2406+
24012407static bool shouldTagGlobal (const llvm::GlobalVariable &G) {
24022408 // We used to do this in clang, but there are optimization passes that turn
24032409 // non-constant globals into constants. So now, clang only tells us whether
@@ -2430,19 +2436,18 @@ static bool shouldTagGlobal(const llvm::GlobalVariable &G) {
24302436 if (G.hasSection ())
24312437 return false ;
24322438
2433- return true ;
2439+ return globalSize (G) > 0 ;
24342440}
24352441
24362442static void tagGlobalDefinition (Module &M, GlobalVariable *G) {
2437- Constant *Initializer = G->getInitializer ();
2438- uint64_t SizeInBytes =
2439- M.getDataLayout ().getTypeAllocSize (Initializer->getType ());
2443+ uint64_t SizeInBytes = globalSize (*G);
24402444
24412445 uint64_t NewSize = alignTo (SizeInBytes, 16 );
24422446 if (SizeInBytes != NewSize) {
24432447 // Pad the initializer out to the next multiple of 16 bytes.
24442448 llvm::SmallVector<uint8_t > Init (NewSize - SizeInBytes, 0 );
24452449 Constant *Padding = ConstantDataArray::get (M.getContext (), Init);
2450+ Constant *Initializer = G->getInitializer ();
24462451 Initializer = ConstantStruct::getAnon ({Initializer, Padding});
24472452 auto *NewGV = new GlobalVariable (
24482453 M, Initializer->getType (), G->isConstant (), G->getLinkage (),
0 commit comments