diff options
author | Andrew Pinski <quic_apinski@quicinc.com> | 2025-03-06 16:07:02 -0800 |
---|---|---|
committer | Andrew Pinski <quic_apinski@quicinc.com> | 2025-03-07 18:00:06 +0000 |
commit | cf65235e03d2eb1667624943eae8f7fc355bceaf (patch) | |
tree | 81602b1b7a8d8579b8f5f3e30034669220d61f6b /gcc | |
parent | aa55a6a30bc4778938af42dac9b624cf67fa4698 (diff) | |
download | gcc-cf65235e03d2eb1667624943eae8f7fc355bceaf.zip gcc-cf65235e03d2eb1667624943eae8f7fc355bceaf.tar.gz gcc-cf65235e03d2eb1667624943eae8f7fc355bceaf.tar.bz2 |
c: Fix warning after an error on a return statment [PR60440]
Like r5-6912-g3dbb84276aca10 but this is for the C front-end.
Basically we have an error on a return statement, we just return
error_mark_node and then the warning happens as there is no return
statement. Anyways instead mark the current function for supression
of the warning instead.
PR c/60440
gcc/c/ChangeLog:
* c-typeck.cc (c_finish_return): Mark the current function
for supression of the -Wreturn-type if there was an error
on the return statement.
gcc/testsuite/ChangeLog:
* gcc.dg/Wreturn-mismatch-2.c: Change dg-warning
for the last -Wreturn-type to dg-bogus.
* gcc.dg/pr60440-1.c: New test.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c/c-typeck.cc | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wreturn-mismatch-2.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr60440-1.c | 10 |
3 files changed, 17 insertions, 2 deletions
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index 691b583..a13989a 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -12765,7 +12765,12 @@ c_finish_return (location_t loc, tree retval, tree origtype, bool musttail_p) current_function_returns_value = 1; if (t == error_mark_node) - return NULL_TREE; + { + /* Suppress -Wreturn-type for this function. */ + if (warn_return_type) + suppress_warning (current_function_decl, OPT_Wreturn_type); + return NULL_TREE; + } save = in_late_binary_op; if (C_BOOLEAN_TYPE_P (TREE_TYPE (res)) diff --git a/gcc/testsuite/gcc.dg/Wreturn-mismatch-2.c b/gcc/testsuite/gcc.dg/Wreturn-mismatch-2.c index 0881102..5285226 100644 --- a/gcc/testsuite/gcc.dg/Wreturn-mismatch-2.c +++ b/gcc/testsuite/gcc.dg/Wreturn-mismatch-2.c @@ -37,5 +37,5 @@ int f7 (void) { return f1 (); /* { dg-error "void value not ignored as it ought to be" } */ -} /* { dg-warning "control reaches end of non-void\[^\n\r\]*-Wreturn-type" } */ +} /* { dg-bogus "control reaches end of non-void\[^\n\r\]*-Wreturn-type" } */ diff --git a/gcc/testsuite/gcc.dg/pr60440-1.c b/gcc/testsuite/gcc.dg/pr60440-1.c new file mode 100644 index 0000000..cd179cf --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr60440-1.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-Wreturn-type" } */ + +/* PR c/60440 */ +/* Don't warn for a missing return when there was an error + on the return stamtent. */ + +int f(int a) { + return a + b; /* { dg-error "undeclared" } */ +} /* { dg-bogus "control reaches end of non-void function" } */ |