[llvm] [NFCI][msan] Add test for "disjoint" OR (PR #145982)

Thurston Dang via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 26 15:52:18 PDT 2025


https://github.com/thurstond updated https://github.com/llvm/llvm-project/pull/145982

>From 35ae66a21cc7dc0883e9672792b80c242f0322d6 Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston at google.com>
Date: Thu, 26 Jun 2025 22:24:21 +0000
Subject: [PATCH 1/2] [NFCI][msan] Add test for "disjoint" OR

Disjoint OR is an extension to OR that was introduced in https://github.com/llvm/llvm-project/pull/72583
This patch adds a test case that shows MSan does not handle it
correctly.
---
 .../MemorySanitizer/disjoint_or.ll            | 50 +++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100644 llvm/test/Instrumentation/MemorySanitizer/disjoint_or.ll

diff --git a/llvm/test/Instrumentation/MemorySanitizer/disjoint_or.ll b/llvm/test/Instrumentation/MemorySanitizer/disjoint_or.ll
new file mode 100644
index 0000000000000..6570b6d9d91ca
--- /dev/null
+++ b/llvm/test/Instrumentation/MemorySanitizer/disjoint_or.ll
@@ -0,0 +1,50 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -S -passes=msan 2>&1 | FileCheck %s
+;
+; Test bitwise OR instructions, especially the "disjoint OR", which is
+; currently handled incorrectly by MSan (as if it was a regular OR).
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i8 @test_or(i8 %a, i8 %b) sanitize_memory {
+; CHECK-LABEL: define i8 @test_or(
+; CHECK-SAME: i8 [[A:%.*]], i8 [[B:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:    [[TMP1:%.*]] = load i8, ptr @__msan_param_tls, align 8
+; CHECK-NEXT:    [[TMP2:%.*]] = load i8, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__msan_param_tls to i64), i64 8) to ptr), align 8
+; CHECK-NEXT:    call void @llvm.donothing()
+; CHECK-NEXT:    [[TMP3:%.*]] = xor i8 [[A]], -1
+; CHECK-NEXT:    [[TMP4:%.*]] = xor i8 [[B]], -1
+; CHECK-NEXT:    [[TMP5:%.*]] = and i8 [[TMP1]], [[TMP2]]
+; CHECK-NEXT:    [[TMP6:%.*]] = and i8 [[TMP3]], [[TMP2]]
+; CHECK-NEXT:    [[TMP7:%.*]] = and i8 [[TMP1]], [[TMP4]]
+; CHECK-NEXT:    [[TMP8:%.*]] = or i8 [[TMP5]], [[TMP6]]
+; CHECK-NEXT:    [[TMP9:%.*]] = or i8 [[TMP8]], [[TMP7]]
+; CHECK-NEXT:    [[C:%.*]] = or i8 [[A]], [[B]]
+; CHECK-NEXT:    store i8 [[TMP9]], ptr @__msan_retval_tls, align 8
+; CHECK-NEXT:    ret i8 [[C]]
+;
+  %c = or i8 %a, %b
+  ret i8 %c
+}
+
+define i8 @test_disjoint_or(i8 %a, i8 %b) sanitize_memory {
+; CHECK-LABEL: define i8 @test_disjoint_or(
+; CHECK-SAME: i8 [[A:%.*]], i8 [[B:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:    [[TMP1:%.*]] = load i8, ptr @__msan_param_tls, align 8
+; CHECK-NEXT:    [[TMP2:%.*]] = load i8, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__msan_param_tls to i64), i64 8) to ptr), align 8
+; CHECK-NEXT:    call void @llvm.donothing()
+; CHECK-NEXT:    [[TMP3:%.*]] = xor i8 [[A]], -1
+; CHECK-NEXT:    [[TMP4:%.*]] = xor i8 [[B]], -1
+; CHECK-NEXT:    [[TMP5:%.*]] = and i8 [[TMP1]], [[TMP2]]
+; CHECK-NEXT:    [[TMP6:%.*]] = and i8 [[TMP3]], [[TMP2]]
+; CHECK-NEXT:    [[TMP7:%.*]] = and i8 [[TMP1]], [[TMP4]]
+; CHECK-NEXT:    [[TMP8:%.*]] = or i8 [[TMP5]], [[TMP6]]
+; CHECK-NEXT:    [[TMP11:%.*]] = or i8 [[TMP8]], [[TMP7]]
+; CHECK-NEXT:    [[C:%.*]] = or disjoint i8 [[A]], [[B]]
+; CHECK-NEXT:    store i8 [[TMP11]], ptr @__msan_retval_tls, align 8
+; CHECK-NEXT:    ret i8 [[C]]
+;
+  %c = or disjoint i8 %a, %b
+  ret i8 %c
+}

>From 4c3148090bc57e816eb423f62359e412d35a89e2 Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston at google.com>
Date: Thu, 26 Jun 2025 22:51:49 +0000
Subject: [PATCH 2/2] Rename to or.ll

---
 .../Instrumentation/MemorySanitizer/{disjoint_or.ll => or.ll}     | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename llvm/test/Instrumentation/MemorySanitizer/{disjoint_or.ll => or.ll} (100%)

diff --git a/llvm/test/Instrumentation/MemorySanitizer/disjoint_or.ll b/llvm/test/Instrumentation/MemorySanitizer/or.ll
similarity index 100%
rename from llvm/test/Instrumentation/MemorySanitizer/disjoint_or.ll
rename to llvm/test/Instrumentation/MemorySanitizer/or.ll



More information about the llvm-commits mailing list