@@ -2398,6 +2398,12 @@ void AsmPrinter::emitRemarksSection(remarks::RemarkStreamer &RS) {
2398
2398
OutStreamer->emitBinaryData (Buf);
2399
2399
}
2400
2400
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
+
2401
2407
static bool shouldTagGlobal (const llvm::GlobalVariable &G) {
2402
2408
// We used to do this in clang, but there are optimization passes that turn
2403
2409
// non-constant globals into constants. So now, clang only tells us whether
@@ -2430,19 +2436,18 @@ static bool shouldTagGlobal(const llvm::GlobalVariable &G) {
2430
2436
if (G.hasSection ())
2431
2437
return false ;
2432
2438
2433
- return true ;
2439
+ return globalSize (G) > 0 ;
2434
2440
}
2435
2441
2436
2442
static 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);
2440
2444
2441
2445
uint64_t NewSize = alignTo (SizeInBytes, 16 );
2442
2446
if (SizeInBytes != NewSize) {
2443
2447
// Pad the initializer out to the next multiple of 16 bytes.
2444
2448
llvm::SmallVector<uint8_t > Init (NewSize - SizeInBytes, 0 );
2445
2449
Constant *Padding = ConstantDataArray::get (M.getContext (), Init);
2450
+ Constant *Initializer = G->getInitializer ();
2446
2451
Initializer = ConstantStruct::getAnon ({Initializer, Padding});
2447
2452
auto *NewGV = new GlobalVariable (
2448
2453
M, Initializer->getType (), G->isConstant (), G->getLinkage (),
0 commit comments