[cfe-commits] r63394 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGen/sizeof-vla.c

Anders Carlsson andersca at mac.com
Fri Jan 30 08:41:05 PST 2009


Author: andersca
Date: Fri Jan 30 10:41:04 2009
New Revision: 63394

URL: http://llvm.org/viewvc/llvm-project?rev=63394&view=rev
Log:
Make sure to cast the VLA size of array to the type of size_t. Fixes PR3442.

Added:
    cfe/trunk/test/CodeGen/sizeof-vla.c
Modified:
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=63394&r1=63393&r2=63394&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Fri Jan 30 10:41:04 2009
@@ -684,7 +684,10 @@
         // sizeof(type) - make sure to emit the VLA size.
         CGF.EmitVLASize(TypeToSize);
       }
-      return CGF.GetVLASize(VAT);
+      
+      llvm::Value *VLASize = CGF.GetVLASize(VAT);
+      return Builder.CreateIntCast(VLASize, ConvertType(E->getType()), 
+                                   false, "conv");
     }
   }
 

Added: cfe/trunk/test/CodeGen/sizeof-vla.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/sizeof-vla.c?rev=63394&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/sizeof-vla.c (added)
+++ cfe/trunk/test/CodeGen/sizeof-vla.c Fri Jan 30 10:41:04 2009
@@ -0,0 +1,13 @@
+// RUN: clang -triple x86_64-unknown-unknown -emit-llvm -o %t %s
+
+// PR3442
+
+static void *g(unsigned long len);
+
+void
+f(int n)
+{
+ unsigned begin_set[n];
+ 
+ g(sizeof(begin_set));
+}





More information about the cfe-commits mailing list