From 88f7b576dde22ca95b4c73c4fd463e2e799873a7 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Sat, 16 May 2009 12:15:55 +0000 Subject: [PATCH] PR2044: reject declarations of functions returning variably modified types. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71941 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 7 +++++++ test/Sema/vla.c | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 1ed063ab40..077658c624 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -2344,6 +2344,13 @@ void Sema::CheckFunctionDeclaration(FunctionDecl *NewFD, NamedDecl *&PrevDecl, if (NewFD->isInvalidDecl()) return; + if (NewFD->getResultType()->isVariablyModifiedType()) { + // Functions returning a variably modified type violate C99 6.7.5.2p2 + // because all functions have linkage. + Diag(NewFD->getLocation(), diag::err_vm_func_decl); + return NewFD->setInvalidDecl(); + } + // Semantic checking for this function declaration (in isolation). if (getLangOptions().CPlusPlus) { // C++-specific checks. diff --git a/test/Sema/vla.c b/test/Sema/vla.c index b4839143bf..674547297a 100644 --- a/test/Sema/vla.c +++ b/test/Sema/vla.c @@ -46,3 +46,8 @@ static const unsigned array[((2 * (int)((((4) / 2) + 1.0/3.0) * (4) - 1e-8)) + 1 int a[*]; // expected-error {{star modifier used outside of function prototype}} int f4(int a[*][*]); + +// PR2044 +int pr2044(int b) {int (*c(void))[b];**c() = 2;} // expected-error {{variably modified type}} +int pr2044b; +int (*pr2044c(void))[pr2044b]; // expected-error {{variably modified type}} -- 2.40.0