Index: llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp @@ -302,6 +302,12 @@ IRB.CreateLoad(IRB.CreateIntToPtr(ShadowLong, IRB.getInt8PtrTy())); Value *TagMismatch = IRB.CreateICmpNE(PtrTag, MemTag); + if (ClEnableKhwasan) { + Value *TagNotIgnored = IRB.CreateICmpNE(PtrTag, + ConstantInt::get(PtrTag->getType(), 0xFF)); + TagMismatch = IRB.CreateAnd(TagMismatch, TagNotIgnored); + } + TerminatorInst *CheckTerm = SplitBlockAndInsertIfThen(TagMismatch, InsertBefore, !Recover, MDBuilder(*C).createBranchWeights(1, 100000)); Index: llvm/test/Instrumentation/HWAddressSanitizer/kernel.ll =================================================================== --- llvm/test/Instrumentation/HWAddressSanitizer/kernel.ll +++ llvm/test/Instrumentation/HWAddressSanitizer/kernel.ll @@ -24,7 +24,9 @@ ; CHECK: %[[MEMTAG:[^ ]*]] = load i8, i8* %[[E]] ; CHECK: %[[F:[^ ]*]] = icmp ne i8 %[[PTRTAG]], %[[MEMTAG]] -; CHECK: br i1 %[[F]], label {{.*}}, label {{.*}}, !prof {{.*}} +; CHECK: %[[G:[^ ]*]] = icmp ne i8 %[[PTRTAG]], -1 +; CHECK: %[[H:[^ ]*]] = and i1 %[[F]], %[[G]] +; CHECK: br i1 %[[H]], label {{.*}}, label {{.*}}, !prof {{.*}} ; ABORT: call void asm sideeffect "brk #2304", "{x0}"(i64 %[[A]]) ; ABORT: unreachable