diff options
author | Florian Weimer <fweimer@redhat.com> | 2023-12-01 08:10:13 +0100 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2023-12-01 08:10:13 +0100 |
commit | 9715c545d33b3a32ddc1ae817ba9356ade1fb9df (patch) | |
tree | ce3c24917ac2c32b20fab88fe6743945b803bcc4 /gcc/c | |
parent | 4ecfa6c4a9df19b364cbdf6d9de5f0b98c22bd8f (diff) | |
download | gcc-9715c545d33b3a32ddc1ae817ba9356ade1fb9df.zip gcc-9715c545d33b3a32ddc1ae817ba9356ade1fb9df.tar.gz gcc-9715c545d33b3a32ddc1ae817ba9356ade1fb9df.tar.bz2 |
c: Turn -Wincompatible-pointer-types into a permerror
The change to build_conditional_expr drops the downgrade
from a pedwarn to warning for builtins for C99 and later
language dialects. It remains a warning in C89 mode (not
a permerror), as the -std=gnu89 -fno-permissive test shows.
gcc/
* doc/invoke.texi (Warning Options): Document changes.
gcc/c/
PR c/96284
* c-typeck.cc (build_conditional_expr): Upgrade most pointer
type mismatches to a permerror.
(convert_for_assignment): Use permerror_opt and
permerror_init for OPT_Wincompatible_pointer_types warnings.
gcc/testsuite/
* gcc.dg/permerror-default.c (incompatible_pointer_types):
Expect new permerror.
* gcc.dg/permerror-gnu89-nopermissive.c
(incompatible_pointer_types): Likewise.
* gcc.dg/permerror-pedantic.c (incompatible_pointer_types):
Likewise.
* gcc.dg/permerror-system.c: Likewise.
* gcc.dg/Wincompatible-pointer-types-2.c: Compile with
-fpermissive due to expected errors.
* gcc.dg/Wincompatible-pointer-types-5.c: New test. Copied
from gcc.dg/Wincompatible-pointer-types-2.c. Expect errors.
* gcc.dg/anon-struct-11.c: Compile with -fpermissive
due to expected errors.
* gcc.dg/anon-struct-11a.c: New test. Copied from
gcc.dg/anon-struct-11.c. Expect errors.
* gcc.dg/anon-struct-13.c: Compile with -fpermissive
due to expected errors.
* gcc.dg/anon-struct-13a.c: New test. Copied from
gcc.dg/anon-struct-13.c. Expect errors.
* gcc.dg/builtin-arith-overflow-4.c: Compile with -fpermissive
due to expected errors.
* gcc.dg/builtin-arith-overflow-4a.c: New test. Copied from
gcc.dg/builtin-arith-overflow-4.c. Expect errors.
* gcc.dg/c23-qual-4.c: Expect -Wincompatible-pointer-types errors.
* gcc.dg/dfp/composite-type.c: Compile with -fpermissive
due to expected errors.
* gcc.dg/dfp/composite-type-2.c: New test. Copied from
gcc.dg/dfp/composite-type.c. Expect errors.
* gcc.dg/diag-aka-1.c: Compile with -fpermissive
due to expected errors.
* gcc.dg/diag-aka-1a.c: New test. Copied from
gcc.dg/diag-aka-1a.c. Expect errors.
* gcc.dg/enum-compat-1.c: Compile with -fpermissive
due to expected errors.
* gcc.dg/enum-compat-2.c: New test. Copied from
gcc.dg/enum-compat-1.c. Expect errors.
* gcc.dg/func-ptr-conv-1.c: Compile with -fpermissive
due to expected errors.
* gcc.dg/func-ptr-conv-2.c: New test. Copied from
gcc.dg/func-ptr-conv-1.c. Expect errors.
* gcc.dg/init-bad-7.c: Compile with -fpermissive
due to expected errors.
* gcc.dg/init-bad-7a.c: New test. Copied from gcc.dg/init-bad-7.c.
Expect errors.
* gcc.dg/noncompile/incomplete-3.c (foo): Expect
-Wincompatible-pointer-types error.
* gcc.dg/param-type-mismatch-2.c (test8): Likewise.
* gcc.dg/pointer-array-atomic.c: Compile with -fpermissive
due to expected errors.
* gcc.dg/pointer-array-atomic-2.c: New test. Copied from
gcc.dg/pointer-array-atomic.c. Expect errors.
* gcc.dg/pointer-array-quals-1.c (test): Expect
-Wincompatible-pointer-types errors.
* gcc.dg/transparent-union-1.c: Compile with -fpermissive
due to expected errors.
* gcc.dg/transparent-union-1a.c: New test. Copied from
gcc.dg/transparent-union-1.c. Expect errors.
* gcc.target/aarch64/acle/memtag_2a.c
(test_memtag_warning_return_qualifier): Expect additional
errors.
* gcc.target/aarch64/sve/acle/general-c/load_2.c (f1): Likewise.
* gcc.target/aarch64/sve/acle/general-c/load_ext_gather_offset_1.c
(f1): Likewise.
* gcc.target/aarch64/sve/acle/general-c/load_ext_gather_offset_2.c
(f1): Likewise.
* gcc.target/aarch64/sve/acle/general-c/load_ext_gather_offset_3.c
(f1): Likewise.
* gcc.target/aarch64/sve/acle/general-c/load_ext_gather_offset_4.c
(f1): Likewise.
* gcc.target/aarch64/sve/acle/general-c/load_ext_gather_offset_5.c
(f1): Likewise.
* gcc.target/aarch64/sve/acle/general-c/load_ext_gather_offset_restricted_1.c
(f1): Likewise.
* gcc.target/aarch64/sve/acle/general-c/load_ext_gather_offset_restricted_2.c
(f1): Likewise.
* gcc.target/aarch64/sve/acle/general-c/load_ext_gather_offset_restricted_3.c
(f1): Likewise.
* gcc.target/aarch64/sve/acle/general-c/load_ext_gather_offset_restricted_4.c
(f1): Likewise.
* gcc.target/aarch64/sve/acle/general-c/sizeless-1.c (f1): Likewise.
* gcc.target/aarch64/sve/acle/general-c/sizeless-2.c (f1): Likewise.
* gcc.target/aarch64/sve/acle/general-c/store_1.c (f1): Likewise.
* gcc.target/aarch64/sve/acle/general-c/store_2.c (f1): Likewise.
* gcc.target/aarch64/sve/acle/general-c/store_scatter_index_1.c
(f1): Likewise.
* gcc.target/aarch64/sve/acle/general-c/store_scatter_index_restricted_1.c
(f1): Likewise.
* gcc.target/aarch64/sve/acle/general-c/store_scatter_offset_2.c
(f1): Likewise.
* gcc.target/aarch64/sve/acle/general-c/store_scatter_offset_restricted_1.c
(f1): Likewise.
* gcc.target/aarch64/sve/acle/general/attributes_7.c
(f1): Likewise.
* gcc.target/i386/sse2-bfloat16-scalar-typecheck.c (footest):
Expect -Wincompatible-pointer-types errors.
* gcc.target/i386/vect-bfloat16-typecheck_1.c (footest): Likewise.
* gcc.target/i386/vect-bfloat16-typecheck_2.c (footest): Likewise.
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/c-typeck.cc | 62 |
1 files changed, 35 insertions, 27 deletions
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index b03532a..a6edbc85 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -5463,8 +5463,15 @@ build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp, else { int qual = ENCODE_QUAL_ADDR_SPACE (as_common); - if (emit_diagnostic (bltin1 && bltin2 ? DK_WARNING : DK_PEDWARN, - colon_loc, OPT_Wincompatible_pointer_types, + diagnostic_t kind = DK_PERMERROR; + if (!flag_isoc99) + /* This downgrade to a warning ensures that -std=gnu89 + -pedantic-errors does not flag these mismatches between + builtins as errors (as DK_PERMERROR would). ISO C99 + and later do not have implicit function declarations, + so the mismatch cannot occur naturally there. */ + kind = bltin1 && bltin2 ? DK_WARNING : DK_PEDWARN; + if (emit_diagnostic (kind, colon_loc, OPT_Wincompatible_pointer_types, "pointer type mismatch " "in conditional expression")) { @@ -7602,46 +7609,47 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type, auto_diagnostic_group d; range_label_for_type_mismatch rhs_label (rhstype, type); gcc_rich_location richloc (expr_loc, &rhs_label); - if (pedwarn (&richloc, OPT_Wincompatible_pointer_types, - "passing argument %d of %qE from incompatible " - "pointer type", parmnum, rname)) + if (permerror_opt (&richloc, OPT_Wincompatible_pointer_types, + "passing argument %d of %qE from " + "incompatible pointer type", + parmnum, rname)) inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype); } break; case ic_assign: if (bltin) - pedwarn (location, OPT_Wincompatible_pointer_types, - "assignment to %qT from pointer to " - "%qD with incompatible type %qT", - type, bltin, rhstype); + permerror_opt (location, OPT_Wincompatible_pointer_types, + "assignment to %qT from pointer to " + "%qD with incompatible type %qT", + type, bltin, rhstype); else - pedwarn (location, OPT_Wincompatible_pointer_types, - "assignment to %qT from incompatible pointer type %qT", - type, rhstype); + permerror_opt (location, OPT_Wincompatible_pointer_types, + "assignment to %qT from incompatible pointer " + "type %qT", type, rhstype); break; case ic_init: case ic_init_const: if (bltin) - pedwarn_init (location, OPT_Wincompatible_pointer_types, - "initialization of %qT from pointer to " - "%qD with incompatible type %qT", - type, bltin, rhstype); + permerror_init (location, OPT_Wincompatible_pointer_types, + "initialization of %qT from pointer to " + "%qD with incompatible type %qT", + type, bltin, rhstype); else - pedwarn_init (location, OPT_Wincompatible_pointer_types, - "initialization of %qT from incompatible " - "pointer type %qT", - type, rhstype); + permerror_init (location, OPT_Wincompatible_pointer_types, + "initialization of %qT from incompatible " + "pointer type %qT", + type, rhstype); break; case ic_return: if (bltin) - pedwarn (location, OPT_Wincompatible_pointer_types, - "returning pointer to %qD of type %qT from " - "a function with incompatible type %qT", - bltin, rhstype, type); + permerror_opt (location, OPT_Wincompatible_pointer_types, + "returning pointer to %qD of type %qT from " + "a function with incompatible type %qT", + bltin, rhstype, type); else - pedwarn (location, OPT_Wincompatible_pointer_types, - "returning %qT from a function with incompatible " - "return type %qT", rhstype, type); + permerror_opt (location, OPT_Wincompatible_pointer_types, + "returning %qT from a function with " + "incompatible return type %qT", rhstype, type); break; default: gcc_unreachable (); |