Skip to content

Commit cce7cfb

Browse files
committed
[AddressSanitizer] Avoid unnecessary pointer casts for ODR indicator (NFCI)
Don't generate an unnecessary inttoptr + ptrtoint pair for the local case. This should be NFC as the cast pair will get eliminated.
1 parent 224873d commit cce7cfb

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,7 +2662,7 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB,
26622662
G->eraseFromParent();
26632663
NewGlobals[i] = NewGlobal;
26642664

2665-
Constant *ODRIndicator = ConstantPointerNull::get(PtrTy);
2665+
Constant *ODRIndicator = Constant::getNullValue(IntptrTy);
26662666
GlobalValue *InstrumentedGlobal = NewGlobal;
26672667

26682668
bool CanUsePrivateAliases =
@@ -2677,8 +2677,7 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB,
26772677

26782678
// ODR should not happen for local linkage.
26792679
if (NewGlobal->hasLocalLinkage()) {
2680-
ODRIndicator =
2681-
ConstantExpr::getIntToPtr(ConstantInt::get(IntptrTy, -1), PtrTy);
2680+
ODRIndicator = ConstantInt::get(IntptrTy, -1);
26822681
} else if (UseOdrIndicator) {
26832682
// With local aliases, we need to provide another externally visible
26842683
// symbol __odr_asan_XXX to detect ODR violation.
@@ -2692,7 +2691,7 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB,
26922691
ODRIndicatorSym->setVisibility(NewGlobal->getVisibility());
26932692
ODRIndicatorSym->setDLLStorageClass(NewGlobal->getDLLStorageClass());
26942693
ODRIndicatorSym->setAlignment(Align(1));
2695-
ODRIndicator = ODRIndicatorSym;
2694+
ODRIndicator = ConstantExpr::getPtrToInt(ODRIndicatorSym, IntptrTy);
26962695
}
26972696

26982697
Constant *Initializer = ConstantStruct::get(
@@ -2703,8 +2702,7 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB,
27032702
ConstantExpr::getPointerCast(Name, IntptrTy),
27042703
ConstantExpr::getPointerCast(getOrCreateModuleName(), IntptrTy),
27052704
ConstantInt::get(IntptrTy, MD.IsDynInit),
2706-
Constant::getNullValue(IntptrTy),
2707-
ConstantExpr::getPointerCast(ODRIndicator, IntptrTy));
2705+
Constant::getNullValue(IntptrTy), ODRIndicator);
27082706

27092707
LLVM_DEBUG(dbgs() << "NEW GLOBAL: " << *NewGlobal << "\n");
27102708

0 commit comments

Comments
 (0)