[llvm] [dfsan] Fix big-endian origin mask (PR #223247)

via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 13 07:18:09 PDT 2026


https://github.com/MarkVeerasingam created https://github.com/llvm/llvm-project/pull/223247

Fix the mask used when loading wide shadows on big-endian targets.

The previous expression used a 32-bit integer for the shift, producing an incorrect zero mask for 64-bit wide shadows. Changed the expression to use 1ULL so that a 64-bit mask is constructed correctly. The resulting mask keeps the upper 32 bits and clears the lower 32 bits.

Previously, the big-endian path generated:

```ll
%10 = load i64, ptr %6, align 1
%11 = and i64 %10, 0
```

With this change, it generates:

```ll
%10 = load i64, ptr %6, align 1
%11 = and i64 %10, -4294967296
```
Added a SystemZ big-endian regression test.

cc: @uweigand @anoopkg6


>From ef682cbea0482c625adaed15809a40b00c97fc88 Mon Sep 17 00:00:00 2001
From: MarkVeerasingam <markveer70 at gmail.com>
Date: Sun, 13 Sep 2026 07:11:03 -0500
Subject: [PATCH 1/2] [dfsan] Fix big-endian origin mask

---
 llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
index ad4e26450ca42..866622a2db8fb 100644
--- a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
@@ -2212,7 +2212,7 @@ std::pair<Value *, Value *> DFSanFunction::loadShadowFast(
               : IRB.CreateAnd(
                     WideShadow,
                     ConstantInt::get(WideShadowTy,
-                                     (1 - (1 << (WideShadowBitWidth / 2)))
+                                     ((1ULL << (WideShadowBitWidth / 2)) - 1)
                                          << (WideShadowBitWidth / 2)));
       Shadows.push_back(WideShadow);
       Origins.push_back(DFS.loadNextOrigin(Pos, OriginAlign, &OriginAddr));

>From ab05659fcc7007b03d05738471ee6e7739d1dbdf Mon Sep 17 00:00:00 2001
From: MarkVeerasingam <markveer70 at gmail.com>
Date: Sun, 13 Sep 2026 07:30:04 -0500
Subject: [PATCH 2/2] [dfsan] Test big-endian wide shadow mask

---
 .../DataFlowSanitizer/origin_load_big_endian.ll     | 13 +++++++++++++
 1 file changed, 13 insertions(+)
 create mode 100644 llvm/test/Instrumentation/DataFlowSanitizer/origin_load_big_endian.ll

diff --git a/llvm/test/Instrumentation/DataFlowSanitizer/origin_load_big_endian.ll b/llvm/test/Instrumentation/DataFlowSanitizer/origin_load_big_endian.ll
new file mode 100644
index 0000000000000..f3b7aea7d61e3
--- /dev/null
+++ b/llvm/test/Instrumentation/DataFlowSanitizer/origin_load_big_endian.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -passes=dfsan -dfsan-track-origins=1 -S | FileCheck %s
+
+target datalayout = "E-p:64:64:64-i1: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-n8:16:32:64-S128"
+target triple = "s390x-unknown-linux-gnu"
+
+define i64 @load64(ptr %p) {
+  ; CHECK-LABEL: @load64.dfsan
+  ; CHECK: %[[SHADOW:.*]] = load i64, ptr {{.*}}, align 1
+  ; CHECK-NEXT: and i64 %[[SHADOW]], -4294967296
+
+  %a = load i64, ptr %p
+  ret i64 %a
+}



More information about the llvm-commits mailing list