diff --git a/compiler-rt/test/hwasan/TestCases/short-granule-and-match-all-tag.cpp b/compiler-rt/test/hwasan/TestCases/short-granule-and-match-all-tag.cpp new file mode 100644 --- /dev/null +++ b/compiler-rt/test/hwasan/TestCases/short-granule-and-match-all-tag.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_hwasan %s -o %t && not %run %t 2>&1 | FileCheck %s + +#include +#include +#include + +int main() { + __hwasan_enable_allocator_tagging(); + fprintf(stderr, "main\n"); + char *x = (char *)malloc(40); + char volatile z = *x; + free(x); + return 0; +} + +// CHECK: main +// CHECK-NOT: ERROR: HWAddressSanitizer: tag-mismatch on address {{.*}} at pc {{[0x]+}} +// CHECK-NOT: WRITE of size 1 {{.*}} in thread T0 diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp --- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp +++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp @@ -531,14 +531,14 @@ if (HasMatchAllTag) { OutStreamer->emitInstruction(MCInstBuilder(AArch64::UBFMXri) - .addReg(AArch64::X16) + .addReg(AArch64::X17) .addReg(Reg) .addImm(56) .addImm(63), *STI); OutStreamer->emitInstruction(MCInstBuilder(AArch64::SUBSXri) .addReg(AArch64::XZR) - .addReg(AArch64::X16) + .addReg(AArch64::X17) .addImm(MatchAllTag) .addImm(0), *STI); diff --git a/llvm/test/CodeGen/AArch64/hwasan-check-memaccess.ll b/llvm/test/CodeGen/AArch64/hwasan-check-memaccess.ll --- a/llvm/test/CodeGen/AArch64/hwasan-check-memaccess.ll +++ b/llvm/test/CodeGen/AArch64/hwasan-check-memaccess.ll @@ -36,6 +36,12 @@ ret void } +define void @f4(ptr %x0, ptr %x1) { + ; 0x1000010 (access-size-index = 0, is-write = 1, match-all = 0x0) + call void @llvm.hwasan.check.memaccess.shortgranules(ptr %x0, ptr %x1, i32 16777232) + ret void +} + declare void @llvm.hwasan.check.memaccess(ptr, ptr, i32) declare void @llvm.hwasan.check.memaccess.shortgranules(ptr, ptr, i32) @@ -98,11 +104,40 @@ ; CHECK-NEXT: .Ltmp6: ; CHECK-NEXT: ret ; CHECK-NEXT: .Ltmp5: -; CHECK-NEXT: lsr x16, x1, #56 -; CHECK-NEXT: cmp x16, #255 +; CHECK-NEXT: lsr x17, x1, #56 +; CHECK-NEXT: cmp x17, #255 ; CHECK-NEXT: b.eq .Ltmp6 ; CHECK-NEXT: stp x0, x1, [sp, #-256]! ; CHECK-NEXT: stp x29, x30, [sp, #232] ; CHECK-NEXT: mov x0, x1 ; CHECK-NEXT: mov x1, #0 ; CHECK-NEXT: b __hwasan_tag_mismatch + +; CHECK: __hwasan_check_x1_16777232_short_v2: +; CHECK-NEXT: sbfx x16, x1, #4, #52 +; CHECK-NEXT: ldrb w16, [x20, x16] +; CHECK-NEXT: cmp x16, x1, lsr #56 +; CHECK-NEXT: b.ne .Ltmp7 +; CHECK-NEXT: .Ltmp8: +; CHECK-NEXT: ret +; CHECK-NEXT: .Ltmp7: +; CHECK-NEXT: lsr x17, x1, #56 +; CHECK-NEXT: cmp x17, #0 +; CHECK-NEXT: b.eq .Ltmp8 +; CHECK-NEXT: cmp w16, #15 +; CHECK-NEXT: b.hi .Ltmp9 +; CHECK-NEXT: and x17, x1, #0xf +; CHECK-NEXT: cmp w16, w17 +; CHECK-NEXT: b.ls .Ltmp9 +; CHECK-NEXT: orr x16, x1, #0xf +; CHECK-NEXT: ldrb w16, [x16] +; CHECK-NEXT: cmp x16, x1, lsr #56 +; CHECK-NEXT: b.eq .Ltmp8 +; CHECK-NEXT: .Ltmp9: +; CHECK-NEXT: stp x0, x1, [sp, #-256]! +; CHECK-NEXT: stp x29, x30, [sp, #232] +; CHECK-NEXT: mov x0, x1 +; CHECK-NEXT: mov x1, #16 +; CHECK-NEXT: adrp x16, :got:__hwasan_tag_mismatch_v2 +; CHECK-NEXT: ldr x16, [x16, :got_lo12:__hwasan_tag_mismatch_v2] +; CHECK-NEXT: br x16