[cfe-commits] r71941 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/Sema/vla.c

Eli Friedman eli.friedman at gmail.com
Sat May 16 05:16:01 PDT 2009


Author: efriedma
Date: Sat May 16 07:15:55 2009
New Revision: 71941

URL: http://llvm.org/viewvc/llvm-project?rev=71941&view=rev
Log:
PR2044: reject declarations of functions returning variably modified 
types.


Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/vla.c

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=71941&r1=71940&r2=71941&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat May 16 07:15:55 2009
@@ -2344,6 +2344,13 @@
   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.

Modified: cfe/trunk/test/Sema/vla.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/vla.c?rev=71941&r1=71940&r2=71941&view=diff

==============================================================================
--- cfe/trunk/test/Sema/vla.c (original)
+++ cfe/trunk/test/Sema/vla.c Sat May 16 07:15:55 2009
@@ -46,3 +46,8 @@
 
 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}}





More information about the cfe-commits mailing list