@@ -2423,6 +2423,12 @@ void AsmPrinter::emitRemarksSection(remarks::RemarkStreamer &RS) {
2423
2423
OutStreamer->emitBinaryData (Buf);
2424
2424
}
2425
2425
2426
+ static uint64_t globalSize (const llvm::GlobalVariable &G) {
2427
+ const Constant *Initializer = G.getInitializer ();
2428
+ return G.getParent ()->getDataLayout ().getTypeAllocSize (
2429
+ Initializer->getType ());
2430
+ }
2431
+
2426
2432
static bool shouldTagGlobal (const llvm::GlobalVariable &G) {
2427
2433
// We used to do this in clang, but there are optimization passes that turn
2428
2434
// non-constant globals into constants. So now, clang only tells us whether
@@ -2455,19 +2461,18 @@ static bool shouldTagGlobal(const llvm::GlobalVariable &G) {
2455
2461
if (G.hasSection ())
2456
2462
return false ;
2457
2463
2458
- return true ;
2464
+ return globalSize (G) > 0 ;
2459
2465
}
2460
2466
2461
2467
static void tagGlobalDefinition (Module &M, GlobalVariable *G) {
2462
- Constant *Initializer = G->getInitializer ();
2463
- uint64_t SizeInBytes =
2464
- M.getDataLayout ().getTypeAllocSize (Initializer->getType ());
2468
+ uint64_t SizeInBytes = globalSize (*G);
2465
2469
2466
2470
uint64_t NewSize = alignTo (SizeInBytes, 16 );
2467
2471
if (SizeInBytes != NewSize) {
2468
2472
// Pad the initializer out to the next multiple of 16 bytes.
2469
2473
llvm::SmallVector<uint8_t > Init (NewSize - SizeInBytes, 0 );
2470
2474
Constant *Padding = ConstantDataArray::get (M.getContext (), Init);
2475
+ Constant *Initializer = G->getInitializer ();
2471
2476
Initializer = ConstantStruct::getAnon ({Initializer, Padding});
2472
2477
auto *NewGV = new GlobalVariable (
2473
2478
M, Initializer->getType (), G->isConstant (), G->getLinkage (),
0 commit comments