aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/CodeGen/CGExprScalar.cpp5
-rw-r--r--test/CodeGen/sizeof-vla.c13
2 files changed, 17 insertions, 1 deletions
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));
+}