[PATCH] D111829: [Sanitizers] Replaced getMaxPointerSizeInBits with getPointerSizeInBits, which was causing failures for 32bit x86.

Kirill Stoimenov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 15 15:13:02 PDT 2021


kstoimenov updated this revision to Diff 380109.
kstoimenov added a comment.

Added a test, which fails without my fix. I named it i386-bug-fix.ll, let me know if you prefer a better name.
The culprit is the 'target datalayout' statement. I didn't dig deeper, but it somehow makes the max pointer size to be 64.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111829/new/

https://reviews.llvm.org/D111829

Files:
  llvm/lib/Analysis/StackSafetyAnalysis.cpp
  llvm/test/Analysis/StackSafetyAnalysis/i386-bug-fix.ll


Index: llvm/test/Analysis/StackSafetyAnalysis/i386-bug-fix.ll
===================================================================
--- /dev/null
+++ llvm/test/Analysis/StackSafetyAnalysis/i386-bug-fix.ll
@@ -0,0 +1,12 @@
+target datalayout = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128"
+target triple = "i386-unknown-linux-gnu"
+
+; Function Attrs: mustprogress norecurse sanitize_address uwtable
+define dso_local i32 @main(i32 %argc, i8** %argv)  {
+entry:
+  %0 = alloca i32, align 4
+  %1 = alloca i8, i64 32, align 32
+  %2 = ptrtoint i8* %1 to i32
+  store i32 %2, i32* %0, align 4
+  ret i32 0
+}
Index: llvm/lib/Analysis/StackSafetyAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/StackSafetyAnalysis.cpp
+++ llvm/lib/Analysis/StackSafetyAnalysis.cpp
@@ -154,7 +154,7 @@
 ConstantRange getStaticAllocaSizeRange(const AllocaInst &AI) {
   const DataLayout &DL = AI.getModule()->getDataLayout();
   TypeSize TS = DL.getTypeAllocSize(AI.getAllocatedType());
-  unsigned PointerSize = DL.getMaxPointerSizeInBits();
+  unsigned PointerSize = DL.getPointerSizeInBits();
   // Fallback to empty range for alloca size.
   ConstantRange R = ConstantRange::getEmpty(PointerSize);
   if (TS.isScalable())
@@ -752,10 +752,8 @@
         KV.second.Calls.clear();
     }
 
-  uint32_t PointerSize = Copy.begin()
-                             ->first->getParent()
-                             ->getDataLayout()
-                             .getMaxPointerSizeInBits();
+  uint32_t PointerSize =
+      Copy.begin()->first->getParent()->getDataLayout().getPointerSizeInBits();
   StackSafetyDataFlowAnalysis<GlobalValue> SSDFA(PointerSize, std::move(Copy));
 
   for (auto &F : SSDFA.run()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111829.380109.patch
Type: text/x-patch
Size: 1774 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211015/ebf9f9cb/attachment.bin>


More information about the llvm-commits mailing list