public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] disable -Walloc-size-larger-than and -Wstringop-overflow for non-C front ends (PR 80545)
@ 2017-04-29  2:02 Martin Sebor
  2017-05-05  4:21 ` Jeff Law
  0 siblings, 1 reply; 5+ messages in thread
From: Martin Sebor @ 2017-04-29  2:02 UTC (permalink / raw)
  To: Gcc Patch List

[-- Attachment #1: Type: text/plain, Size: 636 bytes --]

The two options were included in -Wall and enabled for all front
ends but only made to be recognized by the driver for the C family
of compilers.  That made it impossible to suppress those warnings
when compiling code for those other front ends (like Fortran).

The attached patch adjusts the warnings so that they are only
enabled for the C family of front ends and not for any others,
as per Richard's suggestion.  (The other solution would have
been to make the warnings available to all front ends.  Since
non-C languages don't have a way of calling the affected
functions -- or do they? -- this is probably not necessary.)

Martin

[-- Attachment #2: gcc-80545.diff --]
[-- Type: text/x-patch, Size: 1268 bytes --]

PR driver/80545 - option -Wstringop-overflow not recognized by Fortran

gcc/c-family/ChangeLog:

	PR driver/80545
	* c.opt (-Walloc-size-larger-than, -Wstringop-overflow): Enable
	and make available for the C family only.

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 6ecbfca..9ad2f6e 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -304,7 +304,7 @@ C ObjC C++ ObjC++ Var(warn_alloca) Warning
 Warn on any use of alloca.
 
 Walloc-size-larger-than=
-C ObjC C++ ObjC++ Var(warn_alloc_size_limit) Warning Joined
+C ObjC C++ ObjC++ Var(warn_alloc_size_limit) Warning Joined LangEnabledBy(C ObjC C++ ObjC++, Wall)
 -Walloc-size-larger-than=<bytes> Warn for calls to allocation functions that
 attempt to allocate objects larger than the specified number of bytes.
 
@@ -716,7 +716,7 @@ Warn about buffer overflow in string manipulation functions like memcpy
 and strcpy.
 
 Wstringop-overflow=
-C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_stringop_overflow) Init(2) Warning
+C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_stringop_overflow) Warning LangEnabledBy(C ObjC C++ ObjC++, Wall, 2, 0)
 Under the control of Object Size type, warn about buffer overflow in string
 manipulation functions like memcpy and strcpy.
 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] disable -Walloc-size-larger-than and -Wstringop-overflow for non-C front ends (PR 80545)
  2017-04-29  2:02 [PATCH] disable -Walloc-size-larger-than and -Wstringop-overflow for non-C front ends (PR 80545) Martin Sebor
@ 2017-05-05  4:21 ` Jeff Law
  2017-05-08 14:33   ` Martin Sebor
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff Law @ 2017-05-05  4:21 UTC (permalink / raw)
  To: Martin Sebor, Gcc Patch List

On 04/28/2017 04:02 PM, Martin Sebor wrote:
> The two options were included in -Wall and enabled for all front
> ends but only made to be recognized by the driver for the C family
> of compilers.  That made it impossible to suppress those warnings
> when compiling code for those other front ends (like Fortran).
> 
> The attached patch adjusts the warnings so that they are only
> enabled for the C family of front ends and not for any others,
> as per Richard's suggestion.  (The other solution would have
> been to make the warnings available to all front ends.  Since
> non-C languages don't have a way of calling the affected
> functions -- or do they? -- this is probably not necessary.)
> 
> Martin
> 
> gcc-80545.diff
> 
> 
> PR driver/80545 - option -Wstringop-overflow not recognized by Fortran
> 
> gcc/c-family/ChangeLog:
> 
> 	PR driver/80545
> 	* c.opt (-Walloc-size-larger-than, -Wstringop-overflow): Enable
> 	and make available for the C family only.
OK.
jeff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] disable -Walloc-size-larger-than and -Wstringop-overflow for non-C front ends (PR 80545)
  2017-05-05  4:21 ` Jeff Law
@ 2017-05-08 14:33   ` Martin Sebor
  2017-05-09  9:28     ` Richard Biener
  0 siblings, 1 reply; 5+ messages in thread
From: Martin Sebor @ 2017-05-08 14:33 UTC (permalink / raw)
  To: Jeff Law, Gcc Patch List

On 05/04/2017 10:13 PM, Jeff Law wrote:
> On 04/28/2017 04:02 PM, Martin Sebor wrote:
>> The two options were included in -Wall and enabled for all front
>> ends but only made to be recognized by the driver for the C family
>> of compilers.  That made it impossible to suppress those warnings
>> when compiling code for those other front ends (like Fortran).
>>
>> The attached patch adjusts the warnings so that they are only
>> enabled for the C family of front ends and not for any others,
>> as per Richard's suggestion.  (The other solution would have
>> been to make the warnings available to all front ends.  Since
>> non-C languages don't have a way of calling the affected
>> functions -- or do they? -- this is probably not necessary.)
>>
>> Martin
>>
>> gcc-80545.diff
>>
>>
>> PR driver/80545 - option -Wstringop-overflow not recognized by Fortran
>>
>> gcc/c-family/ChangeLog:
>>
>>     PR driver/80545
>>     * c.opt (-Walloc-size-larger-than, -Wstringop-overflow): Enable
>>     and make available for the C family only.
> OK.
> jeff

It turns out that this is not the right fix.  I overlooked that
-Wstringop-overflow is meant to be enabled by default and while
removing the Init(2) bit and replacing it with LangEnabledBy (C
ObjC C++ ObjC++, Wall, 2, 0) suppresses the warning in Fortran
it also disables it by default in C/C++ unless -Wall is used.

By my reading of the Option properties part of the GCC Internals
manual there is no way to initialize a warning to on by default
while making it available only in a subset of languages.  The
only way I can think of is to initialize it in the .opt file to
something like -1 and then change it at some point to 2 somewhere
in the C/C++ front ends.  That seems pretty cumbersome.  Am I
missing some trick?

Martin

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] disable -Walloc-size-larger-than and -Wstringop-overflow for non-C front ends (PR 80545)
  2017-05-08 14:33   ` Martin Sebor
@ 2017-05-09  9:28     ` Richard Biener
  2017-05-09 14:14       ` Martin Sebor
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Biener @ 2017-05-09  9:28 UTC (permalink / raw)
  To: Martin Sebor; +Cc: Jeff Law, Gcc Patch List

On Mon, May 8, 2017 at 4:31 PM, Martin Sebor <msebor@gmail.com> wrote:
> On 05/04/2017 10:13 PM, Jeff Law wrote:
>>
>> On 04/28/2017 04:02 PM, Martin Sebor wrote:
>>>
>>> The two options were included in -Wall and enabled for all front
>>> ends but only made to be recognized by the driver for the C family
>>> of compilers.  That made it impossible to suppress those warnings
>>> when compiling code for those other front ends (like Fortran).
>>>
>>> The attached patch adjusts the warnings so that they are only
>>> enabled for the C family of front ends and not for any others,
>>> as per Richard's suggestion.  (The other solution would have
>>> been to make the warnings available to all front ends.  Since
>>> non-C languages don't have a way of calling the affected
>>> functions -- or do they? -- this is probably not necessary.)
>>>
>>> Martin
>>>
>>> gcc-80545.diff
>>>
>>>
>>> PR driver/80545 - option -Wstringop-overflow not recognized by Fortran
>>>
>>> gcc/c-family/ChangeLog:
>>>
>>>     PR driver/80545
>>>     * c.opt (-Walloc-size-larger-than, -Wstringop-overflow): Enable
>>>     and make available for the C family only.
>>
>> OK.
>> jeff
>
>
> It turns out that this is not the right fix.  I overlooked that
> -Wstringop-overflow is meant to be enabled by default and while
> removing the Init(2) bit and replacing it with LangEnabledBy (C
> ObjC C++ ObjC++, Wall, 2, 0) suppresses the warning in Fortran
> it also disables it by default in C/C++ unless -Wall is used.
>
> By my reading of the Option properties part of the GCC Internals
> manual there is no way to initialize a warning to on by default
> while making it available only in a subset of languages.  The
> only way I can think of is to initialize it in the .opt file to
> something like -1 and then change it at some point to 2 somewhere
> in the C/C++ front ends.  That seems pretty cumbersome.  Am I
> missing some trick?

Maybe just enhance the machinery to allow

LangEnabledBy (C ObjC C++ ObjC++, , 2, 0)

(note empty "by")

?

> Martin

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] disable -Walloc-size-larger-than and -Wstringop-overflow for non-C front ends (PR 80545)
  2017-05-09  9:28     ` Richard Biener
@ 2017-05-09 14:14       ` Martin Sebor
  0 siblings, 0 replies; 5+ messages in thread
From: Martin Sebor @ 2017-05-09 14:14 UTC (permalink / raw)
  To: Richard Biener; +Cc: Jeff Law, Gcc Patch List

On 05/09/2017 02:57 AM, Richard Biener wrote:
> On Mon, May 8, 2017 at 4:31 PM, Martin Sebor <msebor@gmail.com> wrote:
>> On 05/04/2017 10:13 PM, Jeff Law wrote:
>>>
>>> On 04/28/2017 04:02 PM, Martin Sebor wrote:
>>>>
>>>> The two options were included in -Wall and enabled for all front
>>>> ends but only made to be recognized by the driver for the C family
>>>> of compilers.  That made it impossible to suppress those warnings
>>>> when compiling code for those other front ends (like Fortran).
>>>>
>>>> The attached patch adjusts the warnings so that they are only
>>>> enabled for the C family of front ends and not for any others,
>>>> as per Richard's suggestion.  (The other solution would have
>>>> been to make the warnings available to all front ends.  Since
>>>> non-C languages don't have a way of calling the affected
>>>> functions -- or do they? -- this is probably not necessary.)
>>>>
>>>> Martin
>>>>
>>>> gcc-80545.diff
>>>>
>>>>
>>>> PR driver/80545 - option -Wstringop-overflow not recognized by Fortran
>>>>
>>>> gcc/c-family/ChangeLog:
>>>>
>>>>     PR driver/80545
>>>>     * c.opt (-Walloc-size-larger-than, -Wstringop-overflow): Enable
>>>>     and make available for the C family only.
>>>
>>> OK.
>>> jeff
>>
>>
>> It turns out that this is not the right fix.  I overlooked that
>> -Wstringop-overflow is meant to be enabled by default and while
>> removing the Init(2) bit and replacing it with LangEnabledBy (C
>> ObjC C++ ObjC++, Wall, 2, 0) suppresses the warning in Fortran
>> it also disables it by default in C/C++ unless -Wall is used.
>>
>> By my reading of the Option properties part of the GCC Internals
>> manual there is no way to initialize a warning to on by default
>> while making it available only in a subset of languages.  The
>> only way I can think of is to initialize it in the .opt file to
>> something like -1 and then change it at some point to 2 somewhere
>> in the C/C++ front ends.  That seems pretty cumbersome.  Am I
>> missing some trick?
>
> Maybe just enhance the machinery to allow
>
> LangEnabledBy (C ObjC C++ ObjC++, , 2, 0)
>
> (note empty "by")
>
> ?

Yes, I was thinking of something along these lines as well.
Generalizing it for all options sounds like the right
approach.  Thanks!

Martin

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-05-09 14:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-29  2:02 [PATCH] disable -Walloc-size-larger-than and -Wstringop-overflow for non-C front ends (PR 80545) Martin Sebor
2017-05-05  4:21 ` Jeff Law
2017-05-08 14:33   ` Martin Sebor
2017-05-09  9:28     ` Richard Biener
2017-05-09 14:14       ` Martin Sebor

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).