public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Add option to control warnings added through attribure "warning"
@ 2018-10-12 10:50 Nikolai Merinov
  2018-10-12 17:19 ` Martin Sebor
  0 siblings, 1 reply; 10+ messages in thread
From: Nikolai Merinov @ 2018-10-12 10:50 UTC (permalink / raw)
  To: gcc-patches

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

Hello,

In https://gcc.gnu.org/ml/gcc-patches/2018-09/msg01795.html mail I suggested patch to have ability to control behavior of "__attribute__((warning))" in case when option "-Werror" enabled. Usage example:

> #include <string.h>
> int a() __attribute__((warning("Warning: `a' was used")));
> int a() { return 1; }
> int main () { return a(); }

> $ gcc -Werror test.c
> test.c: In function ‘main’:
> test.c:4:22: error: call to ‘a’ declared with attribute warning: Warning: `a' was used [-Werror]
>  int main () { return a(); }
>                       ^
> cc1: all warnings being treated as errors
> $ gcc -Werror -Wno-error=warning-attribute test.c
> test.c: In function ‘main’:
> test.c:4:22: warning: call to ‘a’ declared with attribute warning: Warning: `a' was used
>  int main () { return a(); }
>                       ^
Can you provide any feedback on suggested changes?

Regards,
Nikolai

[-- Attachment #2: gcc-warning-attribute.patch --]
[-- Type: text/x-patch, Size: 3002 bytes --]

Index: gcc/common.opt
===================================================================
--- gcc/common.opt	(revision 264725)
+++ gcc/common.opt	(working copy)
@@ -571,6 +571,10 @@ Wcpp
 Common Var(warn_cpp) Init(1) Warning
 Warn when a #warning directive is encountered.
 
+Wwarning-attribute
+Common Var(warn_warning_attribute) Init(1) Warning
+Warn about uses of __attribute__((warning)) declarations.
+
 Wdeprecated-declarations
 Common Var(warn_deprecated_decl) Init(1) Warning
 Warn about uses of __attribute__((deprecated)) declarations.
Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi	(revision 264725)
+++ gcc/doc/invoke.texi	(working copy)
@@ -291,6 +291,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wclobbered  -Wcomment  -Wconditionally-supported @gol
 -Wconversion  -Wcoverage-mismatch  -Wno-cpp  -Wdangling-else  -Wdate-time @gol
 -Wdelete-incomplete @gol
+-Wno-warning-attribute @gol
 -Wno-deprecated  -Wno-deprecated-declarations  -Wno-designated-init @gol
 -Wdisabled-optimization @gol
 -Wno-discarded-qualifiers  -Wno-discarded-array-qualifiers @gol
@@ -6940,6 +6941,15 @@ confused with the digit 0, and so is not the defau
 useful as a local coding convention if the programming environment 
 cannot be fixed to display these characters distinctly.
 
+@item -Wno-warning-attribute
+@opindex Wno-warning-attribute
+@opindex Wwarning-attribute
+Do not warn about usage of functions (@pxref{Function Attributes})
+declared with @code{warning} attribute. By default, this warning is
+enabled.  @option{-Wno-warning-attribute} can be used to disable the
+warning or @option{-Wno-error=warning-attribute} can be used to
+disable the error when compiled with @option{-Werror} flag.
+
 @item -Wno-deprecated
 @opindex Wno-deprecated
 @opindex Wdeprecated
Index: gcc/expr.c
===================================================================
--- gcc/expr.c	(revision 264725)
+++ gcc/expr.c	(working copy)
@@ -10930,7 +10930,8 @@ expand_expr_real_1 (tree exp, rtx target, machine_
 					 DECL_ATTRIBUTES (fndecl))) != NULL)
 	  {
 	    const char *ident = lang_hooks.decl_printable_name (fndecl, 1);
-	    warning_at (tree_nonartificial_location (exp), 0,
+	    warning_at (tree_nonartificial_location (exp),
+			OPT_Wwarning_attribute,
 			"%Kcall to %qs declared with attribute warning: %s",
 			exp, identifier_to_locale (ident),
 			TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
Index: gcc/testsuite/gcc.dg/Wno-warning-attribute.c
===================================================================
--- gcc/testsuite/gcc.dg/Wno-warning-attribute.c	(revision 0)
+++ gcc/testsuite/gcc.dg/Wno-warning-attribute.c	(working copy)
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-Werror -Wno-error=warning-attribute" } */
+
+int f1(void) __attribute__ ((warning("Please avoid f1")));
+int func1(void)
+{
+  return f1(); /* { dg-warning "'f1' declared with attribute warning: Please avoid f1" } */
+}

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

* Re: [PATCH] Add option to control warnings added through attribure "warning"
  2018-10-12 10:50 [PATCH] Add option to control warnings added through attribure "warning" Nikolai Merinov
@ 2018-10-12 17:19 ` Martin Sebor
  2018-10-15  8:13   ` Nikolai Merinov
  0 siblings, 1 reply; 10+ messages in thread
From: Martin Sebor @ 2018-10-12 17:19 UTC (permalink / raw)
  To: Nikolai Merinov, gcc-patches

On 10/12/2018 04:14 AM, Nikolai Merinov wrote:
> Hello,
>
> In https://gcc.gnu.org/ml/gcc-patches/2018-09/msg01795.html mail I
> suggested patch to have ability to control behavior of
> "__attribute__((warning))" in case when option "-Werror" enabled. Usage
> example:
>
>> #include <string.h>
>> int a() __attribute__((warning("Warning: `a' was used")));
>> int a() { return 1; }
>> int main () { return a(); }
>
>> $ gcc -Werror test.c
>> test.c: In function ‘main’:
>> test.c:4:22: error: call to ‘a’ declared with attribute warning:
>> Warning: `a' was used [-Werror]
>>  int main () { return a(); }
>>                       ^
>> cc1: all warnings being treated as errors
>> $ gcc -Werror -Wno-error=warning-attribute test.c
>> test.c: In function ‘main’:
>> test.c:4:22: warning: call to ‘a’ declared with attribute warning:
>> Warning: `a' was used
>>  int main () { return a(); }
>>                       ^
> Can you provide any feedback on suggested changes?

It seems like a useful feature and in line with the philosophy
that distinct warnings should be controlled by their own options.

I would only suggest to consider changing the name to
-Wattribute-warning, because it applies specifically to that
attribute (as opposed to warnings about attributes in general).

There are many attributes in GCC and diagnosing problems that
are unique to each, under the same -Wattributes option, is
becoming too coarse and overly limiting.  To make it more
flexible, I expect new options will need to be introduced,
such as -Wattribute-alias (to control aspects of the alias
attribute and others related to it), or -Wattribute-const
(to control diagnostics about functions declared with
attribute const that violate the attribute's constraints).

An alternative might be to introduce a single -Wattribute=
<attribute-list> option where the <attribute-list> gives
the names of all the distinct attributes whose unique
diagnostics one might need to control.

Martin

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

* Re: [PATCH] Add option to control warnings added through attribure "warning"
  2018-10-12 17:19 ` Martin Sebor
@ 2018-10-15  8:13   ` Nikolai Merinov
  2018-10-15 13:36     ` Martin Sebor
  0 siblings, 1 reply; 10+ messages in thread
From: Nikolai Merinov @ 2018-10-15  8:13 UTC (permalink / raw)
  To: Martin Sebor, gcc-patches

Hi Martin,

On 10/12/18 9:58 PM, Martin Sebor wrote:
> On 10/12/2018 04:14 AM, Nikolai Merinov wrote:
>> Hello,
>>
>> In https://gcc.gnu.org/ml/gcc-patches/2018-09/msg01795.html mail I
>> suggested patch to have ability to control behavior of
>> "__attribute__((warning))" in case when option "-Werror" enabled. Usage
>> example:
>>
>>> #include <string.h>
>>> int a() __attribute__((warning("Warning: `a' was used")));
>>> int a() { return 1; }
>>> int main () { return a(); }
>>
>>> $ gcc -Werror test.c
>>> test.c: In function ‘main’:
>>> test.c:4:22: error: call to ‘a’ declared with attribute warning:
>>> Warning: `a' was used [-Werror]
>>>  int main () { return a(); }
>>>                       ^
>>> cc1: all warnings being treated as errors
>>> $ gcc -Werror -Wno-error=warning-attribute test.c
>>> test.c: In function ‘main’:
>>> test.c:4:22: warning: call to ‘a’ declared with attribute warning:
>>> Warning: `a' was used
>>>  int main () { return a(); }
>>>                       ^
>> Can you provide any feedback on suggested changes?
> 
> It seems like a useful feature and in line with the philosophy
> that distinct warnings should be controlled by their own options.
> 
> I would only suggest to consider changing the name to
> -Wattribute-warning, because it applies specifically to that
> attribute (as opposed to warnings about attributes in general).
> 
> There are many attributes in GCC and diagnosing problems that
> are unique to each, under the same -Wattributes option, is
> becoming too coarse and overly limiting.  To make it more
> flexible, I expect new options will need to be introduced,
> such as -Wattribute-alias (to control aspects of the alias
> attribute and others related to it), or -Wattribute-const
> (to control diagnostics about functions declared with
> attribute const that violate the attribute's constraints).
> 
> An alternative might be to introduce a single -Wattribute=
> <attribute-list> option where the <attribute-list> gives
> the names of all the distinct attributes whose unique
> diagnostics one might need to control.
> 
> Martin

Currently there is several styles already in use:

-Wattribute-alias where "attribute" word used as prefix for name of attribute,
-Wsuggest-attribute=[pure|const|noreturn|format|malloc] where name of attribute passed as possible argument,
-Wmissing-format-attribute where "attribute" word used as suffix,
-Wdeprecated-declarations where "attribute" word not used at all even if this warning option was created especially for "deprecated" attribute.

I changed name to "-Wattribute-warning" as you suggested, but unifying style for all attribute related warning looks like separate activity. Please check new patch in attachments.

Updated changelog:

gcc/Changelog

2018-10-14  Nikolai Merinov <n.merinov@inango-systems.com>

         * gcc/common.opt: Add -Wattribute-warning.
         * gcc/doc/invoke.texi: Add documentation for -Wno-attribute-warning.
         * gcc/testsuite/gcc.dg/Wno-attribute-warning.c: New test.
         * gcc/expr.c (expand_expr_real_1): Add new attribute to warning_at
         call to allow user configure behavior of "warning" attribute

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

* Re: [PATCH] Add option to control warnings added through attribure "warning"
  2018-10-15  8:13   ` Nikolai Merinov
@ 2018-10-15 13:36     ` Martin Sebor
  2018-10-15 15:57       ` Nikolai Merinov
  0 siblings, 1 reply; 10+ messages in thread
From: Martin Sebor @ 2018-10-15 13:36 UTC (permalink / raw)
  To: Nikolai Merinov, gcc-patches

On 10/15/2018 01:55 AM, Nikolai Merinov wrote:
> Hi Martin,
> 
> On 10/12/18 9:58 PM, Martin Sebor wrote:
>> On 10/12/2018 04:14 AM, Nikolai Merinov wrote:
>>> Hello,
>>>
>>> In https://gcc.gnu.org/ml/gcc-patches/2018-09/msg01795.html mail I
>>> suggested patch to have ability to control behavior of
>>> "__attribute__((warning))" in case when option "-Werror" enabled. Usage
>>> example:
>>>
>>>> #include <string.h>
>>>> int a() __attribute__((warning("Warning: `a' was used")));
>>>> int a() { return 1; }
>>>> int main () { return a(); }
>>>
>>>> $ gcc -Werror test.c
>>>> test.c: In function ‘main’:
>>>> test.c:4:22: error: call to ‘a’ declared with attribute warning:
>>>> Warning: `a' was used [-Werror]
>>>>  int main () { return a(); }
>>>>                       ^
>>>> cc1: all warnings being treated as errors
>>>> $ gcc -Werror -Wno-error=warning-attribute test.c
>>>> test.c: In function ‘main’:
>>>> test.c:4:22: warning: call to ‘a’ declared with attribute warning:
>>>> Warning: `a' was used
>>>>  int main () { return a(); }
>>>>                       ^
>>> Can you provide any feedback on suggested changes?
>>
>> It seems like a useful feature and in line with the philosophy
>> that distinct warnings should be controlled by their own options.
>>
>> I would only suggest to consider changing the name to
>> -Wattribute-warning, because it applies specifically to that
>> attribute (as opposed to warnings about attributes in general).
>>
>> There are many attributes in GCC and diagnosing problems that
>> are unique to each, under the same -Wattributes option, is
>> becoming too coarse and overly limiting.  To make it more
>> flexible, I expect new options will need to be introduced,
>> such as -Wattribute-alias (to control aspects of the alias
>> attribute and others related to it), or -Wattribute-const
>> (to control diagnostics about functions declared with
>> attribute const that violate the attribute's constraints).
>>
>> An alternative might be to introduce a single -Wattribute=
>> <attribute-list> option where the <attribute-list> gives
>> the names of all the distinct attributes whose unique
>> diagnostics one might need to control.
>>
>> Martin
> 
> Currently there is several styles already in use:
> 
> -Wattribute-alias where "attribute" word used as prefix for name of 
> attribute,
> -Wsuggest-attribute=[pure|const|noreturn|format|malloc] where name of 
> attribute passed as possible argument,
> -Wmissing-format-attribute where "attribute" word used as suffix,
> -Wdeprecated-declarations where "attribute" word not used at all even if 
> this warning option was created especially for "deprecated" attribute.
> 
> I changed name to "-Wattribute-warning" as you suggested, but unifying 
> style for all attribute related warning looks like separate activity. 
> Please check new patch in attachments.
> 

Thanks for survey!  I agree that making the existing options
consistent (if that's what we want) should be done separately.

Martin

PS It doesn't look like your latest attachments made it to
the list.


> Updated changelog:
> 
> gcc/Changelog
> 
> 2018-10-14  Nikolai Merinov <n.merinov@inango-systems.com>
> 
>          * gcc/common.opt: Add -Wattribute-warning.
>          * gcc/doc/invoke.texi: Add documentation for 
> -Wno-attribute-warning.
>          * gcc/testsuite/gcc.dg/Wno-attribute-warning.c: New test.
>          * gcc/expr.c (expand_expr_real_1): Add new attribute to warning_at
>          call to allow user configure behavior of "warning" attribute

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

* Re: [PATCH] Add option to control warnings added through attribure "warning"
  2018-10-15 13:36     ` Martin Sebor
@ 2018-10-15 15:57       ` Nikolai Merinov
  2018-10-26 12:07         ` Nikolai Merinov
  2018-11-07 21:04         ` Jeff Law
  0 siblings, 2 replies; 10+ messages in thread
From: Nikolai Merinov @ 2018-10-15 15:57 UTC (permalink / raw)
  To: Martin Sebor, gcc-patches

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

Hi Martin,

On 10/15/18 6:20 PM, Martin Sebor wrote:
> On 10/15/2018 01:55 AM, Nikolai Merinov wrote:
>> Hi Martin,
>>
>> On 10/12/18 9:58 PM, Martin Sebor wrote:
>>> On 10/12/2018 04:14 AM, Nikolai Merinov wrote:
>>>> Hello,
>>>>
>>>> In https://gcc.gnu.org/ml/gcc-patches/2018-09/msg01795.html mail I
>>>> suggested patch to have ability to control behavior of
>>>> "__attribute__((warning))" in case when option "-Werror" enabled. Usage
>>>> example:
>>>>
>>>>> #include <string.h>
>>>>> int a() __attribute__((warning("Warning: `a' was used")));
>>>>> int a() { return 1; }
>>>>> int main () { return a(); }
>>>>
>>>>> $ gcc -Werror test.c
>>>>> test.c: In function ‘main’:
>>>>> test.c:4:22: error: call to ‘a’ declared with attribute warning:
>>>>> Warning: `a' was used [-Werror]
>>>>>  int main () { return a(); }
>>>>>                       ^
>>>>> cc1: all warnings being treated as errors
>>>>> $ gcc -Werror -Wno-error=warning-attribute test.c
>>>>> test.c: In function ‘main’:
>>>>> test.c:4:22: warning: call to ‘a’ declared with attribute warning:
>>>>> Warning: `a' was used
>>>>>  int main () { return a(); }
>>>>>                       ^
>>>> Can you provide any feedback on suggested changes?
>>>
>>> It seems like a useful feature and in line with the philosophy
>>> that distinct warnings should be controlled by their own options.
>>>
>>> I would only suggest to consider changing the name to
>>> -Wattribute-warning, because it applies specifically to that
>>> attribute (as opposed to warnings about attributes in general).
>>>
>>> There are many attributes in GCC and diagnosing problems that
>>> are unique to each, under the same -Wattributes option, is
>>> becoming too coarse and overly limiting.  To make it more
>>> flexible, I expect new options will need to be introduced,
>>> such as -Wattribute-alias (to control aspects of the alias
>>> attribute and others related to it), or -Wattribute-const
>>> (to control diagnostics about functions declared with
>>> attribute const that violate the attribute's constraints).
>>>
>>> An alternative might be to introduce a single -Wattribute=
>>> <attribute-list> option where the <attribute-list> gives
>>> the names of all the distinct attributes whose unique
>>> diagnostics one might need to control.
>>>
>>> Martin
>>
>> Currently there is several styles already in use:
>>
>> -Wattribute-alias where "attribute" word used as prefix for name of attribute,
>> -Wsuggest-attribute=[pure|const|noreturn|format|malloc] where name of attribute passed as possible argument,
>> -Wmissing-format-attribute where "attribute" word used as suffix,
>> -Wdeprecated-declarations where "attribute" word not used at all even if this warning option was created especially for "deprecated" attribute.
>>
>> I changed name to "-Wattribute-warning" as you suggested, but unifying style for all attribute related warning looks like separate activity. Please check new patch in attachments.
>>
> 
> Thanks for survey!  I agree that making the existing options
> consistent (if that's what we want) should be done separately.
> 
> Martin
> 
> PS It doesn't look like your latest attachments made it to
> the list.
> 
Thank you for mentioning. There was my mistake. Now it's attached
> 
>> Updated changelog:
>>
>> gcc/Changelog
>>
>> 2018-10-14  Nikolai Merinov <n.merinov@inango-systems.com>
>>
>>          * gcc/common.opt: Add -Wattribute-warning.
>>          * gcc/doc/invoke.texi: Add documentation for -Wno-attribute-warning.
>>          * gcc/testsuite/gcc.dg/Wno-attribute-warning.c: New test.
>>          * gcc/expr.c (expand_expr_real_1): Add new attribute to warning_at
>>          call to allow user configure behavior of "warning" attribute


[-- Attachment #2: gcc-Wattribute-warning.patch --]
[-- Type: text/x-patch, Size: 3002 bytes --]

Index: gcc/common.opt
===================================================================
--- gcc/common.opt	(revision 265156)
+++ gcc/common.opt	(working copy)
@@ -571,6 +571,10 @@ Wcpp
 Common Var(warn_cpp) Init(1) Warning
 Warn when a #warning directive is encountered.
 
+Wattribute-warning
+Common Var(warn_attribute_warning) Init(1) Warning
+Warn about uses of __attribute__((warning)) declarations.
+
 Wdeprecated-declarations
 Common Var(warn_deprecated_decl) Init(1) Warning
 Warn about uses of __attribute__((deprecated)) declarations.
Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi	(revision 265156)
+++ gcc/doc/invoke.texi	(working copy)
@@ -291,6 +291,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wclobbered  -Wcomment  -Wconditionally-supported @gol
 -Wconversion  -Wcoverage-mismatch  -Wno-cpp  -Wdangling-else  -Wdate-time @gol
 -Wdelete-incomplete @gol
+-Wno-attribute-warning @gol
 -Wno-deprecated  -Wno-deprecated-declarations  -Wno-designated-init @gol
 -Wdisabled-optimization @gol
 -Wno-discarded-qualifiers  -Wno-discarded-array-qualifiers @gol
@@ -6950,6 +6951,15 @@ confused with the digit 0, and so is not the defau
 useful as a local coding convention if the programming environment 
 cannot be fixed to display these characters distinctly.
 
+@item -Wno-attribute-warning
+@opindex Wno-attribute-warning
+@opindex Wattribute-warning
+Do not warn about usage of functions (@pxref{Function Attributes})
+declared with @code{warning} attribute. By default, this warning is
+enabled.  @option{-Wno-attribute-warning} can be used to disable the
+warning or @option{-Wno-error=attribute-warning} can be used to
+disable the error when compiled with @option{-Werror} flag.
+
 @item -Wno-deprecated
 @opindex Wno-deprecated
 @opindex Wdeprecated
Index: gcc/expr.c
===================================================================
--- gcc/expr.c	(revision 265156)
+++ gcc/expr.c	(working copy)
@@ -10930,7 +10930,8 @@ expand_expr_real_1 (tree exp, rtx target, machine_
 					 DECL_ATTRIBUTES (fndecl))) != NULL)
 	  {
 	    const char *ident = lang_hooks.decl_printable_name (fndecl, 1);
-	    warning_at (tree_nonartificial_location (exp), 0,
+	    warning_at (tree_nonartificial_location (exp),
+			OPT_Wattribute_warning,
 			"%Kcall to %qs declared with attribute warning: %s",
 			exp, identifier_to_locale (ident),
 			TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
Index: gcc/testsuite/gcc.dg/Wno-attribute-warning.c
===================================================================
--- gcc/testsuite/gcc.dg/Wno-attribute-warning.c	(revision 0)
+++ gcc/testsuite/gcc.dg/Wno-attribute-warning.c	(working copy)
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-Werror -Wno-error=attribute-warning" } */
+
+int f1(void) __attribute__ ((warning("Please avoid f1")));
+int func1(void)
+{
+  return f1(); /* { dg-warning "'f1' declared with attribute warning: Please avoid f1" } */
+}

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

* Re: [PATCH] Add option to control warnings added through attribure "warning"
  2018-10-15 15:57       ` Nikolai Merinov
@ 2018-10-26 12:07         ` Nikolai Merinov
  2018-10-26 15:43           ` Martin Sebor
  2018-11-07 21:04         ` Jeff Law
  1 sibling, 1 reply; 10+ messages in thread
From: Nikolai Merinov @ 2018-10-26 12:07 UTC (permalink / raw)
  To: Martin Sebor, gcc-patches

Hi,

What next steps should I perform in order to get this changes merged to GCC?

Regards,
Nikolai

----- Original Message -----
From: "Nikolai Merinov" 
To: "Martin Sebor" , gcc-patches@gcc.gnu.org
Sent: Monday, October 15, 2018 3:21:15 PM
Subject: Re: [PATCH] Add option to control warnings added through attribure "warning"

Hi Martin,

On 10/15/18 6:20 PM, Martin Sebor wrote:
> On 10/15/2018 01:55 AM, Nikolai Merinov wrote:
>> Hi Martin,
>>
>> On 10/12/18 9:58 PM, Martin Sebor wrote:
>>> On 10/12/2018 04:14 AM, Nikolai Merinov wrote:
>>>> Hello,
>>>>
>>>> In https://gcc.gnu.org/ml/gcc-patches/2018-09/msg01795.html mail I
>>>> suggested patch to have ability to control behavior of
>>>> "__attribute__((warning))" in case when option "-Werror" enabled. Usage
>>>> example:
>>>>
>>>>> #include 
>>>>> int a() __attribute__((warning("Warning: `a' was used")));
>>>>> int a() { return 1; }
>>>>> int main () { return a(); }
>>>>
>>>>> $ gcc -Werror test.c
>>>>> test.c: In function ‘main’:
>>>>> test.c:4:22: error: call to ‘a’ declared with attribute warning:
>>>>> Warning: `a' was used [-Werror]
>>>>>  int main () { return a(); }
>>>>>                       ^
>>>>> cc1: all warnings being treated as errors
>>>>> $ gcc -Werror -Wno-error=warning-attribute test.c
>>>>> test.c: In function ‘main’:
>>>>> test.c:4:22: warning: call to ‘a’ declared with attribute warning:
>>>>> Warning: `a' was used
>>>>>  int main () { return a(); }
>>>>>                       ^
>>>> Can you provide any feedback on suggested changes?
>>>
>>> It seems like a useful feature and in line with the philosophy
>>> that distinct warnings should be controlled by their own options.
>>>
>>> I would only suggest to consider changing the name to
>>> -Wattribute-warning, because it applies specifically to that
>>> attribute (as opposed to warnings about attributes in general).
>>>
>>> There are many attributes in GCC and diagnosing problems that
>>> are unique to each, under the same -Wattributes option, is
>>> becoming too coarse and overly limiting.  To make it more
>>> flexible, I expect new options will need to be introduced,
>>> such as -Wattribute-alias (to control aspects of the alias
>>> attribute and others related to it), or -Wattribute-const
>>> (to control diagnostics about functions declared with
>>> attribute const that violate the attribute's constraints).
>>>
>>> An alternative might be to introduce a single -Wattribute=
>>>  option where the  gives
>>> the names of all the distinct attributes whose unique
>>> diagnostics one might need to control.
>>>
>>> Martin
>>
>> Currently there is several styles already in use:
>>
>> -Wattribute-alias where "attribute" word used as prefix for name of attribute,
>> -Wsuggest-attribute=[pure|const|noreturn|format|malloc] where name of attribute passed as possible argument,
>> -Wmissing-format-attribute where "attribute" word used as suffix,
>> -Wdeprecated-declarations where "attribute" word not used at all even if this warning option was created especially for "deprecated" attribute.
>>
>> I changed name to "-Wattribute-warning" as you suggested, but unifying style for all attribute related warning looks like separate activity. Please check new patch in attachments.
>>
> 
> Thanks for survey!  I agree that making the existing options
> consistent (if that's what we want) should be done separately.
> 
> Martin
> 
> PS It doesn't look like your latest attachments made it to
> the list.
> 
Thank you for mentioning. There was my mistake. Now it's attached
> 
>> Updated changelog:
>>
>> gcc/Changelog
>>
>> 2018-10-14  Nikolai Merinov 
>>
>>          * gcc/common.opt: Add -Wattribute-warning.
>>          * gcc/doc/invoke.texi: Add documentation for -Wno-attribute-warning.
>>          * gcc/testsuite/gcc.dg/Wno-attribute-warning.c: New test.
>>          * gcc/expr.c (expand_expr_real_1): Add new attribute to warning_at
>>          call to allow user configure behavior of "warning" attribute

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

* Re: [PATCH] Add option to control warnings added through attribure "warning"
  2018-10-26 12:07         ` Nikolai Merinov
@ 2018-10-26 15:43           ` Martin Sebor
  2018-10-26 16:13             ` Jeff Law
  0 siblings, 1 reply; 10+ messages in thread
From: Martin Sebor @ 2018-10-26 15:43 UTC (permalink / raw)
  To: Nikolai Merinov, gcc-patches

On 10/26/2018 05:01 AM, Nikolai Merinov wrote:
> Hi,
>
> What next steps should I perform in order to get this changes merged to GCC?

Keep pinging it once a week until a maintainer approves it.
I'm not empowered to do that.

Martin

>
> Regards,
> Nikolai
>
> ----- Original Message -----
> From: "Nikolai Merinov"
> To: "Martin Sebor" , gcc-patches@gcc.gnu.org
> Sent: Monday, October 15, 2018 3:21:15 PM
> Subject: Re: [PATCH] Add option to control warnings added through attribure "warning"
>
> Hi Martin,
>
> On 10/15/18 6:20 PM, Martin Sebor wrote:
>> On 10/15/2018 01:55 AM, Nikolai Merinov wrote:
>>> Hi Martin,
>>>
>>> On 10/12/18 9:58 PM, Martin Sebor wrote:
>>>> On 10/12/2018 04:14 AM, Nikolai Merinov wrote:
>>>>> Hello,
>>>>>
>>>>> In https://gcc.gnu.org/ml/gcc-patches/2018-09/msg01795.html mail I
>>>>> suggested patch to have ability to control behavior of
>>>>> "__attribute__((warning))" in case when option "-Werror" enabled. Usage
>>>>> example:
>>>>>
>>>>>> #include
>>>>>> int a() __attribute__((warning("Warning: `a' was used")));
>>>>>> int a() { return 1; }
>>>>>> int main () { return a(); }
>>>>>
>>>>>> $ gcc -Werror test.c
>>>>>> test.c: In function ‘main’:
>>>>>> test.c:4:22: error: call to ‘a’ declared with attribute warning:
>>>>>> Warning: `a' was used [-Werror]
>>>>>>  int main () { return a(); }
>>>>>>                       ^
>>>>>> cc1: all warnings being treated as errors
>>>>>> $ gcc -Werror -Wno-error=warning-attribute test.c
>>>>>> test.c: In function ‘main’:
>>>>>> test.c:4:22: warning: call to ‘a’ declared with attribute warning:
>>>>>> Warning: `a' was used
>>>>>>  int main () { return a(); }
>>>>>>                       ^
>>>>> Can you provide any feedback on suggested changes?
>>>>
>>>> It seems like a useful feature and in line with the philosophy
>>>> that distinct warnings should be controlled by their own options.
>>>>
>>>> I would only suggest to consider changing the name to
>>>> -Wattribute-warning, because it applies specifically to that
>>>> attribute (as opposed to warnings about attributes in general).
>>>>
>>>> There are many attributes in GCC and diagnosing problems that
>>>> are unique to each, under the same -Wattributes option, is
>>>> becoming too coarse and overly limiting.  To make it more
>>>> flexible, I expect new options will need to be introduced,
>>>> such as -Wattribute-alias (to control aspects of the alias
>>>> attribute and others related to it), or -Wattribute-const
>>>> (to control diagnostics about functions declared with
>>>> attribute const that violate the attribute's constraints).
>>>>
>>>> An alternative might be to introduce a single -Wattribute=
>>>>  option where the  gives
>>>> the names of all the distinct attributes whose unique
>>>> diagnostics one might need to control.
>>>>
>>>> Martin
>>>
>>> Currently there is several styles already in use:
>>>
>>> -Wattribute-alias where "attribute" word used as prefix for name of attribute,
>>> -Wsuggest-attribute=[pure|const|noreturn|format|malloc] where name of attribute passed as possible argument,
>>> -Wmissing-format-attribute where "attribute" word used as suffix,
>>> -Wdeprecated-declarations where "attribute" word not used at all even if this warning option was created especially for "deprecated" attribute.
>>>
>>> I changed name to "-Wattribute-warning" as you suggested, but unifying style for all attribute related warning looks like separate activity. Please check new patch in attachments.
>>>
>>
>> Thanks for survey!  I agree that making the existing options
>> consistent (if that's what we want) should be done separately.
>>
>> Martin
>>
>> PS It doesn't look like your latest attachments made it to
>> the list.
>>
> Thank you for mentioning. There was my mistake. Now it's attached
>>
>>> Updated changelog:
>>>
>>> gcc/Changelog
>>>
>>> 2018-10-14  Nikolai Merinov
>>>
>>>          * gcc/common.opt: Add -Wattribute-warning.
>>>          * gcc/doc/invoke.texi: Add documentation for -Wno-attribute-warning.
>>>          * gcc/testsuite/gcc.dg/Wno-attribute-warning.c: New test.
>>>          * gcc/expr.c (expand_expr_real_1): Add new attribute to warning_at
>>>          call to allow user configure behavior of "warning" attribute

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

* Re: [PATCH] Add option to control warnings added through attribure "warning"
  2018-10-26 15:43           ` Martin Sebor
@ 2018-10-26 16:13             ` Jeff Law
  0 siblings, 0 replies; 10+ messages in thread
From: Jeff Law @ 2018-10-26 16:13 UTC (permalink / raw)
  To: Martin Sebor, Nikolai Merinov, gcc-patches

On 10/26/18 9:11 AM, Martin Sebor wrote:
> On 10/26/2018 05:01 AM, Nikolai Merinov wrote:
>> Hi,
>>
>> What next steps should I perform in order to get this changes merged
>> to GCC?
> 
> Keep pinging it once a week until a maintainer approves it.
> I'm not empowered to do that.
Nikolai -- your patch isn't lost.  It's definitely in the queue.

jeff

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

* Re: [PATCH] Add option to control warnings added through attribure "warning"
  2018-10-15 15:57       ` Nikolai Merinov
  2018-10-26 12:07         ` Nikolai Merinov
@ 2018-11-07 21:04         ` Jeff Law
  1 sibling, 0 replies; 10+ messages in thread
From: Jeff Law @ 2018-11-07 21:04 UTC (permalink / raw)
  To: Nikolai Merinov, Martin Sebor, gcc-patches

On 10/15/18 9:21 AM, Nikolai Merinov wrote:
> Hi Martin,
> 
> On 10/15/18 6:20 PM, Martin Sebor wrote:
>> On 10/15/2018 01:55 AM, Nikolai Merinov wrote:
>>> Hi Martin,
>>>
>>> On 10/12/18 9:58 PM, Martin Sebor wrote:
>>>> On 10/12/2018 04:14 AM, Nikolai Merinov wrote:
>>>>> Hello,
>>>>>
>>>>> In https://gcc.gnu.org/ml/gcc-patches/2018-09/msg01795.html mail I
>>>>> suggested patch to have ability to control behavior of
>>>>> "__attribute__((warning))" in case when option "-Werror" enabled.
>>>>> Usage
>>>>> example:
>>>>>
>>>>>> #include <string.h>
>>>>>> int a() __attribute__((warning("Warning: `a' was used")));
>>>>>> int a() { return 1; }
>>>>>> int main () { return a(); }
>>>>>
>>>>>> $ gcc -Werror test.c
>>>>>> test.c: In function ‘main’:
>>>>>> test.c:4:22: error: call to ‘a’ declared with attribute warning:
>>>>>> Warning: `a' was used [-Werror]
>>>>>>  int main () { return a(); }
>>>>>>                       ^
>>>>>> cc1: all warnings being treated as errors
>>>>>> $ gcc -Werror -Wno-error=warning-attribute test.c
>>>>>> test.c: In function ‘main’:
>>>>>> test.c:4:22: warning: call to ‘a’ declared with attribute warning:
>>>>>> Warning: `a' was used
>>>>>>  int main () { return a(); }
>>>>>>                       ^
>>>>> Can you provide any feedback on suggested changes?
>>>>
>>>> It seems like a useful feature and in line with the philosophy
>>>> that distinct warnings should be controlled by their own options.
>>>>
>>>> I would only suggest to consider changing the name to
>>>> -Wattribute-warning, because it applies specifically to that
>>>> attribute (as opposed to warnings about attributes in general).
>>>>
>>>> There are many attributes in GCC and diagnosing problems that
>>>> are unique to each, under the same -Wattributes option, is
>>>> becoming too coarse and overly limiting.  To make it more
>>>> flexible, I expect new options will need to be introduced,
>>>> such as -Wattribute-alias (to control aspects of the alias
>>>> attribute and others related to it), or -Wattribute-const
>>>> (to control diagnostics about functions declared with
>>>> attribute const that violate the attribute's constraints).
>>>>
>>>> An alternative might be to introduce a single -Wattribute=
>>>> <attribute-list> option where the <attribute-list> gives
>>>> the names of all the distinct attributes whose unique
>>>> diagnostics one might need to control.
>>>>
>>>> Martin
>>>
>>> Currently there is several styles already in use:
>>>
>>> -Wattribute-alias where "attribute" word used as prefix for name of
>>> attribute,
>>> -Wsuggest-attribute=[pure|const|noreturn|format|malloc] where name of
>>> attribute passed as possible argument,
>>> -Wmissing-format-attribute where "attribute" word used as suffix,
>>> -Wdeprecated-declarations where "attribute" word not used at all even
>>> if this warning option was created especially for "deprecated"
>>> attribute.
>>>
>>> I changed name to "-Wattribute-warning" as you suggested, but
>>> unifying style for all attribute related warning looks like separate
>>> activity. Please check new patch in attachments.
>>>
>>
>> Thanks for survey!  I agree that making the existing options
>> consistent (if that's what we want) should be done separately.
>>
>> Martin
>>
>> PS It doesn't look like your latest attachments made it to
>> the list.
>>
> Thank you for mentioning. There was my mistake. Now it's attached
>>
>>> Updated changelog:
>>>
>>> gcc/Changelog
>>>
>>> 2018-10-14  Nikolai Merinov <n.merinov@inango-systems.com>
>>>
>>>          * gcc/common.opt: Add -Wattribute-warning.
>>>          * gcc/doc/invoke.texi: Add documentation for
>>> -Wno-attribute-warning.
>>>          * gcc/testsuite/gcc.dg/Wno-attribute-warning.c: New test.
>>>          * gcc/expr.c (expand_expr_real_1): Add new attribute to
>>> warning_at
>>>          call to allow user configure behavior of "warning" attribute
I split up the ChangeLog and fixed a very minor whitespace issue in the
docs and installed the patch.

I went round and round over whether or not to change the doc text.  It
discusses the attribute and the warning and it's easy to mix up the two.
 But ultimately I decided not to change it.

Thanks and sorry for the long delays.

Jeff
> 

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

* [PATCH] Add option to control warnings added through attribure "warning"
@ 2018-09-30 20:20 Nikolai Merinov
  0 siblings, 0 replies; 10+ messages in thread
From: Nikolai Merinov @ 2018-09-30 20:20 UTC (permalink / raw)
  To: gcc-patches

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

Hello,

I prepared patch that give more precise control over __attribute__((warning)). Currently when you use "warning" attribute with "-Werror" option warning become error and there is no way to ignore this error.

With suggested changes it will be possible to use "-Werror -Wno-error=warning-attribute" to compile code with warning attributes. This particular case added as new testcase.

I tested suggested changes in two cases: with gcc-trunk compiled on GuixSD with GCC 5.5 on amd64 machine and as patch to gcc 6.2.0 inside of Yocto 2.2 environment on Ubuntu 14.04 on amd64 machine.

Regards,
Nikolai

gcc/Changelog

2018-09-29  Nikolai Merinov <n.merinov@inango-systems.com>

         * gcc/common.opt: Add -Wwarning-attribute.
         * gcc/doc/invoke.texi: Add documentation for -Wno-warning-attribute.
         * gcc/testsuite/gcc.dg/Wno-warning-attribute.c: New test.
         * gcc/expr.c (expand_expr_real_1): Add new attribute to warning_at
         call to allow user configure behavior of "warning" attribute

[-- Attachment #2: gcc-warning-attribute.patch --]
[-- Type: text/x-patch, Size: 3002 bytes --]

Index: gcc/common.opt
===================================================================
--- gcc/common.opt	(revision 264725)
+++ gcc/common.opt	(working copy)
@@ -571,6 +571,10 @@ Wcpp
 Common Var(warn_cpp) Init(1) Warning
 Warn when a #warning directive is encountered.
 
+Wwarning-attribute
+Common Var(warn_warning_attribute) Init(1) Warning
+Warn about uses of __attribute__((warning)) declarations.
+
 Wdeprecated-declarations
 Common Var(warn_deprecated_decl) Init(1) Warning
 Warn about uses of __attribute__((deprecated)) declarations.
Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi	(revision 264725)
+++ gcc/doc/invoke.texi	(working copy)
@@ -291,6 +291,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wclobbered  -Wcomment  -Wconditionally-supported @gol
 -Wconversion  -Wcoverage-mismatch  -Wno-cpp  -Wdangling-else  -Wdate-time @gol
 -Wdelete-incomplete @gol
+-Wno-warning-attribute @gol
 -Wno-deprecated  -Wno-deprecated-declarations  -Wno-designated-init @gol
 -Wdisabled-optimization @gol
 -Wno-discarded-qualifiers  -Wno-discarded-array-qualifiers @gol
@@ -6940,6 +6941,15 @@ confused with the digit 0, and so is not the defau
 useful as a local coding convention if the programming environment 
 cannot be fixed to display these characters distinctly.
 
+@item -Wno-warning-attribute
+@opindex Wno-warning-attribute
+@opindex Wwarning-attribute
+Do not warn about usage of functions (@pxref{Function Attributes})
+declared with @code{warning} attribute. By default, this warning is
+enabled.  @option{-Wno-warning-attribute} can be used to disable the
+warning or @option{-Wno-error=warning-attribute} can be used to
+disable the error when compiled with @option{-Werror} flag.
+
 @item -Wno-deprecated
 @opindex Wno-deprecated
 @opindex Wdeprecated
Index: gcc/expr.c
===================================================================
--- gcc/expr.c	(revision 264725)
+++ gcc/expr.c	(working copy)
@@ -10930,7 +10930,8 @@ expand_expr_real_1 (tree exp, rtx target, machine_
 					 DECL_ATTRIBUTES (fndecl))) != NULL)
 	  {
 	    const char *ident = lang_hooks.decl_printable_name (fndecl, 1);
-	    warning_at (tree_nonartificial_location (exp), 0,
+	    warning_at (tree_nonartificial_location (exp),
+			OPT_Wwarning_attribute,
 			"%Kcall to %qs declared with attribute warning: %s",
 			exp, identifier_to_locale (ident),
 			TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
Index: gcc/testsuite/gcc.dg/Wno-warning-attribute.c
===================================================================
--- gcc/testsuite/gcc.dg/Wno-warning-attribute.c	(revision 0)
+++ gcc/testsuite/gcc.dg/Wno-warning-attribute.c	(working copy)
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-Werror -Wno-error=warning-attribute" } */
+
+int f1(void) __attribute__ ((warning("Please avoid f1")));
+int func1(void)
+{
+  return f1(); /* { dg-warning "'f1' declared with attribute warning: Please avoid f1" } */
+}

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

end of thread, other threads:[~2018-11-07 21:04 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-12 10:50 [PATCH] Add option to control warnings added through attribure "warning" Nikolai Merinov
2018-10-12 17:19 ` Martin Sebor
2018-10-15  8:13   ` Nikolai Merinov
2018-10-15 13:36     ` Martin Sebor
2018-10-15 15:57       ` Nikolai Merinov
2018-10-26 12:07         ` Nikolai Merinov
2018-10-26 15:43           ` Martin Sebor
2018-10-26 16:13             ` Jeff Law
2018-11-07 21:04         ` Jeff Law
  -- strict thread matches above, loose matches on Subject: below --
2018-09-30 20:20 Nikolai Merinov

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