]> granicus.if.org Git - clang/commitdiff
PR3247: Handle a couple of cases where we weren't emitting VLA sizes (and
authorEli Friedman <eli.friedman@gmail.com>
Mon, 20 Apr 2009 03:54:15 +0000 (03:54 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Mon, 20 Apr 2009 03:54:15 +0000 (03:54 +0000)
subsequently crashed).

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

lib/CodeGen/CGDecl.cpp
lib/CodeGen/CGExprScalar.cpp
test/CodeGen/variable-array.c

index 681d8f68afefdbd95ed101e632bcd2d51e9b5679..0a1d1d0bd1eb55f2a1e0fe704a1d536d249df874 100644 (file)
@@ -122,6 +122,10 @@ void CodeGenFunction::EmitStaticBlockVarDecl(const VarDecl &D) {
   // circular references.
   DMEntry = GV;
 
+  // Make sure to evaluate VLA bounds now so that we have them for later.
+  if (D.getType()->isVariablyModifiedType())
+    EmitVLASize(D.getType());
+
   if (D.getInit()) {
     llvm::Constant *Init = CGM.EmitConstantExpr(D.getInit(), D.getType(), this);
 
index 0c6e6c6854c364f78b585d3f9831759b06425117..77771bd937a894aa79da194ef0ec8f3d6a314874 100644 (file)
@@ -213,7 +213,11 @@ public:
     return llvm::Constant::getNullValue(ConvertType(E->getType()));
   }
   Value *VisitImplicitCastExpr(const ImplicitCastExpr *E);
-  Value *VisitCastExpr(const CastExpr *E) { 
+  Value *VisitCastExpr(const CastExpr *E) {
+    // Make sure to evaluate VLA bounds now so that we have them for later.
+    if (E->getType()->isVariablyModifiedType())
+      CGF.EmitVLASize(E->getType());
+
     return EmitCastExpr(E->getSubExpr(), E->getType());
   }
   Value *EmitCastExpr(const Expr *E, QualType T);
index 280539fa897ca735208b7d5a0713a9a156f6ea23..f5621c289d7a5dda14253dc77bf9df20cef9f85b 100644 (file)
@@ -1,7 +1,19 @@
-// RUN: clang-cc -emit-llvm < %s | grep puts
+// RUN: clang-cc -emit-llvm < %s | grep puts | count 4
 
+// PR3248
 int a(int x)
 {
   int (*y)[x];
   return sizeof(*(puts("asdf"),y));
 }
+
+// PR3247
+int b() {
+  return sizeof(*(char(*)[puts("asdf")])0);
+}
+
+// PR3247
+int c() {
+  static int (*y)[puts("asdf")];
+  return sizeof(*y);
+}