[cfe-commits] r69566 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGen/variable-array.c

Eli Friedman eli.friedman at gmail.com
Sun Apr 19 20:21:47 PDT 2009


Author: efriedma
Date: Sun Apr 19 22:21:44 2009
New Revision: 69566

URL: http://llvm.org/viewvc/llvm-project?rev=69566&view=rev
Log:
PR3248: Make sure the evaluate the operand of a sizeof when it has a VLA type.

Adapted from patch by Tim Northover.


Added:
    cfe/trunk/test/CodeGen/variable-array.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=69566&r1=69565&r2=69566&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Sun Apr 19 22:21:44 2009
@@ -725,6 +725,10 @@
       if (E->isArgumentType()) {
         // sizeof(type) - make sure to emit the VLA size.
         CGF.EmitVLASize(TypeToSize);
+      } else {
+        // C99 6.5.3.4p2: If the argument is an expression of type
+        // VLA, it is evaluated.
+        CGF.EmitAnyExpr(E->getArgumentExpr());
       }
       
       return CGF.GetVLASize(VAT);

Added: cfe/trunk/test/CodeGen/variable-array.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/variable-array.c?rev=69566&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/variable-array.c (added)
+++ cfe/trunk/test/CodeGen/variable-array.c Sun Apr 19 22:21:44 2009
@@ -0,0 +1,7 @@
+// RUN: clang-cc -emit-llvm < %s | grep puts
+
+int a(int x)
+{
+  int (*y)[x];
+  return sizeof(*(puts("asdf"),y));
+}





More information about the cfe-commits mailing list