]> granicus.if.org Git - clang/commitdiff
PR3248: Make sure the evaluate the operand of a sizeof when it has a VLA type.
authorEli Friedman <eli.friedman@gmail.com>
Mon, 20 Apr 2009 03:21:44 +0000 (03:21 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Mon, 20 Apr 2009 03:21:44 +0000 (03:21 +0000)
Adapted from patch by Tim Northover.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69566 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprScalar.cpp
test/CodeGen/variable-array.c [new file with mode: 0644]

index 98c41e24b6a45d1a6f1c2f0747f25e4438865d15..0c6e6c6854c364f78b585d3f9831759b06425117 100644 (file)
@@ -725,6 +725,10 @@ ScalarExprEmitter::VisitSizeOfAlignOfExpr(const SizeOfAlignOfExpr *E) {
       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);
diff --git a/test/CodeGen/variable-array.c b/test/CodeGen/variable-array.c
new file mode 100644 (file)
index 0000000..280539f
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: clang-cc -emit-llvm < %s | grep puts
+
+int a(int x)
+{
+  int (*y)[x];
+  return sizeof(*(puts("asdf"),y));
+}