From f5bf912767ba19832bba7694fc679a5ec3c055ff Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Wed, 14 Nov 2012 22:09:59 +0000 Subject: [PATCH] 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 / . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167985 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenFunction.cpp | 11 ++++++++++- test/CodeGen/vla.c | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 18f1623d24..d7ccfc9f0b 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -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(VD)) + Ty = PVD->getOriginalType(); + else + Ty = VD->getType(); if (Ty->isVariablyModifiedType()) EmitVariablyModifiedType(Ty); diff --git a/test/CodeGen/vla.c b/test/CodeGen/vla.c index e151827627..f63796b39d 100644 --- a/test/CodeGen/vla.c +++ b/test/CodeGen/vla.c @@ -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) +}