I'd prefer auto * in the if statement <br><br>On Monday, May 9, 2016, Sanjay Patel <<a href="mailto:spatel@rotateright.com">spatel@rotateright.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">spatel updated this revision to Diff 56633.<br>
spatel added a comment.<br>
<br>
Patch updated:<br>
Add a ConstExpr test case.<br>
<br>
<br>
<a href="http://reviews.llvm.org/D20077" target="_blank">http://reviews.llvm.org/D20077</a><br>
<br>
Files:<br>
  lib/Analysis/InlineCost.cpp<br>
  test/Transforms/Inline/alloca_test.ll<br>
<br>
Index: test/Transforms/Inline/alloca_test.ll<br>
===================================================================<br>
--- test/Transforms/Inline/alloca_test.ll<br>
+++ test/Transforms/Inline/alloca_test.ll<br>
@@ -1,3 +1,4 @@<br>
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py<br>
 ; This test ensures that alloca instructions in the entry block for an inlined<br>
 ; function are moved to the top of the function they are inlined into.<br>
 ;<br>
@@ -23,3 +24,32 @@<br>
   ret i32 %Y<br>
 }<br>
<br>
+; <a href="https://llvm.org/bugs/show_bug.cgi?id=27277" target="_blank">https://llvm.org/bugs/show_bug.cgi?id=27277</a><br>
+; Don't assume that the size is a ConstantInt (an undef value is also a constant).<br>
+<br>
+define void @PR27277(i32 %p1) {<br>
+; CHECK-LABEL: @PR27277(<br>
+; CHECK-NEXT:    [[VLA:%.*]] = alloca double, i32 %p1<br>
+; CHECK-NEXT:    call void @PR27277(i32 undef)<br>
+; CHECK-NEXT:    ret void<br>
+;<br>
+  %vla = alloca double, i32 %p1<br>
+  call void @PR27277(i32 undef)<br>
+  ret void<br>
+}<br>
+<br>
+; Don't assume that the size is a ConstantInt (a ConstExpr is also a constant).<br>
+<br>
+@GV = common global i32* null<br>
+<br>
+define void @PR27277_part2(i32 %p1) {<br>
+; CHECK-LABEL: @PR27277_part2(<br>
+; CHECK-NEXT:    [[VLA:%.*]] = alloca double, i32 %p1<br>
+; CHECK-NEXT:    call void @PR27277_part2(i32 ptrtoint (i32** @GV to i32))<br>
+; CHECK-NEXT:    ret void<br>
+;<br>
+  %vla = alloca double, i32 %p1<br>
+  call void @PR27277_part2(i32 ptrtoint (i32** @GV to i32))<br>
+  ret void<br>
+}<br>
+<br>
Index: lib/Analysis/InlineCost.cpp<br>
===================================================================<br>
--- lib/Analysis/InlineCost.cpp<br>
+++ lib/Analysis/InlineCost.cpp<br>
@@ -329,12 +329,12 @@<br>
<br>
 bool CallAnalyzer::visitAlloca(AllocaInst &I) {<br>
   // Check whether inlining will turn a dynamic alloca into a static<br>
-  // alloca, and handle that case.<br>
+  // alloca and handle that case.<br>
   if (I.isArrayAllocation()) {<br>
-    if (Constant *Size = SimplifiedValues.lookup(I.getArraySize())) {<br>
-      ConstantInt *AllocSize = dyn_cast<ConstantInt>(Size);<br>
-      assert(AllocSize && "Allocation size not a constant int?");<br>
+    if (ConstantInt *AllocSize = dyn_cast_or_null<ConstantInt>(<br>
+            SimplifiedValues.lookup(I.getArraySize()))) {<br>
       Type *Ty = I.getAllocatedType();<br>
+      // FIXME: This can't be right. AllocatedSize is in *bytes*.<br>
       AllocatedSize += Ty->getPrimitiveSizeInBits() * AllocSize->getZExtValue();<br>
       return Base::visitAlloca(I);<br>
     }<br>
<br>
<br>
</blockquote>