* [C PATCH] Add -Wint-conversion option
@ 2014-06-30 18:32 Marek Polacek
2014-06-30 20:16 ` Joseph S. Myers
2014-06-30 20:52 ` Gerald Pfeifer
0 siblings, 2 replies; 7+ messages in thread
From: Marek Polacek @ 2014-06-30 18:32 UTC (permalink / raw)
To: GCC Patches; +Cc: Joseph S. Myers
Basically everything I wrote in the patch for -Wincompatible-pointer-types
applies here as well. A new option, -Wint-conversion (to be compatible
with clang), is added to allow more fine-grained control over the warnings.
I think we should print the types here as well, and moreover, we could hint the
user that & or * may be used to fix the code.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2014-06-30 Marek Polacek <polacek@redhat.com>
* doc/invoke.texi: Document -Wint-conversion.
c-family/
* c.opt (Wint-conversion): New option.
c/
* c-typeck.c (convert_for_assignment): Pass OPT_Wint_conversion
instead of 0 to WARN_FOR_ASSIGNMENT.
testsuite/
* gcc.dg/Wint-conversion.c: New test.
diff --git gcc/c-family/c.opt gcc/c-family/c.opt
index 6448b1b..c89040a 100644
--- gcc/c-family/c.opt
+++ gcc/c-family/c.opt
@@ -474,6 +474,10 @@ Winherited-variadic-ctor
C++ ObjC++ Var(warn_inh_var_ctor) Init(1) Warning
Warn about C++11 inheriting constructors when the base has a variadic constructor
+Wint-conversion
+C ObjC Var(warn_int_conversion) Init(1) Warning
+Warn about incompatible integer to pointer and pointer to integer conversions
+
Wint-to-pointer-cast
C ObjC C++ ObjC++ Var(warn_int_to_pointer_cast) Init(1) Warning
Warn when there is a cast to a pointer from an integer of a different size
diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
index fff26a3..35bfd14 100644
--- gcc/c/c-typeck.c
+++ gcc/c/c-typeck.c
@@ -6213,7 +6213,8 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
or one that results from arithmetic, even including
a cast to integer type. */
if (!null_pointer_constant)
- WARN_FOR_ASSIGNMENT (location, expr_loc, 0,
+ WARN_FOR_ASSIGNMENT (location, expr_loc,
+ OPT_Wint_conversion,
G_("passing argument %d of %qE makes "
"pointer from integer without a cast"),
G_("assignment makes pointer from integer "
@@ -6227,7 +6228,8 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
}
else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
{
- WARN_FOR_ASSIGNMENT (location, expr_loc, 0,
+ WARN_FOR_ASSIGNMENT (location, expr_loc,
+ OPT_Wint_conversion,
G_("passing argument %d of %qE makes integer "
"from pointer without a cast"),
G_("assignment makes integer from pointer "
diff --git gcc/doc/invoke.texi gcc/doc/invoke.texi
index dfae4f0..e6e71c0 100644
--- gcc/doc/invoke.texi
+++ gcc/doc/invoke.texi
@@ -253,7 +253,7 @@ Objective-C and Objective-C++ Dialects}.
-Wframe-larger-than=@var{len} -Wno-free-nonheap-object -Wjump-misses-init @gol
-Wignored-qualifiers -Wincompatible-pointer-types @gol
-Wimplicit -Wimplicit-function-declaration -Wimplicit-int @gol
--Winit-self -Winline @gol
+-Winit-self -Winline -Wno-int-conversion @gol
-Wno-int-to-pointer-cast -Wno-invalid-offsetof @gol
-Winvalid-pch -Wlarger-than=@var{len} -Wunsafe-loop-optimizations @gol
-Wlogical-op -Wlogical-not-parentheses -Wlong-long @gol
@@ -4213,6 +4213,12 @@ can be used to suppress such a warning.
Do not warn when there is a conversion between pointers that have incompatible
types.
+@item -Wno-int-conversion @r{(C and Objective-C only)}
+@opindex Wno-int-conversion
+@opindex Wint-conversion
+Do not warn about incompatible integer to pointer and pointer to integer
+conversions.
+
@item -Wno-div-by-zero
@opindex Wno-div-by-zero
@opindex Wdiv-by-zero
diff --git gcc/testsuite/gcc.dg/Wint-conversion.c gcc/testsuite/gcc.dg/Wint-conversion.c
index e69de29..1b7a03e 100644
--- gcc/testsuite/gcc.dg/Wint-conversion.c
+++ gcc/testsuite/gcc.dg/Wint-conversion.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-Wno-int-conversion" } */
+
+int fn1 (int *), *fn2 (int);
+
+int
+fn1 (int *p)
+{
+ int i = p;
+ i = p;
+ fn2 (p);
+ return p;
+}
+
+int *
+fn2 (int i)
+{
+ int *p = i;
+ p = i;
+ fn1 (i);
+ return i;
+}
Marek
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [C PATCH] Add -Wint-conversion option
2014-06-30 18:32 [C PATCH] Add -Wint-conversion option Marek Polacek
@ 2014-06-30 20:16 ` Joseph S. Myers
2014-07-01 8:48 ` Marek Polacek
2014-06-30 20:52 ` Gerald Pfeifer
1 sibling, 1 reply; 7+ messages in thread
From: Joseph S. Myers @ 2014-06-30 20:16 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches
On Mon, 30 Jun 2014, Marek Polacek wrote:
> Basically everything I wrote in the patch for -Wincompatible-pointer-types
> applies here as well. A new option, -Wint-conversion (to be compatible
> with clang), is added to allow more fine-grained control over the warnings.
> I think we should print the types here as well, and moreover, we could hint the
> user that & or * may be used to fix the code.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
OK with the documentation amended to make clear this is about *implicit*
conversions, not the cases covered by -Wno-int-to-pointer-cast and
-Wno-pointer-to-int-cast.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [C PATCH] Add -Wint-conversion option
2014-06-30 20:16 ` Joseph S. Myers
@ 2014-07-01 8:48 ` Marek Polacek
0 siblings, 0 replies; 7+ messages in thread
From: Marek Polacek @ 2014-07-01 8:48 UTC (permalink / raw)
To: Joseph S. Myers; +Cc: GCC Patches
On Mon, Jun 30, 2014 at 08:16:01PM +0000, Joseph S. Myers wrote:
> On Mon, 30 Jun 2014, Marek Polacek wrote:
>
> > Basically everything I wrote in the patch for -Wincompatible-pointer-types
> > applies here as well. A new option, -Wint-conversion (to be compatible
> > with clang), is added to allow more fine-grained control over the warnings.
> > I think we should print the types here as well, and moreover, we could hint the
> > user that & or * may be used to fix the code.
> >
> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> OK with the documentation amended to make clear this is about *implicit*
> conversions, not the cases covered by -Wno-int-to-pointer-cast and
> -Wno-pointer-to-int-cast.
Right, I'm applying the following then:
2014-07-01 Marek Polacek <polacek@redhat.com>
* doc/invoke.texi: Document -Wint-conversion.
c-family/
* c.opt (Wint-conversion): New option.
c/
* c-typeck.c (convert_for_assignment): Pass OPT_Wint_conversion
instead of 0 to WARN_FOR_ASSIGNMENT.
testsuite/
* gcc.dg/Wint-conversion.c: New test.
diff --git gcc/c-family/c.opt gcc/c-family/c.opt
index 6448b1b..c89040a 100644
--- gcc/c-family/c.opt
+++ gcc/c-family/c.opt
@@ -474,6 +474,10 @@ Winherited-variadic-ctor
C++ ObjC++ Var(warn_inh_var_ctor) Init(1) Warning
Warn about C++11 inheriting constructors when the base has a variadic constructor
+Wint-conversion
+C ObjC Var(warn_int_conversion) Init(1) Warning
+Warn about incompatible integer to pointer and pointer to integer conversions
+
Wint-to-pointer-cast
C ObjC C++ ObjC++ Var(warn_int_to_pointer_cast) Init(1) Warning
Warn when there is a cast to a pointer from an integer of a different size
diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
index fff26a3..35bfd14 100644
--- gcc/c/c-typeck.c
+++ gcc/c/c-typeck.c
@@ -6213,7 +6213,8 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
or one that results from arithmetic, even including
a cast to integer type. */
if (!null_pointer_constant)
- WARN_FOR_ASSIGNMENT (location, expr_loc, 0,
+ WARN_FOR_ASSIGNMENT (location, expr_loc,
+ OPT_Wint_conversion,
G_("passing argument %d of %qE makes "
"pointer from integer without a cast"),
G_("assignment makes pointer from integer "
@@ -6227,7 +6228,8 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
}
else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
{
- WARN_FOR_ASSIGNMENT (location, expr_loc, 0,
+ WARN_FOR_ASSIGNMENT (location, expr_loc,
+ OPT_Wint_conversion,
G_("passing argument %d of %qE makes integer "
"from pointer without a cast"),
G_("assignment makes integer from pointer "
diff --git gcc/doc/invoke.texi gcc/doc/invoke.texi
index 409fa17..b1f6f4b 100644
--- gcc/doc/invoke.texi
+++ gcc/doc/invoke.texi
@@ -253,7 +253,7 @@ Objective-C and Objective-C++ Dialects}.
-Wframe-larger-than=@var{len} -Wno-free-nonheap-object -Wjump-misses-init @gol
-Wignored-qualifiers -Wincompatible-pointer-types @gol
-Wimplicit -Wimplicit-function-declaration -Wimplicit-int @gol
--Winit-self -Winline @gol
+-Winit-self -Winline -Wno-int-conversion @gol
-Wno-int-to-pointer-cast -Wno-invalid-offsetof @gol
-Winvalid-pch -Wlarger-than=@var{len} -Wunsafe-loop-optimizations @gol
-Wlogical-op -Wlogical-not-parentheses -Wlong-long @gol
@@ -4214,6 +4214,14 @@ Do not warn when there is a conversion between pointers that have incompatible
types. This warning is for cases not covered by @option{-Wno-pointer-sign},
which warns for pointer argument passing or assignment with different signedness
+@item -Wno-int-conversion @r{(C and Objective-C only)}
+@opindex Wno-int-conversion
+@opindex Wint-conversion
+Do not warn about incompatible integer to pointer and pointer to integer
+conversions. This warning is about implicit conversions; for explicit
+conversions the warnings @option{-Wno-int-to-pointer-cast} and
+@option{-Wno-pointer-to-int-cast} may be used.
+
@item -Wno-div-by-zero
@opindex Wno-div-by-zero
@opindex Wdiv-by-zero
diff --git gcc/testsuite/gcc.dg/Wint-conversion.c gcc/testsuite/gcc.dg/Wint-conversion.c
index e69de29..1b7a03e 100644
--- gcc/testsuite/gcc.dg/Wint-conversion.c
+++ gcc/testsuite/gcc.dg/Wint-conversion.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-Wno-int-conversion" } */
+
+int fn1 (int *), *fn2 (int);
+
+int
+fn1 (int *p)
+{
+ int i = p;
+ i = p;
+ fn2 (p);
+ return p;
+}
+
+int *
+fn2 (int i)
+{
+ int *p = i;
+ p = i;
+ fn1 (i);
+ return i;
+}
Marek
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [C PATCH] Add -Wint-conversion option
2014-06-30 18:32 [C PATCH] Add -Wint-conversion option Marek Polacek
2014-06-30 20:16 ` Joseph S. Myers
@ 2014-06-30 20:52 ` Gerald Pfeifer
2014-06-30 20:54 ` Jakub Jelinek
1 sibling, 1 reply; 7+ messages in thread
From: Gerald Pfeifer @ 2014-06-30 20:52 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches, Joseph S. Myers
Can you please add this and the other one to gcc-4.10/changes.html?
I can provide help if you need any.
Gerald
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [C PATCH] Add -Wint-conversion option
2014-06-30 20:52 ` Gerald Pfeifer
@ 2014-06-30 20:54 ` Jakub Jelinek
2014-06-30 21:08 ` Gerald Pfeifer
0 siblings, 1 reply; 7+ messages in thread
From: Jakub Jelinek @ 2014-06-30 20:54 UTC (permalink / raw)
To: Gerald Pfeifer; +Cc: Marek Polacek, GCC Patches, Joseph S. Myers
On Mon, Jun 30, 2014 at 10:51:59PM +0200, Gerald Pfeifer wrote:
> Can you please add this and the other one to gcc-4.10/changes.html?
>
> I can provide help if you need any.
We don't have gcc-4.10/ directory, because the version of the next release
is still to be decided (hopefully at Cauldron next month).
Jakub
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [C PATCH] Add -Wint-conversion option
2014-06-30 20:54 ` Jakub Jelinek
@ 2014-06-30 21:08 ` Gerald Pfeifer
2014-07-01 9:34 ` Marek Polacek
0 siblings, 1 reply; 7+ messages in thread
From: Gerald Pfeifer @ 2014-06-30 21:08 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Marek Polacek, gcc-patches, Joseph S. Myers
On Mon, 30 Jun 2014, Jakub Jelinek wrote:
> We don't have gcc-4.10/ directory, because the version of the next
> release is still to be decided (hopefully at Cauldron next month).
I'm a bit worried we'll miss entries in the meantime.
Can we use gcc-4.10/ for now and rename later if we go for
GCC V or whatever? :-)
Gerald
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [C PATCH] Add -Wint-conversion option
2014-06-30 21:08 ` Gerald Pfeifer
@ 2014-07-01 9:34 ` Marek Polacek
0 siblings, 0 replies; 7+ messages in thread
From: Marek Polacek @ 2014-07-01 9:34 UTC (permalink / raw)
To: Gerald Pfeifer; +Cc: Jakub Jelinek, gcc-patches, Joseph S. Myers
On Mon, Jun 30, 2014 at 11:07:57PM +0200, Gerald Pfeifer wrote:
> On Mon, 30 Jun 2014, Jakub Jelinek wrote:
> > We don't have gcc-4.10/ directory, because the version of the next
> > release is still to be decided (hopefully at Cauldron next month).
>
> I'm a bit worried we'll miss entries in the meantime.
>
> Can we use gcc-4.10/ for now and rename later if we go for
> GCC V or whatever? :-)
Well, looks like I can't do much right now, so I'll go through my C FE
changes and new ubsan features after we have some actual changes.html,
and post a patch then...
Marek
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-07-01 9:34 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-30 18:32 [C PATCH] Add -Wint-conversion option Marek Polacek
2014-06-30 20:16 ` Joseph S. Myers
2014-07-01 8:48 ` Marek Polacek
2014-06-30 20:52 ` Gerald Pfeifer
2014-06-30 20:54 ` Jakub Jelinek
2014-06-30 21:08 ` Gerald Pfeifer
2014-07-01 9:34 ` Marek Polacek
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).