]> granicus.if.org Git - clang/commitdiff
When evaluating variably modified types for function parameters, dig out the
authorEli Friedman <eli.friedman@gmail.com>
Wed, 14 Nov 2012 22:09:59 +0000 (22:09 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Wed, 14 Nov 2012 22:09:59 +0000 (22:09 +0000)
type as written from the ParmVarDecl; it's unclear whether the standard
(C99 6.9.1p10) requires this, but we're following the precedent set by gcc,
and hopefully nobody will ever ask about this again.

PR9559 / <rdar://problem/12621983>.

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

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

index 18f1623d242e7da66de4147c943e5e9224475538..d7ccfc9f0b79d797e95f455f6495159c64ec8a68 100644 (file)
@@ -454,7 +454,16 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
   // emit the type size.
   for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
        i != e; ++i) {
-    QualType Ty = (*i)->getType();
+    const VarDecl *VD = *i;
+
+    // Dig out the type as written from ParmVarDecls; it's unclear whether
+    // the standard (C99 6.9.1p10) requires this, but we're following the
+    // precedent set by gcc.
+    QualType Ty;
+    if (const ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(VD))
+      Ty = PVD->getOriginalType();
+    else
+      Ty = VD->getType();
 
     if (Ty->isVariablyModifiedType())
       EmitVariablyModifiedType(Ty);
index e151827627060560dd9b6fb48c61d0b833522250..f63796b39dc22006c70c563c3546e01829a38094 100644 (file)
@@ -190,4 +190,8 @@ void test6(void)
   // CHECK-NEXT: store i32 0, i32* [[IX2]], align 4
 }
 
-
+// Follow gcc's behavior for VLAs in parameter lists.  PR9559.
+void test7(int a[b(0)]) {
+  // CHECK: define void @test7(
+  // CHECK: call i32 @b(i8* null)
+}