[llvm] c90681b - [Attributor][FIX] Don't crash on ptr2int/int2ptr instructions

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 3 08:44:51 PST 2020


Author: Johannes Doerfert
Date: 2020-01-03T10:43:40-06:00
New Revision: c90681b681a7a45cf5bf515d1904e2015f7ed524

URL: https://github.com/llvm/llvm-project/commit/c90681b681a7a45cf5bf515d1904e2015f7ed524
DIFF: https://github.com/llvm/llvm-project/commit/c90681b681a7a45cf5bf515d1904e2015f7ed524.diff

LOG: [Attributor][FIX] Don't crash on ptr2int/int2ptr instructions

An integer isn't allowed in getAlignmentForValue so we need to stop at a
ptr2int instruction during exploration.

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/Attributor.cpp
    llvm/test/Transforms/Attributor/align.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 2655930aec57..46664d627699 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -3466,7 +3466,8 @@ static unsigned int getKnownAlignForUse(Attributor &A,
   // We need to follow common pointer manipulation uses to the accesses they
   // feed into.
   if (isa<CastInst>(I)) {
-    TrackUse = true;
+    // Follow all but ptr2int casts.
+    TrackUse = !isa<PtrToIntInst>(I);
     return 0;
   }
   if (auto *GEP = dyn_cast<GetElementPtrInst>(I)) {

diff  --git a/llvm/test/Transforms/Attributor/align.ll b/llvm/test/Transforms/Attributor/align.ll
index 6f955be467bf..f01ae28431d6 100644
--- a/llvm/test/Transforms/Attributor/align.ll
+++ b/llvm/test/Transforms/Attributor/align.ll
@@ -398,5 +398,15 @@ define void @test12-6(i32* align 4 %p) {
   ret void
 }
 
+; Don't crash on ptr2int/int2ptr uses.
+define i64 @ptr2int(i32* %p) {
+  %p2i = ptrtoint i32* %p to i64
+  ret i64 %p2i
+}
+define i64* @int2ptr(i64 %i) {
+  %i2p = inttoptr i64 %i to i64*
+  ret i64* %i2p
+}
+
 attributes #0 = { nounwind uwtable noinline }
 attributes #1 = { uwtable noinline }


        


More information about the llvm-commits mailing list