@@ -384,7 +384,7 @@ class HWAddressSanitizer {
384
384
385
385
Type *VoidTy = Type::getVoidTy(M.getContext());
386
386
Type *IntptrTy;
387
- Type *Int8PtrTy ;
387
+ PointerType *PtrTy ;
388
388
Type *Int8Ty;
389
389
Type *Int32Ty;
390
390
Type *Int64Ty = Type::getInt64Ty(M.getContext());
@@ -587,7 +587,7 @@ void HWAddressSanitizer::initializeModule() {
587
587
C = &(M.getContext ());
588
588
IRBuilder<> IRB (*C);
589
589
IntptrTy = IRB.getIntPtrTy (DL);
590
- Int8PtrTy = IRB.getInt8PtrTy ();
590
+ PtrTy = IRB.getPtrTy ();
591
591
Int8Ty = IRB.getInt8Ty ();
592
592
Int32Ty = IRB.getInt32Ty ();
593
593
@@ -667,19 +667,19 @@ void HWAddressSanitizer::initializeCallbacks(Module &M) {
667
667
FunctionType::get (VoidTy, {IntptrTy, IntptrTy, Int8Ty}, false );
668
668
HwasanMemoryAccessCallbackFnTy =
669
669
FunctionType::get (VoidTy, {IntptrTy, Int8Ty}, false );
670
- HwasanMemTransferFnTy = FunctionType::get (
671
- Int8PtrTy , {Int8PtrTy, Int8PtrTy , IntptrTy, Int8Ty}, false );
672
- HwasanMemsetFnTy = FunctionType::get (
673
- Int8PtrTy , {Int8PtrTy , Int32Ty, IntptrTy, Int8Ty}, false );
670
+ HwasanMemTransferFnTy =
671
+ FunctionType::get (PtrTy , {PtrTy, PtrTy , IntptrTy, Int8Ty}, false );
672
+ HwasanMemsetFnTy =
673
+ FunctionType::get (PtrTy , {PtrTy , Int32Ty, IntptrTy, Int8Ty}, false );
674
674
} else {
675
675
HwasanMemoryAccessCallbackSizedFnTy =
676
676
FunctionType::get (VoidTy, {IntptrTy, IntptrTy}, false );
677
677
HwasanMemoryAccessCallbackFnTy =
678
678
FunctionType::get (VoidTy, {IntptrTy}, false );
679
679
HwasanMemTransferFnTy =
680
- FunctionType::get (Int8PtrTy , {Int8PtrTy, Int8PtrTy , IntptrTy}, false );
680
+ FunctionType::get (PtrTy , {PtrTy, PtrTy , IntptrTy}, false );
681
681
HwasanMemsetFnTy =
682
- FunctionType::get (Int8PtrTy , {Int8PtrTy , Int32Ty, IntptrTy}, false );
682
+ FunctionType::get (PtrTy , {PtrTy , Int32Ty, IntptrTy}, false );
683
683
}
684
684
685
685
for (size_t AccessIsWrite = 0 ; AccessIsWrite <= 1 ; AccessIsWrite++) {
@@ -713,7 +713,7 @@ void HWAddressSanitizer::initializeCallbacks(Module &M) {
713
713
MemIntrinCallbackPrefix + " memset" + MatchAllStr, HwasanMemsetFnTy);
714
714
715
715
HwasanTagMemoryFunc = M.getOrInsertFunction (" __hwasan_tag_memory" , VoidTy,
716
- Int8PtrTy , Int8Ty, IntptrTy);
716
+ PtrTy , Int8Ty, IntptrTy);
717
717
HwasanGenerateTagFunc =
718
718
M.getOrInsertFunction (" __hwasan_generate_tag" , Int8Ty);
719
719
@@ -733,7 +733,7 @@ Value *HWAddressSanitizer::getOpaqueNoopCast(IRBuilder<> &IRB, Value *Val) {
733
733
// This prevents code bloat as a result of rematerializing trivial definitions
734
734
// such as constants or global addresses at every load and store.
735
735
InlineAsm *Asm =
736
- InlineAsm::get (FunctionType::get (Int8PtrTy , {Val->getType ()}, false ),
736
+ InlineAsm::get (FunctionType::get (PtrTy , {Val->getType ()}, false ),
737
737
StringRef (" " ), StringRef (" =r,0" ),
738
738
/* hasSideEffects=*/ false );
739
739
return IRB.CreateCall (Asm, {Val}, " .hwasan.shadow" );
@@ -747,15 +747,15 @@ Value *HWAddressSanitizer::getShadowNonTls(IRBuilder<> &IRB) {
747
747
if (Mapping.Offset != kDynamicShadowSentinel )
748
748
return getOpaqueNoopCast (
749
749
IRB, ConstantExpr::getIntToPtr (
750
- ConstantInt::get (IntptrTy, Mapping.Offset ), Int8PtrTy ));
750
+ ConstantInt::get (IntptrTy, Mapping.Offset ), PtrTy ));
751
751
752
752
if (Mapping.InGlobal )
753
753
return getDynamicShadowIfunc (IRB);
754
754
755
755
Value *GlobalDynamicAddress =
756
756
IRB.GetInsertBlock ()->getParent ()->getParent ()->getOrInsertGlobal (
757
- kHwasanShadowMemoryDynamicAddress , Int8PtrTy );
758
- return IRB.CreateLoad (Int8PtrTy , GlobalDynamicAddress);
757
+ kHwasanShadowMemoryDynamicAddress , PtrTy );
758
+ return IRB.CreateLoad (PtrTy , GlobalDynamicAddress);
759
759
}
760
760
761
761
bool HWAddressSanitizer::ignoreAccess (Instruction *Inst, Value *Ptr) {
@@ -860,7 +860,7 @@ Value *HWAddressSanitizer::memToShadow(Value *Mem, IRBuilder<> &IRB) {
860
860
// Mem >> Scale
861
861
Value *Shadow = IRB.CreateLShr (Mem, Mapping.Scale );
862
862
if (Mapping.Offset == 0 )
863
- return IRB.CreateIntToPtr (Shadow, Int8PtrTy );
863
+ return IRB.CreateIntToPtr (Shadow, PtrTy );
864
864
// (Mem >> Scale) + Offset
865
865
return IRB.CreateGEP (Int8Ty, ShadowBase, Shadow);
866
866
}
@@ -952,7 +952,7 @@ void HWAddressSanitizer::instrumentMemAccessInline(Value *Ptr, bool IsWrite,
952
952
953
953
IRB.SetInsertPoint (TCI.TagMismatchTerm );
954
954
Value *InlineTagAddr = IRB.CreateOr (TCI.AddrLong , 15 );
955
- InlineTagAddr = IRB.CreateIntToPtr (InlineTagAddr, Int8PtrTy );
955
+ InlineTagAddr = IRB.CreateIntToPtr (InlineTagAddr, PtrTy );
956
956
Value *InlineTag = IRB.CreateLoad (Int8Ty, InlineTagAddr);
957
957
Value *InlineTagMismatch = IRB.CreateICmpNE (TCI.PtrTag , InlineTag);
958
958
SplitBlockAndInsertIfThen (InlineTagMismatch, TCI.TagMismatchTerm , false ,
@@ -1013,16 +1013,15 @@ void HWAddressSanitizer::instrumentMemIntrinsic(MemIntrinsic *MI) {
1013
1013
IRBuilder<> IRB (MI);
1014
1014
if (isa<MemTransferInst>(MI)) {
1015
1015
SmallVector<Value *, 4 > Args{
1016
- IRB.CreatePointerCast (MI->getOperand (0 ), IRB.getInt8PtrTy ()),
1017
- IRB.CreatePointerCast (MI->getOperand (1 ), IRB.getInt8PtrTy ()),
1016
+ MI->getOperand (0 ), MI->getOperand (1 ),
1018
1017
IRB.CreateIntCast (MI->getOperand (2 ), IntptrTy, false )};
1019
1018
1020
1019
if (UseMatchAllCallback)
1021
1020
Args.emplace_back (ConstantInt::get (Int8Ty, *MatchAllTag));
1022
1021
IRB.CreateCall (isa<MemMoveInst>(MI) ? HwasanMemmove : HwasanMemcpy, Args);
1023
1022
} else if (isa<MemSetInst>(MI)) {
1024
1023
SmallVector<Value *, 4 > Args{
1025
- IRB. CreatePointerCast ( MI->getOperand (0 ), IRB. getInt8PtrTy () ),
1024
+ MI->getOperand (0 ),
1026
1025
IRB.CreateIntCast (MI->getOperand (1 ), IRB.getInt32Ty (), false ),
1027
1026
IRB.CreateIntCast (MI->getOperand (2 ), IntptrTy, false )};
1028
1027
if (UseMatchAllCallback)
@@ -1084,7 +1083,7 @@ void HWAddressSanitizer::tagAlloca(IRBuilder<> &IRB, AllocaInst *AI, Value *Tag,
1084
1083
Tag = IRB.CreateTrunc (Tag, Int8Ty);
1085
1084
if (InstrumentWithCalls) {
1086
1085
IRB.CreateCall (HwasanTagMemoryFunc,
1087
- {IRB.CreatePointerCast (AI, Int8PtrTy ), Tag,
1086
+ {IRB.CreatePointerCast (AI, PtrTy ), Tag,
1088
1087
ConstantInt::get (IntptrTy, AlignedSize)});
1089
1088
} else {
1090
1089
size_t ShadowSize = Size >> Mapping.Scale ;
@@ -1102,9 +1101,9 @@ void HWAddressSanitizer::tagAlloca(IRBuilder<> &IRB, AllocaInst *AI, Value *Tag,
1102
1101
const uint8_t SizeRemainder = Size % Mapping.getObjectAlignment ().value ();
1103
1102
IRB.CreateStore (ConstantInt::get (Int8Ty, SizeRemainder),
1104
1103
IRB.CreateConstGEP1_32 (Int8Ty, ShadowPtr, ShadowSize));
1105
- IRB.CreateStore (Tag, IRB. CreateConstGEP1_32 (
1106
- Int8Ty, IRB.CreatePointerCast (AI, Int8PtrTy ),
1107
- AlignedSize - 1 ));
1104
+ IRB.CreateStore (
1105
+ Tag, IRB. CreateConstGEP1_32 ( Int8Ty, IRB.CreatePointerCast (AI, PtrTy ),
1106
+ AlignedSize - 1 ));
1108
1107
}
1109
1108
}
1110
1109
}
@@ -1243,7 +1242,7 @@ Value *HWAddressSanitizer::getSP(IRBuilder<> &IRB) {
1243
1242
Module *M = F->getParent ();
1244
1243
auto *GetStackPointerFn = Intrinsic::getDeclaration (
1245
1244
M, Intrinsic::frameaddress,
1246
- IRB.getInt8PtrTy (M->getDataLayout ().getAllocaAddrSpace ()));
1245
+ IRB.getPtrTy (M->getDataLayout ().getAllocaAddrSpace ()));
1247
1246
CachedSP = IRB.CreatePtrToInt (
1248
1247
IRB.CreateCall (GetStackPointerFn, {Constant::getNullValue (Int32Ty)}),
1249
1248
IntptrTy);
@@ -1344,7 +1343,7 @@ void HWAddressSanitizer::emitPrologue(IRBuilder<> &IRB, bool WithFrameRecord) {
1344
1343
ThreadLongMaybeUntagged,
1345
1344
ConstantInt::get (IntptrTy, (1ULL << kShadowBaseAlignment ) - 1 )),
1346
1345
ConstantInt::get (IntptrTy, 1 ), " hwasan.shadow" );
1347
- ShadowBase = IRB.CreateIntToPtr (ShadowBase, Int8PtrTy );
1346
+ ShadowBase = IRB.CreateIntToPtr (ShadowBase, PtrTy );
1348
1347
}
1349
1348
}
1350
1349
@@ -1404,7 +1403,7 @@ bool HWAddressSanitizer::instrumentStack(memtag::StackInfo &SInfo,
1404
1403
size_t Size = memtag::getAllocaSizeInBytes (*AI);
1405
1404
size_t AlignedSize = alignTo (Size, Mapping.getObjectAlignment ());
1406
1405
1407
- Value *AICast = IRB.CreatePointerCast (AI, Int8PtrTy );
1406
+ Value *AICast = IRB.CreatePointerCast (AI, PtrTy );
1408
1407
1409
1408
auto HandleLifetime = [&](IntrinsicInst *II) {
1410
1409
// Set the lifetime intrinsic to cover the whole alloca. This reduces the
@@ -1723,8 +1722,8 @@ void HWAddressSanitizer::instrumentPersonalityFunctions() {
1723
1722
return ;
1724
1723
1725
1724
FunctionCallee HwasanPersonalityWrapper = M.getOrInsertFunction (
1726
- " __hwasan_personality_wrapper" , Int32Ty, Int32Ty, Int32Ty, Int64Ty,
1727
- Int8PtrTy, Int8PtrTy, Int8PtrTy, Int8PtrTy, Int8PtrTy );
1725
+ " __hwasan_personality_wrapper" , Int32Ty, Int32Ty, Int32Ty, Int64Ty, PtrTy,
1726
+ PtrTy, PtrTy, PtrTy, PtrTy );
1728
1727
FunctionCallee UnwindGetGR = M.getOrInsertFunction (" _Unwind_GetGR" , VoidTy);
1729
1728
FunctionCallee UnwindGetCFA = M.getOrInsertFunction (" _Unwind_GetCFA" , VoidTy);
1730
1729
@@ -1733,7 +1732,7 @@ void HWAddressSanitizer::instrumentPersonalityFunctions() {
1733
1732
if (P.first )
1734
1733
ThunkName += (" ." + P.first ->getName ()).str ();
1735
1734
FunctionType *ThunkFnTy = FunctionType::get (
1736
- Int32Ty, {Int32Ty, Int32Ty, Int64Ty, Int8PtrTy, Int8PtrTy }, false );
1735
+ Int32Ty, {Int32Ty, Int32Ty, Int64Ty, PtrTy, PtrTy }, false );
1737
1736
bool IsLocal = P.first && (!isa<GlobalValue>(P.first ) ||
1738
1737
cast<GlobalValue>(P.first )->hasLocalLinkage ());
1739
1738
auto *ThunkFn = Function::Create (ThunkFnTy,
@@ -1751,7 +1750,7 @@ void HWAddressSanitizer::instrumentPersonalityFunctions() {
1751
1750
HwasanPersonalityWrapper,
1752
1751
{ThunkFn->getArg (0 ), ThunkFn->getArg (1 ), ThunkFn->getArg (2 ),
1753
1752
ThunkFn->getArg (3 ), ThunkFn->getArg (4 ),
1754
- P.first ? P.first : Constant::getNullValue (Int8PtrTy ),
1753
+ P.first ? P.first : Constant::getNullValue (PtrTy ),
1755
1754
UnwindGetGR.getCallee (), UnwindGetCFA.getCallee ()});
1756
1755
WrapperCall->setTailCall ();
1757
1756
IRB.CreateRet (WrapperCall);
0 commit comments