This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Fix diagnosing functions with VM return types (PR 39564)
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 25 Apr 2009 18:56:03 +0000 (UTC)
- Subject: Fix diagnosing functions with VM return types (PR 39564)
This patch fixes PR 39564, certain cases of functions with variably
modified types not being diagnosed.
I didn't add tests for the case of nested functions (which I avoided
diagnosing, since no storage class specifier there means "auto" rather
than "extern") because I found they resulted in an ICE (which I filed
as PR 39900).
Bootstrapped with no regressions on x86_64-unknown-linux-gnu. Applied
to mainline.
2009-04-25 Joseph Myers <joseph@codesourcery.com>
PR c/39564
* c-decl.c (grokdeclarator): Diagnose declarations of functions
with variably modified return type and no storage class
specifiers, except for the case of nested functions. Distinguish
extern declarations of functions with variably modified return
types from those of objects with variably modified types.
testsuite:
2009-04-25 Joseph Myers <joseph@codesourcery.com>
PR c/39564
* gcc.dg/vla-19.c: New test.
Index: c-decl.c
===================================================================
--- c-decl.c (revision 146747)
+++ c-decl.c (working copy)
@@ -5012,11 +5012,17 @@
DECL_TLS_MODEL (decl) = decl_default_tls_model (decl);
}
- if (storage_class == csc_extern
+ if ((storage_class == csc_extern
+ || (storage_class == csc_none
+ && TREE_CODE (type) == FUNCTION_TYPE
+ && !funcdef_flag))
&& variably_modified_type_p (type, NULL_TREE))
{
/* C99 6.7.5.2p2 */
- error ("object with variably modified type must have no linkage");
+ if (TREE_CODE (type) == FUNCTION_TYPE)
+ error ("non-nested function with variably modified type");
+ else
+ error ("object with variably modified type must have no linkage");
}
/* Record `register' declaration for warnings on &
Index: testsuite/gcc.dg/vla-19.c
===================================================================
--- testsuite/gcc.dg/vla-19.c (revision 0)
+++ testsuite/gcc.dg/vla-19.c (revision 0)
@@ -0,0 +1,32 @@
+/* Test diagnostics for variably modified function return types. PR
+ 39564. */
+/* { dg-do compile } */
+/* { dg-options "-std=c99" } */
+
+int a;
+
+void
+f1 (void)
+{
+ typedef int T[a];
+ extern T *g1 (void); /* { dg-error "non-nested function with variably modified type" } */
+}
+
+void
+f2 (void)
+{
+ extern int (*g2 (void))[a]; /* { dg-error "non-nested function with variably modified type" } */
+}
+
+void
+f3 (void)
+{
+ typedef int T[a];
+ T *g3 (void); /* { dg-error "non-nested function with variably modified type" } */
+}
+
+void
+f4 (void)
+{
+ int (*g4 (void))[a]; /* { dg-error "non-nested function with variably modified type" } */
+}
--
Joseph S. Myers
joseph@codesourcery.com