From: Anders Carlsson Date: Sun, 21 Dec 2008 03:33:21 +0000 (+0000) Subject: Make sure to emit the size expression for sizeof(type) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b50525ba0e996bc072cdb76152fcfe0bc64bb72a;p=clang Make sure to emit the size expression for sizeof(type) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61301 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 4984d0df35..d829facb16 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -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"); } diff --git a/test/CodeGen/vla.c b/test/CodeGen/vla.c index a584020abc..0881520c75 100644 --- a/test/CodeGen/vla.c +++ b/test/CodeGen/vla.c @@ -8,3 +8,8 @@ void a(int x) { arry[0] = 10; b(arry); } + +void b(int n) +{ + sizeof(int[n]); +}