diff options
author | Joseph Myers <jsm@polyomino.org.uk> | 2004-09-09 02:16:16 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2004-09-09 02:16:16 +0100 |
commit | bc4b653be6451211226018f96146a1eaa439b6cd (patch) | |
tree | cafc9cbafbe798461e115c710492d5167b17d34a /gcc/testsuite/gcc.dg | |
parent | 1835f9efd2e8bac8a4a44497915f37f45144e932 (diff) | |
download | gcc-bc4b653be6451211226018f96146a1eaa439b6cd.zip gcc-bc4b653be6451211226018f96146a1eaa439b6cd.tar.gz gcc-bc4b653be6451211226018f96146a1eaa439b6cd.tar.bz2 |
c-tree.h (C_DECL_USED, [...]): New.
* c-tree.h (C_DECL_USED, parser_obstack, in_alignof, in_sizeof,
in_typeof, record_maybe_used_decl, pop_maybe_used,
c_expr_sizeof_expr, c_expr_sizeof_type): New.
* c-decl.c (parser_obstack): New.
(c_init_decl_processing): Initialize parser_obstack.
(c_write_global_declarations_1): Check for used but undefined
static functions.
* c-parse.in (%union): Add otype.
(save_obstack_position): New.
(extdefs): Use it.
(unary_expr): Update in_sizeof and in_alignof. Use
c_expr_sizeof_expr and c_expr_sizeof_type.
(sizeof): Update in_sizeof.
(alignof): Update in_alignof.
(typeof): Update in_typeof.
(typespec_nonreserved_nonattr): Call pop_maybe_used.
* c-typeck.c (in_alignof, in_sizeof, in_typeof, struct
maybe_used_decl, maybe_used_decls, record_maybe_used_decl,
pop_maybe_used, c_expr_sizeof_expr, c_expr_sizeof_type): New.
(build_external_ref): Set C_DECL_USED or call
record_maybe_used_decl if appropriate.
* toplev.c (check_global_declarations): Check TREE_NO_WARNING.
testsuite:
* gcc.dg/c90-static-1.c, gcc.dg/c99-static-1.c,
gcc.dg/gnu99-static-1.c: New tests.
From-SVN: r87216
Diffstat (limited to 'gcc/testsuite/gcc.dg')
-rw-r--r-- | gcc/testsuite/gcc.dg/c90-static-1.c | 22 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/c99-static-1.c | 35 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/gnu99-static-1.c | 30 |
3 files changed, 87 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/c90-static-1.c b/gcc/testsuite/gcc.dg/c90-static-1.c new file mode 100644 index 0000000..cc6f320 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c90-static-1.c @@ -0,0 +1,22 @@ +/* It is a constraint violation for a static function to be declared + but not defined if it is used except in a sizeof expression. The + use of the function simply being unevaluated is not enough. */ +/* Origin: Joseph Myers <jsm@polyomino.org.uk> */ +/* { dg-do compile } */ +/* { dg-options "-O2 -std=iso9899:1990 -pedantic-errors" } */ + +/* Constraint violation (trivial case, where function is used). */ +static void f0(void); /* { dg-error "used but never defined" } */ +void g0(void) { f0(); } + +/* Constraint violation. */ +static void f1(void); /* { dg-error "used but never defined" } */ +void g1(void) { if (0) { f1(); } } + +/* Constraint violation. */ +static int f2(void); /* { dg-error "used but never defined" } */ +void g2(void) { 0 ? f2() : 0; } + +/* OK. */ +static int f3(void); +void g3(void) { sizeof(f3()); } diff --git a/gcc/testsuite/gcc.dg/c99-static-1.c b/gcc/testsuite/gcc.dg/c99-static-1.c new file mode 100644 index 0000000..3c817c6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c99-static-1.c @@ -0,0 +1,35 @@ +/* It is a constraint violation for a static function to be declared + but not defined if it is used except in a sizeof expression whose + result is an integer constant. The use of the function simply + being unevaluated is not enough. */ +/* Origin: Joseph Myers <jsm@polyomino.org.uk> */ +/* { dg-do compile } */ +/* { dg-options "-O2 -std=iso9899:1999 -pedantic-errors" } */ + +/* Constraint violation (trivial case, where function is used). */ +static void f0(void); /* { dg-error "used but never defined" } */ +void g0(void) { f0(); } + +/* Constraint violation. */ +static void f1(void); /* { dg-error "used but never defined" } */ +void g1(void) { if (0) { f1(); } } + +/* Constraint violation. */ +static int f2(void); /* { dg-error "used but never defined" } */ +void g2(void) { 0 ? f2() : 0; } + +/* OK. */ +static int f3(void); +void g3(void) { sizeof(f3()); } + +/* OK (VM type, not VLA). */ +static int f4(void); +void g4(void) { sizeof(int (*)[f4()]); } + +/* Constraint violation (VLA). */ +static int f5(void); /* { dg-error "used but never defined" "VLA" { xfail *-*-* } } */ +void g5(void) { sizeof(int [0 ? f5() : 1]); } + +/* OK (non-constant sizeof inside constant sizeof). */ +static int f6(void); +void g6(void) { sizeof(sizeof(int [f6()])); } diff --git a/gcc/testsuite/gcc.dg/gnu99-static-1.c b/gcc/testsuite/gcc.dg/gnu99-static-1.c new file mode 100644 index 0000000..b600a4b --- /dev/null +++ b/gcc/testsuite/gcc.dg/gnu99-static-1.c @@ -0,0 +1,30 @@ +/* It is a constraint violation for a static function to be declared + but not defined if it is used except in a sizeof expression whose + result is an integer constant. In GNU C, we need to consider + __typeof__ and __alignof__ as well. __alignof__ always returns a + constant, so static functions can always be used therein. + __typeof__ evaluates its argument iff it has variably modified + type. */ +/* Origin: Joseph Myers <jsm@polyomino.org.uk> */ +/* { dg-do compile } */ +/* { dg-options "-O2 -std=gnu99 -pedantic-errors" } */ + +/* __alignof__, OK. */ +static int f0(void); +void g0(void) { __alignof__(f0()); } + +/* __typeof__ not variably modified, OK. */ +static int f1(void); +void g1(void) { __typeof__(f1()) x; } + +/* __typeof__ variably modified, not OK. */ +static int f2(void); /* { dg-error "used but never defined" } */ +void g2(void) { __typeof__(int [f2()]) x; } + +/* __typeof__ variably modified, not OK. */ +static int f3(void); /* { dg-error "used but never defined" } */ +void g3(void) { __typeof__(int (*)[f3()]) x; } + +/* Integer sizeof of VM typeof, OK. */ +static int f4(void); +void g4(void) { sizeof(__typeof__(int (*)[f3()])); } |