From 6cd586d2668653501ecd73d53e81cbc76db3a18c Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Fri, 30 Jan 2009 16:41:04 +0000 Subject: [PATCH] Make sure to cast the VLA size of array to the type of size_t. Fixes PR3442. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63394 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprScalar.cpp | 5 ++++- test/CodeGen/sizeof-vla.c | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/CodeGen/sizeof-vla.c diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 1d389b6049..44eefea71d 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -684,7 +684,10 @@ ScalarExprEmitter::VisitSizeOfAlignOfExpr(const SizeOfAlignOfExpr *E) { // 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"); } } diff --git a/test/CodeGen/sizeof-vla.c b/test/CodeGen/sizeof-vla.c new file mode 100644 index 0000000000..d49bf12097 --- /dev/null +++ b/test/CodeGen/sizeof-vla.c @@ -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)); +} -- 2.50.1