Index: llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp @@ -238,7 +238,7 @@ Value *getUARTag(IRBuilder<> &IRB, Value *StackTag); Value *getHwasanThreadSlotPtr(IRBuilder<> &IRB, Type *Ty); - void emitPrologue(IRBuilder<> &IRB, bool WithFrameRecord); + bool emitPrologue(IRBuilder<> &IRB, bool WithFrameRecord); void instrumentGlobal(GlobalVariable *GV, uint8_t Tag); void instrumentGlobals(); @@ -913,15 +913,15 @@ return nullptr; } -void HWAddressSanitizer::emitPrologue(IRBuilder<> &IRB, bool WithFrameRecord) { +bool HWAddressSanitizer::emitPrologue(IRBuilder<> &IRB, bool WithFrameRecord) { if (!Mapping.InTls) { LocalDynamicShadow = getDynamicShadowNonTls(IRB); - return; + return LocalDynamicShadow != nullptr; } if (!WithFrameRecord && TargetTriple.isAndroid()) { LocalDynamicShadow = getDynamicShadowIfunc(IRB); - return; + return LocalDynamicShadow != nullptr; } Value *SlotPtr = getHwasanThreadSlotPtr(IRB, IntptrTy); @@ -987,6 +987,8 @@ ConstantInt::get(IntptrTy, (1ULL << kShadowBaseAlignment) - 1)), ConstantInt::get(IntptrTy, 1), "hwasan.shadow"); LocalDynamicShadow = IRB.CreateIntToPtr(LocalDynamicShadow, Int8PtrTy); + + return true; } Value *HWAddressSanitizer::readRegister(IRBuilder<> &IRB, StringRef Name) { @@ -1121,36 +1123,38 @@ initializeCallbacks(*F.getParent()); - if (!LandingPadVec.empty()) - instrumentLandingPads(LandingPadVec); + bool Changed = false; + + if (!LandingPadVec.empty()) { + Changed |= instrumentLandingPads(LandingPadVec); + } if (AllocasToInstrument.empty() && F.hasPersonalityFn() && F.getPersonalityFn()->getName() == kHwasanPersonalityThunkName) { // __hwasan_personality_thunk is a no-op for functions without an // instrumented stack, so we can drop it. F.setPersonalityFn(nullptr); + Changed = true; } if (AllocasToInstrument.empty() && OperandsToInstrument.empty() && IntrinToInstrument.empty()) - return false; + return Changed; assert(!LocalDynamicShadow); Instruction *InsertPt = &*F.getEntryBlock().begin(); IRBuilder<> EntryIRB(InsertPt); - emitPrologue(EntryIRB, + Changed |= emitPrologue(EntryIRB, /*WithFrameRecord*/ ClRecordStackHistory && !AllocasToInstrument.empty()); - bool Changed = false; if (!AllocasToInstrument.empty()) { Value *StackTag = ClGenerateTagsWithCalls ? nullptr : getStackBaseTag(EntryIRB); Changed |= instrumentStack(AllocasToInstrument, AllocaDbgMap, RetVec, StackTag); } - // Pad and align each of the allocas that we instrumented to stop small // uninteresting allocas from hiding in instrumented alloca's padding and so // that we have enough space to store real tags for short granules.