[PATCH] D15597: [ValueTracking] Handle opaque types in isDereferenceableAndAlignedPointer.

Michael Zolotukhin via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 16 16:02:36 PST 2015


mzolotukhin created this revision.
mzolotukhin added reviewers: apilipenko, reames, sanjoy, hfinkel.
mzolotukhin added a subscriber: llvm-commits.

While we do check that type Ty is sized, an opaque type still can slip thru
this check to isAligned function and hit an assertion there. The fix is to
check type of value after stripping constant offsets. Does it look good?

http://reviews.llvm.org/D15597

Files:
  lib/Analysis/ValueTracking.cpp
  test/Analysis/ValueTracking/memory-dereferenceable.ll

Index: test/Analysis/ValueTracking/memory-dereferenceable.ll
===================================================================
--- test/Analysis/ValueTracking/memory-dereferenceable.ll
+++ test/Analysis/ValueTracking/memory-dereferenceable.ll
@@ -5,6 +5,8 @@
 
 target datalayout = "e"
 
+%TypeOpaque = type opaque
+
 declare zeroext i1 @return_i1()
 
 declare i32* @foo()
@@ -17,6 +19,7 @@
 @globalptr.align1 = external global i8, align 1
 @globalptr.align16 = external global i8, align 16
 
+; CHECK-LABEL: 'test'
 define void @test(i32 addrspace(1)* dereferenceable(8) %dparam,
                   i8 addrspace(1)* dereferenceable(32) align 1 %dparam.align1,
                   i8 addrspace(1)* dereferenceable(32) align 16 %dparam.align16)
@@ -133,6 +136,23 @@
     ret void
 }
 
+; Just check that we don't crash.
+; CHECK-LABEL: 'opaque_type_crasher'
+define void @opaque_type_crasher(%TypeOpaque* dereferenceable(16) %a) {
+entry:
+  %bc = bitcast %TypeOpaque* %a to i8*
+  %ptr8 = getelementptr inbounds i8, i8* %bc, i32 8
+  %ptr32 = bitcast i8* %ptr8 to i32*
+  br i1 undef, label %if.then, label %if.end
+
+if.then:
+  %res = load i32, i32* %ptr32, align 4
+  br label %if.end
+
+if.end:
+  ret void
+}
+
 declare i32 @llvm.experimental.gc.statepoint.p0f_i1f(i64, i32, i1 ()*, i32, i32, ...)
 declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32, i32, i32)
 
Index: lib/Analysis/ValueTracking.cpp
===================================================================
--- lib/Analysis/ValueTracking.cpp
+++ lib/Analysis/ValueTracking.cpp
@@ -3299,7 +3299,16 @@
     APInt Offset(DL.getTypeStoreSizeInBits(VTy), 0);
     const Value *BV = V->stripAndAccumulateInBoundsConstantOffsets(DL, Offset);
 
-    if (Offset.isNonNegative())
+    // Don't deal with opaque types - we don't know whether they're aligned or
+    // not.
+    bool TypeIsOpaque = false;
+    if (StructType *STy =
+            dyn_cast<StructType>(BV->getType()->getPointerElementType())) {
+      if (STy->isOpaque())
+        TypeIsOpaque = true;
+    }
+
+    if (!TypeIsOpaque && Offset.isNonNegative())
       if (isDereferenceableFromAttribute(BV, Offset, Ty, DL, CtxI, DT, TLI) &&
           isAligned(BV, Offset, Align, DL))
         return true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15597.43081.patch
Type: text/x-patch
Size: 2247 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151217/0b300256/attachment.bin>


More information about the llvm-commits mailing list