]> granicus.if.org Git - clang/commitdiff
Make sure to emit the size expression for sizeof(type)
authorAnders Carlsson <andersca@mac.com>
Sun, 21 Dec 2008 03:33:21 +0000 (03:33 +0000)
committerAnders Carlsson <andersca@mac.com>
Sun, 21 Dec 2008 03:33:21 +0000 (03:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61301 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprScalar.cpp
test/CodeGen/vla.c

index 4984d0df355e86b95b3cec97473cd3959584b3e4..d829facb16d6f0eaf19559c11ea31bfccd8d91a5 100644 (file)
@@ -663,8 +663,13 @@ ScalarExprEmitter::VisitSizeOfAlignOfExpr(const SizeOfAlignOfExpr *E) {
   
   if (const VariableArrayType *VAT = 
         CGF.getContext().getAsVariableArrayType(TypeToSize)) {
-    if (E->isSizeOf())
+    if (E->isSizeOf()) {
+      if (E->isArgumentType()) {
+        // sizeof(type) - make sure to emit the VLA size.
+        CGF.EmitVLASize(TypeToSize);
+      }
       return CGF.GetVLASize(VAT);
+    }
     // FIXME: This should be an UNSUPPORTED error.
     assert(0 && "alignof VLAs not implemented yet");
   }
index a584020abc825d57da10bebaea669956e920adde..0881520c75788367cf1b357bbc9f2647e52b30b5 100644 (file)
@@ -8,3 +8,8 @@ void a(int x) {
   arry[0] = 10;
   b(arry);
 }
+
+void b(int n)
+{
+  sizeof(int[n]);
+}