[llvm] Fix Endianess issue (PR #162881)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 29 07:51:05 PDT 2025


https://github.com/anoopkg6 updated https://github.com/llvm/llvm-project/pull/162881

>From 552bdae22fee776603ee62362daf2f6d6e6193ea Mon Sep 17 00:00:00 2001
From: anoopkg6 <anoopkg6 at github.com>
Date: Fri, 10 Oct 2025 18:22:29 +0200
Subject: [PATCH 1/2] Resolve Endianess issue with getting shadow 4 bytes
 corresponding to the first origin pointer

---
 .../Transforms/Instrumentation/DataFlowSanitizer.cpp   | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
index 5ba2167859490..b4f88779b00c0 100644
--- a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
@@ -2187,8 +2187,14 @@ std::pair<Value *, Value *> DFSanFunction::loadShadowFast(
       // and then the entire shadow for the second origin pointer (which will be
       // chosen by combineOrigins() iff the least-significant half of the wide
       // shadow was empty but the other half was not).
-      Value *WideShadowLo = IRB.CreateShl(
-          WideShadow, ConstantInt::get(WideShadowTy, WideShadowBitWidth / 2));
+      Value *WideShadowLo =
+          F->getParent()->getDataLayout().isLittleEndian()
+              ? IRB.CreateShl(
+                    WideShadow,
+                    ConstantInt::get(WideShadowTy, WideShadowBitWidth / 2))
+              : IRB.CreateAnd(
+                    WideShadow,
+                    ConstantInt::get(WideShadowTy, 0xFFFFFFFF00000000ULL));
       Shadows.push_back(WideShadow);
       Origins.push_back(DFS.loadNextOrigin(Pos, OriginAlign, &OriginAddr));
 

>From 774ef1cbad6ed4526c7fa06e2045b63be37afe5a Mon Sep 17 00:00:00 2001
From: anoopkg6 <anoopkg6 at github.com>
Date: Sun, 12 Oct 2025 14:39:07 +0200
Subject: [PATCH 2/2] Rewriting masking off WideShadow 4 bytes for Big Endians
 in terms of WideShadowBitWidth

---
 llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

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



More information about the llvm-commits mailing list