From 4e81b788bb6a2f4ecc51965232727d86ca375c94 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Tue, 28 Apr 2015 08:36:50 +0000 Subject: [PATCH] re PR c/65901 (no warning or error for va_arg (ap, void)) PR c/65901 * c-typeck.c (c_build_va_arg): Require TYPE be a complete type. * gcc.c-torture/compile/pr48767.c (foo): Add dg-error. * gcc.dg/pr65901.c: New test. From-SVN: r222515 --- gcc/c/ChangeLog | 5 +++++ gcc/c/c-typeck.c | 5 +++++ gcc/testsuite/ChangeLog | 8 +++++++- gcc/testsuite/gcc.c-torture/compile/pr48767.c | 2 +- gcc/testsuite/gcc.dg/pr65901.c | 16 ++++++++++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr65901.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 938262a93f7..5d50d4cb5be 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,8 @@ +2015-04-28 Marek Polacek + + PR c/65901 + * c-typeck.c (c_build_va_arg): Require TYPE be a complete type. + 2015-04-25 Marek Polacek PR c/52085 diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 91735b54dea..c58e9181f0e 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -12648,6 +12648,11 @@ c_build_va_arg (location_t loc, tree expr, tree type) if (warn_cxx_compat && TREE_CODE (type) == ENUMERAL_TYPE) warning_at (loc, OPT_Wc___compat, "C++ requires promoted type, not enum type, in %"); + if (type == error_mark_node || !COMPLETE_TYPE_P (type)) + { + c_incomplete_type_error (NULL_TREE, type); + return error_mark_node; + } return build_va_arg (loc, expr, type); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 703bc3aa19e..fcd850ce456 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2015-04-28 Marek Polacek + + PR c/65901 + * gcc.c-torture/compile/pr48767.c (foo): Add dg-error. + * gcc.dg/pr65901.c: New test. + 2015-04-28 Richard Biener PR tree-optimization/62283 @@ -11,7 +17,7 @@ 2015-04-27 Jeff Law - PR tree-optimization/65217 + PR tree-optimization/65217 * gcc.target/i386/pr65217.c: Remove XFAIL. 2015-04-27 Andre Vehreschild diff --git a/gcc/testsuite/gcc.c-torture/compile/pr48767.c b/gcc/testsuite/gcc.c-torture/compile/pr48767.c index 66cb34885d0..c8fef35ad37 100644 --- a/gcc/testsuite/gcc.c-torture/compile/pr48767.c +++ b/gcc/testsuite/gcc.c-torture/compile/pr48767.c @@ -3,5 +3,5 @@ void foo (__builtin_va_list ap) { - __builtin_va_arg (ap, void); + __builtin_va_arg (ap, void); /* { dg-error "invalid use of void expression" } */ } diff --git a/gcc/testsuite/gcc.dg/pr65901.c b/gcc/testsuite/gcc.dg/pr65901.c new file mode 100644 index 00000000000..8708a1ef1aa --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr65901.c @@ -0,0 +1,16 @@ +/* PR c/65901 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +struct S; +enum E; +union U; + +void +foo (__builtin_va_list ap) +{ + __builtin_va_arg (ap, void); /* { dg-error "invalid use of void expression" } */ + __builtin_va_arg (ap, struct S); /* { dg-error "invalid use of undefined type" } */ + __builtin_va_arg (ap, enum E); /* { dg-error "invalid use of undefined type" } */ + __builtin_va_arg (ap, union U); /* { dg-error "invalid use of undefined type" } */ +} -- 2.30.2