[cfe-commits] r167985 - in /cfe/trunk: lib/CodeGen/CodeGenFunction.cpp test/CodeGen/vla.c

Eli Friedman eli.friedman at gmail.com
Wed Nov 14 14:10:00 PST 2012


Author: efriedma
Date: Wed Nov 14 16:09:59 2012
New Revision: 167985

URL: http://llvm.org/viewvc/llvm-project?rev=167985&view=rev
Log:
When evaluating variably modified types for function parameters, dig out the
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>.


Modified:
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/test/CodeGen/vla.c

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=167985&r1=167984&r2=167985&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Wed Nov 14 16:09:59 2012
@@ -454,7 +454,16 @@
   // 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);

Modified: cfe/trunk/test/CodeGen/vla.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/vla.c?rev=167985&r1=167984&r2=167985&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/vla.c (original)
+++ cfe/trunk/test/CodeGen/vla.c Wed Nov 14 16:09:59 2012
@@ -190,4 +190,8 @@
   // 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)
+}





More information about the cfe-commits mailing list