public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/106416] New: -Wint-conversion should be an error, not a pedwarn
@ 2022-07-22 22:55 redi at gcc dot gnu.org
2022-07-25 14:16 ` [Bug c/106416] " mpolacek at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2022-07-22 22:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106416
Bug ID: 106416
Summary: -Wint-conversion should be an error, not a pedwarn
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
Aaron Ballman and I discussed this recently, and now he just made this an error
in Clang, with the following justification:
Clang has traditionally allowed C programs to implicitly convert
integers to pointers and pointers to integers, despite it not being
valid to do so except under special circumstances (like converting the
integer 0, which is the null pointer constant, to a pointer). In C89,
this would result in undefined behavior per 3.3.4, and in C99 this rule
was strengthened to be a constraint violation instead. Constraint
violations are most often handled as an error.
This patch changes the warning to default to an error in all C modes
(it is already an error in C++). This gives us better security posture
by calling out potential programmer mistakes in code but still allows
users who need this behavior to use -Wno-error=int-conversion to retain
the warning behavior, or -Wno-int-conversion to silence the diagnostic
entirely.
GCC should do the same, for the same reasons. It's an error, and should not be
accepted by default in 2022.
I tried to look at how to change gcc/c/c-typeck.cc so that the pedwarns in
convert_for_assignment are errors by default, unless you use
-Wno-error=int-conversion, but I'm not sure how to make that happen.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/106416] -Wint-conversion should be an error, not a pedwarn
2022-07-22 22:55 [Bug c/106416] New: -Wint-conversion should be an error, not a pedwarn redi at gcc dot gnu.org
@ 2022-07-25 14:16 ` mpolacek at gcc dot gnu.org
2022-07-27 15:43 ` fw at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-07-25 14:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106416
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
CC| |mpolacek at gcc dot gnu.org
Last reconfirmed| |2022-07-25
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/106416] -Wint-conversion should be an error, not a pedwarn
2022-07-22 22:55 [Bug c/106416] New: -Wint-conversion should be an error, not a pedwarn redi at gcc dot gnu.org
2022-07-25 14:16 ` [Bug c/106416] " mpolacek at gcc dot gnu.org
@ 2022-07-27 15:43 ` fw at gcc dot gnu.org
2022-07-27 20:01 ` redi at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: fw at gcc dot gnu.org @ 2022-07-27 15:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106416
Florian Weimer <fw at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |fw at gcc dot gnu.org
--- Comment #1 from Florian Weimer <fw at gcc dot gnu.org> ---
This will likely need the same preparatory treatment as rejecting implicit
function declarations (bug 91092), for the same reason: Without some care
upfront, introducing the new compiler error will change configure test results
in fully consistent ways, resulting in silently dropped features.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/106416] -Wint-conversion should be an error, not a pedwarn
2022-07-22 22:55 [Bug c/106416] New: -Wint-conversion should be an error, not a pedwarn redi at gcc dot gnu.org
2022-07-25 14:16 ` [Bug c/106416] " mpolacek at gcc dot gnu.org
2022-07-27 15:43 ` fw at gcc dot gnu.org
@ 2022-07-27 20:01 ` redi at gcc dot gnu.org
2022-07-31 8:44 ` dcb314 at hotmail dot com
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2022-07-27 20:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106416
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=91092
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Yes, definitely in the same category.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/106416] -Wint-conversion should be an error, not a pedwarn
2022-07-22 22:55 [Bug c/106416] New: -Wint-conversion should be an error, not a pedwarn redi at gcc dot gnu.org
` (2 preceding siblings ...)
2022-07-27 20:01 ` redi at gcc dot gnu.org
@ 2022-07-31 8:44 ` dcb314 at hotmail dot com
2022-07-31 8:50 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: dcb314 at hotmail dot com @ 2022-07-31 8:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106416
David Binderman <dcb314 at hotmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dcb314 at hotmail dot com
--- Comment #3 from David Binderman <dcb314 at hotmail dot com> ---
Interestingly, for this C code:
extern void g( int);
void f( int *p)
{
int a = p;
int b = (int *) p;
g( a);
g( b);
}
gcc does this:
$ /home/dcb/gcc/results/bin/gcc -c -std=c2x jul31a.c
jul31a.c: In function ‘f’:
jul31a.c:6:17: warning: initialization of ‘int’ from ‘int *’ makes integer from
pointer without a cast [-Wint-conversion]
6 | int a = p;
| ^
jul31a.c:7:17: warning: initialization of ‘int’ from ‘int *’ makes integer from
pointer without a cast [-Wint-conversion]
7 | int b = (int *) p;
| ^
$
The second warning looks wrong to me.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/106416] -Wint-conversion should be an error, not a pedwarn
2022-07-22 22:55 [Bug c/106416] New: -Wint-conversion should be an error, not a pedwarn redi at gcc dot gnu.org
` (3 preceding siblings ...)
2022-07-31 8:44 ` dcb314 at hotmail dot com
@ 2022-07-31 8:50 ` pinskia at gcc dot gnu.org
2022-07-31 8:54 ` dcb314 at hotmail dot com
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-07-31 8:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106416
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> The second warning looks wrong to me.
It is right. Try doing the cast to int instead of a pointer (to int).
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/106416] -Wint-conversion should be an error, not a pedwarn
2022-07-22 22:55 [Bug c/106416] New: -Wint-conversion should be an error, not a pedwarn redi at gcc dot gnu.org
` (4 preceding siblings ...)
2022-07-31 8:50 ` pinskia at gcc dot gnu.org
@ 2022-07-31 8:54 ` dcb314 at hotmail dot com
2023-12-01 7:12 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: dcb314 at hotmail dot com @ 2022-07-31 8:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106416
--- Comment #5 from David Binderman <dcb314 at hotmail dot com> ---
(In reply to Andrew Pinski from comment #4)
> > The second warning looks wrong to me.
>
> It is right. Try doing the cast to int instead of a pointer (to int).
Thanks for the correction. gcc does the right thing.
New warning output is:
$ /home/dcb/gcc/results/bin/gcc -c -std=c2x bug834.c
bug834.c: In function ‘f’:
bug834.c:6:17: warning: initialization of ‘int’ from ‘int *’ makes integer from
pointer without a cast [-Wint-conversion]
6 | int a = p;
| ^
bug834.c:7:17: warning: cast from pointer to integer of different size
[-Wpointer-to-int-cast]
7 | int b = (int) p;
| ^
$
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/106416] -Wint-conversion should be an error, not a pedwarn
2022-07-22 22:55 [Bug c/106416] New: -Wint-conversion should be an error, not a pedwarn redi at gcc dot gnu.org
` (5 preceding siblings ...)
2022-07-31 8:54 ` dcb314 at hotmail dot com
@ 2023-12-01 7:12 ` cvs-commit at gcc dot gnu.org
2023-12-01 7:15 ` fw at gcc dot gnu.org
2023-12-01 8:20 ` sjames at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-01 7:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106416
--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Florian Weimer <fw@gcc.gnu.org>:
https://gcc.gnu.org/g:2c3db94d9fd07681f8806dae93d555779ff4dfb1
commit r14-6032-g2c3db94d9fd07681f8806dae93d555779ff4dfb1
Author: Florian Weimer <fweimer@redhat.com>
Date: Fri Dec 1 08:10:12 2023 +0100
c: Turn int-conversion warnings into permerrors
gcc/
* doc/invoke.texi (Warning Options): Document changes.
gcc/c/
PR c/96284
PR c/106416
* c-typeck.cc (build_conditional_expr): Use permerror_opt for
pointer/integer type mismatches, based on -Wint-conversion.
(pedwarn_permerror_init, permerror_init): New function.
(pedwarn_init): Call pedwarn_permerror_init.
(convert_for_assignment): Use permerror_opt and
permerror_init for -Wint-conversion warnings.
gcc/testsuite/
* gcc.dg/permerror-default.c (int_conversion_1)
(int_conversion_2): Expect the new permerrors.
* gcc.dg/permerror-gnu89-nopermissive.c (int_conversion_1)
(int_conversion_2): Likewise.
* gcc.dg/permerror-system.c: Likewise.
* c-c++-common/pr77624-1.c (foo, bar): Expect
error instead of warning.
* gcc.dg/Wint-conversion-2.c: Compile with -fpermissive due
to expected int-conversion warning.
* gcc.dg/Wint-conversion-3.c: Likewise.
* gcc.dg/Wint-conversion-4.c: New test. Based on
gcc.dg/Wint-conversion-3.c. Expect int-conversion errors.
* gcc.dg/assign-warn-1.c: Compile with -fpermissive.
* gcc.dg/assign-warn-4.c: New file. Extracted from
assign-warn1.c. Expect int-conversion errors.
* gcc.dg/diagnostic-types-1.c: Compile with -fpermissive.
* gcc.dg/diagnostic-types-2.c: New file. Extracted from
gcc.dg/diagnostic-types-1.c. Expect some errors instead of
warnings.
* gcc.dg/gomp/pr35738.c: Compile with -fpermissive due to
expected int-conversion error.
* gcc.dg/gomp/pr35738-2.c: New test. Based on
gcc.dg/gomp/pr35738.c. Expect int-converison errors.
* gcc.dg/init-excess-3.c: Expect int-converison errors.
* gcc.dg/overflow-warn-1.c: Likewise.
* gcc.dg/overflow-warn-3.c: Likewise.
* gcc.dg/param-type-mismatch.c: Compile with -fpermissive.
* gcc.dg/param-type-mismatch-2.c: New test. Copied from
gcc.dg/param-type-mismatch.c. Expect errors.
* gcc.dg/pr61162-2.c: Compile with -fpermissive.
* gcc.dg/pr61162-3.c: New test. Extracted from
gcc.dg/pr61162-2.c. Expect int-conversion errors.
* gcc.dg/spec-barrier-3.c: Use -fpermissive due to expected
int-conversion error.
* gcc.dg/spec-barrier-3a.c: New test. Based on
gcc.dg/spec-barrier-3.c. Expect int-conversion errors.
* gcc.target/aarch64/acle/memtag_2.c: Use -fpermissive due to
expected
int-conversion error.
* gcc.target/aarch64/acle/memtag_2a.c: New test. Copied from
gcc.target/aarch64/acle/memtag_2.c. Expect error.
* gcc.target/aarch64/sve/acle/general-c/load_3.c (f1): Expect
error.
* 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.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/106416] -Wint-conversion should be an error, not a pedwarn
2022-07-22 22:55 [Bug c/106416] New: -Wint-conversion should be an error, not a pedwarn redi at gcc dot gnu.org
` (6 preceding siblings ...)
2023-12-01 7:12 ` cvs-commit at gcc dot gnu.org
@ 2023-12-01 7:15 ` fw at gcc dot gnu.org
2023-12-01 8:20 ` sjames at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: fw at gcc dot gnu.org @ 2023-12-01 7:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106416
Florian Weimer <fw at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|NEW |RESOLVED
--- Comment #7 from Florian Weimer <fw at gcc dot gnu.org> ---
Fixed for GCC 14.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/106416] -Wint-conversion should be an error, not a pedwarn
2022-07-22 22:55 [Bug c/106416] New: -Wint-conversion should be an error, not a pedwarn redi at gcc dot gnu.org
` (7 preceding siblings ...)
2023-12-01 7:15 ` fw at gcc dot gnu.org
@ 2023-12-01 8:20 ` sjames at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: sjames at gcc dot gnu.org @ 2023-12-01 8:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106416
Sam James <sjames at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |14.0
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-12-01 8:20 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-22 22:55 [Bug c/106416] New: -Wint-conversion should be an error, not a pedwarn redi at gcc dot gnu.org
2022-07-25 14:16 ` [Bug c/106416] " mpolacek at gcc dot gnu.org
2022-07-27 15:43 ` fw at gcc dot gnu.org
2022-07-27 20:01 ` redi at gcc dot gnu.org
2022-07-31 8:44 ` dcb314 at hotmail dot com
2022-07-31 8:50 ` pinskia at gcc dot gnu.org
2022-07-31 8:54 ` dcb314 at hotmail dot com
2023-12-01 7:12 ` cvs-commit at gcc dot gnu.org
2023-12-01 7:15 ` fw at gcc dot gnu.org
2023-12-01 8:20 ` sjames at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).