@@ -64,11 +64,9 @@ static cl::opt<bool>
64
64
65
65
STATISTIC (NumInstrumentedAccesses, " Number of instrumented accesses" );
66
66
67
- static Regex AnonNameRegex (" ^_ZTS.*N[1-9][0-9]*_GLOBAL__N" );
68
-
69
67
namespace {
70
68
71
- // / TypeSanitizer: instrument the code in module to find type-based aliasing
69
+ // / TypeSanitizer: instrument the code in module to find type-based aliasing
72
70
// / violations.
73
71
struct TypeSanitizer {
74
72
TypeSanitizer (Module &M);
@@ -92,11 +90,9 @@ struct TypeSanitizer {
92
90
bool SanitizeFunction,
93
91
TypeDescriptorsMapTy &TypeDescriptors,
94
92
const DataLayout &DL);
95
- bool instrumentMemoryAccess (Instruction *I, MemoryLocation &MLoc,
96
- Value *ShadowBase, Value *AppMemMask,
97
- bool SanitizeFunction,
98
- TypeDescriptorsMapTy &TypeDescriptors,
99
- const DataLayout &DL);
93
+
94
+ // / Memory-related intrinsics/instructions reset the type of the destination
95
+ // / memory (including allocas and byval arguments).
100
96
bool instrumentMemInst (Value *I, Value *&ShadowBase, Value *&AppMemMask,
101
97
const DataLayout &DL);
102
98
@@ -150,9 +146,8 @@ void TypeSanitizer::initializeCallbacks(Module &M) {
150
146
OrdTy // Flags.
151
147
);
152
148
153
- TysanCtorFunction = cast<Function>(
154
- M.getOrInsertFunction (kTysanModuleCtorName , Attr, IRB.getVoidTy ())
155
- .getCallee ());
149
+ TysanCtorFunction =
150
+ M.getOrInsertFunction (kTysanModuleCtorName , Attr, IRB.getVoidTy ());
156
151
}
157
152
158
153
void TypeSanitizer::instrumentGlobals (Module &M) {
@@ -535,7 +530,6 @@ bool TypeSanitizer::run(Function &F, const TargetLibraryInfo &TLI) {
535
530
if (A.hasByValAttr ())
536
531
MemTypeResetInsts.push_back (&A);
537
532
538
-
539
533
Module &M = *F.getParent ();
540
534
TypeDescriptorsMapTy TypeDescriptors;
541
535
TypeNameMapTy TypeNames;
@@ -552,11 +546,22 @@ bool TypeSanitizer::run(Function &F, const TargetLibraryInfo &TLI) {
552
546
553
547
const DataLayout &DL = F.getParent ()->getDataLayout ();
554
548
bool SanitizeFunction = F.hasFnAttribute (Attribute::SanitizeType);
555
- Value *ShadowBase = MemoryAccesses.empty () ? nullptr : getShadowBase (F);
556
- Value *AppMemMask = MemoryAccesses.empty () ? nullptr : getAppMemMask (F);
557
- for (auto &MA : MemoryAccesses)
558
- Res |= instrumentMemoryAccess (MA.first , MA.second , ShadowBase, AppMemMask,
559
- SanitizeFunction, TypeDescriptors, DL);
549
+ bool NeedsInstrumentation =
550
+ MemTypeResetInsts.empty () && MemoryAccesses.empty ();
551
+ Value *ShadowBase = NeedsInstrumentation ? nullptr : getShadowBase (F);
552
+ Value *AppMemMask = NeedsInstrumentation ? nullptr : getAppMemMask (F);
553
+ for (const auto &[I, MLoc] : MemoryAccesses) {
554
+ IRBuilder<> IRB (I);
555
+ assert (MLoc.Size .isPrecise ());
556
+ if (instrumentWithShadowUpdate (
557
+ IRB, MLoc.AATags .TBAA , const_cast <Value *>(MLoc.Ptr ),
558
+ MLoc.Size .getValue (), I->mayReadFromMemory (), I->mayWriteToMemory (),
559
+ ShadowBase, AppMemMask, false , SanitizeFunction, TypeDescriptors,
560
+ DL)) {
561
+ ++NumInstrumentedAccesses;
562
+ Res = true ;
563
+ }
564
+ }
560
565
561
566
for (auto Inst : MemTypeResetInsts)
562
567
Res |= instrumentMemInst (Inst, ShadowBase, AppMemMask, DL);
@@ -712,26 +717,6 @@ bool TypeSanitizer::instrumentWithShadowUpdate(
712
717
return true ;
713
718
}
714
719
715
- bool TypeSanitizer::instrumentMemoryAccess (
716
- Instruction *I, MemoryLocation &MLoc, Value *ShadowBase, Value *AppMemMask,
717
- bool SanitizeFunction, TypeDescriptorsMapTy &TypeDescriptors,
718
- const DataLayout &DL) {
719
- IRBuilder<> IRB (I);
720
- assert (MLoc.Size .isPrecise ());
721
- if (instrumentWithShadowUpdate (
722
- IRB, MLoc.AATags .TBAA , const_cast <Value *>(MLoc.Ptr ),
723
- MLoc.Size .getValue (), I->mayReadFromMemory (), I->mayWriteToMemory (),
724
- ShadowBase, AppMemMask, false , SanitizeFunction, TypeDescriptors,
725
- DL)) {
726
- ++NumInstrumentedAccesses;
727
- return true ;
728
- }
729
-
730
- return false ;
731
- }
732
-
733
- // Memory-related intrinsics/instructions reset the type of the destination
734
- // memory (including allocas and byval arguments).
735
720
bool TypeSanitizer::instrumentMemInst (Value *V, Value *&ShadowBase,
736
721
Value *&AppMemMask,
737
722
const DataLayout &DL) {
0 commit comments