public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: PR35503 - warn for restrict pointer (-Wrestrict)
@ 2016-08-29 13:21 Eric Gallager
  2016-08-29 14:28 ` Marek Polacek
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Gallager @ 2016-08-29 13:21 UTC (permalink / raw)
  To: Prathamesh Kulkarni
  Cc: Jason Merrill, gcc Patches, Marek Polacek, Joseph S. Myers

On 8/28/16, Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org> wrote:
> On 26 August 2016 at 21:25, Jason Merrill <jason@redhat.com> wrote:
>> On Fri, Aug 26, 2016 at 7:39 AM, Prathamesh Kulkarni
>> <prathamesh.kulkarni@linaro.org> wrote:
>>> However with C++FE it appears TYPE_RESTRICT is not set for the
>>> parameters (buf and fmt)
>>> and hence the warning doesn't get emitted for C++.
>>> C FE sets TYPE_RESTRICT for them. I am not sure how to workaround this
>>> issue, and would be grateful for suggestions.
>>
>> In the C++ FE you can see TYPE_RESTRICT on the types of the
>> DECL_ARGUMENTS of the function.
> Thanks for the suggestions, I could indeed see TYPE_RESTRICT set on
> DECL_ARGUMENTS.
> The attached patch warns for both C and C++ with -Wrestrict, and I
> have put it under -Wall.
> I suppose we don't want to warn for null pointer args ?
> for eg:
> void f(int *restrict x, int *y);
>
> void foo(void)
> {
>   f(NULL, NULL) ?
> }
>
> However I suppose warning for pointer constants other than zero is desirable
> ?
> I am not sure whether restrict is valid for obj-c/obj-c++, so I have
> just kept it to C and C++
> in the patch. Should the warning also be included for obj-c and obj-c++ FE's
> ?
> Boostrapped and tested on x86_64-unknown-linux-gnu.
> OK to commit ?
>
> Thanks,
> Prathamesh
>


I tried this patch on my fork of gdb-binutils and got a few warnings
from it. Would it be possible to have the caret point to the argument
mentioned, instead of the function name? And also print the option
name? E.g., instead of the current:

or32-opc.c: In function ‘or32_print_register’:
or32-opc.c:956:3: warning: passing argument 1 to restrict qualified
parameter aliases with argument 3
   sprintf (disassembled, "%sr%d", disassembled, regnum);
   ^~~~~~~

could it look like:

or32-opc.c: In function ‘or32_print_register’:
or32-opc.c:956:3: warning: passing argument 1 to restrict qualified
parameter aliases with argument 3 [-Wrestrict]
   sprintf (disassembled, "%sr%d", disassembled, regnum);
            ^~~~~~~~~~~~

instead?
Just an idea. Either way, I hope this patch goes in.
Thanks,
Eric

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

* Re: PR35503 - warn for restrict pointer (-Wrestrict)
  2016-08-29 13:21 PR35503 - warn for restrict pointer (-Wrestrict) Eric Gallager
@ 2016-08-29 14:28 ` Marek Polacek
  2016-08-29 16:54   ` Jason Merrill
  0 siblings, 1 reply; 7+ messages in thread
From: Marek Polacek @ 2016-08-29 14:28 UTC (permalink / raw)
  To: Eric Gallager
  Cc: Prathamesh Kulkarni, Jason Merrill, gcc Patches, Joseph S. Myers

On Mon, Aug 29, 2016 at 09:20:53AM -0400, Eric Gallager wrote:
> I tried this patch on my fork of gdb-binutils and got a few warnings
> from it. Would it be possible to have the caret point to the argument
> mentioned, instead of the function name? And also print the option
> name? E.g., instead of the current:
> 
> or32-opc.c: In function ‘or32_print_register’:
> or32-opc.c:956:3: warning: passing argument 1 to restrict qualified
> parameter aliases with argument 3
>    sprintf (disassembled, "%sr%d", disassembled, regnum);
>    ^~~~~~~
> 
> could it look like:
> 
> or32-opc.c: In function ‘or32_print_register’:
> or32-opc.c:956:3: warning: passing argument 1 to restrict qualified
> parameter aliases with argument 3 [-Wrestrict]
>    sprintf (disassembled, "%sr%d", disassembled, regnum);
>             ^~~~~~~~~~~~
> 
> instead?

I didn't try to implement it, but I think this should be fairly easy to
achieve in the C FE, because c_parser_postfix_expression_after_primary
has arg_loc, which is a vector of parameter locations.

	Marek

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

* Re: PR35503 - warn for restrict pointer (-Wrestrict)
  2016-08-29 14:28 ` Marek Polacek
@ 2016-08-29 16:54   ` Jason Merrill
  2016-08-30 11:41     ` Eric Gallager
  0 siblings, 1 reply; 7+ messages in thread
From: Jason Merrill @ 2016-08-29 16:54 UTC (permalink / raw)
  To: Marek Polacek
  Cc: Eric Gallager, Prathamesh Kulkarni, gcc Patches, Joseph S. Myers

On Mon, Aug 29, 2016 at 10:28 AM, Marek Polacek <polacek@redhat.com> wrote:
> On Mon, Aug 29, 2016 at 09:20:53AM -0400, Eric Gallager wrote:
>> I tried this patch on my fork of gdb-binutils and got a few warnings
>> from it. Would it be possible to have the caret point to the argument
>> mentioned, instead of the function name? And also print the option
>> name? E.g., instead of the current:
>>
>> or32-opc.c: In function ‘or32_print_register’:
>> or32-opc.c:956:3: warning: passing argument 1 to restrict qualified
>> parameter aliases with argument 3
>>    sprintf (disassembled, "%sr%d", disassembled, regnum);
>>    ^~~~~~~
>>
>> could it look like:
>>
>> or32-opc.c: In function ‘or32_print_register’:
>> or32-opc.c:956:3: warning: passing argument 1 to restrict qualified
>> parameter aliases with argument 3 [-Wrestrict]
>>    sprintf (disassembled, "%sr%d", disassembled, regnum);
>>             ^~~~~~~~~~~~
>>
>> instead?
>
> I didn't try to implement it, but I think this should be fairly easy to
> achieve in the C FE, because c_parser_postfix_expression_after_primary
> has arg_loc, which is a vector of parameter locations.

The C++ FE doesn't have this currently, but it could be added without
too much trouble: in cp_parser_parenthesized_expression_list, extract
the locations from the cp_expr return value of
cp_parser_assignment_expression, and then pass the locations back up
to cp_parser_postfix_expression.

Jason

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

* Re: PR35503 - warn for restrict pointer (-Wrestrict)
  2016-08-29 16:54   ` Jason Merrill
@ 2016-08-30 11:41     ` Eric Gallager
  2016-08-30 11:57       ` Prathamesh Kulkarni
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Gallager @ 2016-08-30 11:41 UTC (permalink / raw)
  To: Jason Merrill
  Cc: Marek Polacek, Prathamesh Kulkarni, gcc Patches, Joseph S. Myers

On 8/29/16, Jason Merrill <jason@redhat.com> wrote:
> On Mon, Aug 29, 2016 at 10:28 AM, Marek Polacek <polacek@redhat.com> wrote:
>> On Mon, Aug 29, 2016 at 09:20:53AM -0400, Eric Gallager wrote:
>>> I tried this patch on my fork of gdb-binutils and got a few warnings
>>> from it. Would it be possible to have the caret point to the argument
>>> mentioned, instead of the function name? And also print the option
>>> name? E.g., instead of the current:
>>>
>>> or32-opc.c: In function ‘or32_print_register’:
>>> or32-opc.c:956:3: warning: passing argument 1 to restrict qualified
>>> parameter aliases with argument 3
>>>    sprintf (disassembled, "%sr%d", disassembled, regnum);
>>>    ^~~~~~~
>>>
>>> could it look like:
>>>
>>> or32-opc.c: In function ‘or32_print_register’:
>>> or32-opc.c:956:3: warning: passing argument 1 to restrict qualified
>>> parameter aliases with argument 3 [-Wrestrict]
>>>    sprintf (disassembled, "%sr%d", disassembled, regnum);
>>>             ^~~~~~~~~~~~
>>>
>>> instead?
>>
>> I didn't try to implement it, but I think this should be fairly easy to
>> achieve in the C FE, because c_parser_postfix_expression_after_primary
>> has arg_loc, which is a vector of parameter locations.
>
> The C++ FE doesn't have this currently, but it could be added without
> too much trouble: in cp_parser_parenthesized_expression_list, extract
> the locations from the cp_expr return value of
> cp_parser_assignment_expression, and then pass the locations back up
> to cp_parser_postfix_expression.
>
> Jason
>


On the topic of how to get this warning working with various
frontends, is there any reason why the Objective C frontend doesn't
handle -Wrestrict? Currently when trying to use it, it just says:

cc1obj: warning: command line option '-Wrestrict' is valid for C/C++
but not for ObjC

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

* Re: PR35503 - warn for restrict pointer (-Wrestrict)
  2016-08-30 11:41     ` Eric Gallager
@ 2016-08-30 11:57       ` Prathamesh Kulkarni
  2016-08-30 22:15         ` Mike Stump
  0 siblings, 1 reply; 7+ messages in thread
From: Prathamesh Kulkarni @ 2016-08-30 11:57 UTC (permalink / raw)
  To: Eric Gallager; +Cc: Jason Merrill, Marek Polacek, gcc Patches, Joseph S. Myers

On 30 August 2016 at 17:11, Eric Gallager <egall@gwmail.gwu.edu> wrote:
> On 8/29/16, Jason Merrill <jason@redhat.com> wrote:
>> On Mon, Aug 29, 2016 at 10:28 AM, Marek Polacek <polacek@redhat.com> wrote:
>>> On Mon, Aug 29, 2016 at 09:20:53AM -0400, Eric Gallager wrote:
>>>> I tried this patch on my fork of gdb-binutils and got a few warnings
>>>> from it. Would it be possible to have the caret point to the argument
>>>> mentioned, instead of the function name? And also print the option
>>>> name? E.g., instead of the current:
>>>>
>>>> or32-opc.c: In function ‘or32_print_register’:
>>>> or32-opc.c:956:3: warning: passing argument 1 to restrict qualified
>>>> parameter aliases with argument 3
>>>>    sprintf (disassembled, "%sr%d", disassembled, regnum);
>>>>    ^~~~~~~
>>>>
>>>> could it look like:
>>>>
>>>> or32-opc.c: In function ‘or32_print_register’:
>>>> or32-opc.c:956:3: warning: passing argument 1 to restrict qualified
>>>> parameter aliases with argument 3 [-Wrestrict]
>>>>    sprintf (disassembled, "%sr%d", disassembled, regnum);
>>>>             ^~~~~~~~~~~~
>>>>
>>>> instead?
>>>
>>> I didn't try to implement it, but I think this should be fairly easy to
>>> achieve in the C FE, because c_parser_postfix_expression_after_primary
>>> has arg_loc, which is a vector of parameter locations.
>>
>> The C++ FE doesn't have this currently, but it could be added without
>> too much trouble: in cp_parser_parenthesized_expression_list, extract
>> the locations from the cp_expr return value of
>> cp_parser_assignment_expression, and then pass the locations back up
>> to cp_parser_postfix_expression.
>>
>> Jason
>>
>
>
> On the topic of how to get this warning working with various
> frontends, is there any reason why the Objective C frontend doesn't
> handle -Wrestrict? Currently when trying to use it, it just says:
>
> cc1obj: warning: command line option '-Wrestrict' is valid for C/C++
> but not for ObjC
Hi Eric,
I am not sure if restrict is valid for ObjC/Obj-C++ and hence didn't
add the option for these front-ends.
If it is valid, I will enable the option for ObjC and Obj-C++.

Thanks,
Prathamesh

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

* Re: PR35503 - warn for restrict pointer (-Wrestrict)
  2016-08-30 11:57       ` Prathamesh Kulkarni
@ 2016-08-30 22:15         ` Mike Stump
  2016-08-31 15:58           ` Prathamesh Kulkarni
  0 siblings, 1 reply; 7+ messages in thread
From: Mike Stump @ 2016-08-30 22:15 UTC (permalink / raw)
  To: Prathamesh Kulkarni
  Cc: Eric Gallager, Jason Merrill, Marek Polacek, gcc Patches,
	Joseph S. Myers

On Aug 30, 2016, at 4:57 AM, Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org> wrote:
> 
> On 30 August 2016 at 17:11, Eric Gallager <egall@gwmail.gwu.edu> wrote:
>> On 8/29/16, Jason Merrill <jason@redhat.com> wrote:
>>> On Mon, Aug 29, 2016 at 10:28 AM, Marek Polacek <polacek@redhat.com> wrote:
>>>> On Mon, Aug 29, 2016 at 09:20:53AM -0400, Eric Gallager wrote:
>>>>> I tried this patch on my fork of gdb-binutils and got a few warnings
>>>>> from it. Would it be possible to have the caret point to the argument
>>>>> mentioned, instead of the function name? And also print the option
>>>>> name? E.g., instead of the current:
>>>>> 
>>>>> or32-opc.c: In function ‘or32_print_register’:
>>>>> or32-opc.c:956:3: warning: passing argument 1 to restrict qualified
>>>>> parameter aliases with argument 3
>>>>>   sprintf (disassembled, "%sr%d", disassembled, regnum);
>>>>>   ^~~~~~~
>>>>> 
>>>>> could it look like:
>>>>> 
>>>>> or32-opc.c: In function ‘or32_print_register’:
>>>>> or32-opc.c:956:3: warning: passing argument 1 to restrict qualified
>>>>> parameter aliases with argument 3 [-Wrestrict]
>>>>>   sprintf (disassembled, "%sr%d", disassembled, regnum);
>>>>>            ^~~~~~~~~~~~
>>>>> 
>>>>> instead?
>>>> 
>>>> I didn't try to implement it, but I think this should be fairly easy to
>>>> achieve in the C FE, because c_parser_postfix_expression_after_primary
>>>> has arg_loc, which is a vector of parameter locations.
>>> 
>>> The C++ FE doesn't have this currently, but it could be added without
>>> too much trouble: in cp_parser_parenthesized_expression_list, extract
>>> the locations from the cp_expr return value of
>>> cp_parser_assignment_expression, and then pass the locations back up
>>> to cp_parser_postfix_expression.
>>> 
>>> Jason
>>> 
>> 
>> 
>> On the topic of how to get this warning working with various
>> frontends, is there any reason why the Objective C frontend doesn't
>> handle -Wrestrict? Currently when trying to use it, it just says:
>> 
>> cc1obj: warning: command line option '-Wrestrict' is valid for C/C++
>> but not for ObjC
> Hi Eric,
> I am not sure if restrict is valid for ObjC/Obj-C++ and hence didn't
> add the option for these front-ends.
> If it is valid, I will enable the option for ObjC and Obj-C++.

This is wrong, C/C++ options should always be ObjC/ObjC++ options.

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

* Re: PR35503 - warn for restrict pointer (-Wrestrict)
  2016-08-30 22:15         ` Mike Stump
@ 2016-08-31 15:58           ` Prathamesh Kulkarni
  0 siblings, 0 replies; 7+ messages in thread
From: Prathamesh Kulkarni @ 2016-08-31 15:58 UTC (permalink / raw)
  To: Mike Stump
  Cc: Eric Gallager, Jason Merrill, Marek Polacek, gcc Patches,
	Joseph S. Myers

On 31 August 2016 at 03:45, Mike Stump <mikestump@comcast.net> wrote:
> On Aug 30, 2016, at 4:57 AM, Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org> wrote:
>>
>> On 30 August 2016 at 17:11, Eric Gallager <egall@gwmail.gwu.edu> wrote:
>>> On 8/29/16, Jason Merrill <jason@redhat.com> wrote:
>>>> On Mon, Aug 29, 2016 at 10:28 AM, Marek Polacek <polacek@redhat.com> wrote:
>>>>> On Mon, Aug 29, 2016 at 09:20:53AM -0400, Eric Gallager wrote:
>>>>>> I tried this patch on my fork of gdb-binutils and got a few warnings
>>>>>> from it. Would it be possible to have the caret point to the argument
>>>>>> mentioned, instead of the function name? And also print the option
>>>>>> name? E.g., instead of the current:
>>>>>>
>>>>>> or32-opc.c: In function ‘or32_print_register’:
>>>>>> or32-opc.c:956:3: warning: passing argument 1 to restrict qualified
>>>>>> parameter aliases with argument 3
>>>>>>   sprintf (disassembled, "%sr%d", disassembled, regnum);
>>>>>>   ^~~~~~~
>>>>>>
>>>>>> could it look like:
>>>>>>
>>>>>> or32-opc.c: In function ‘or32_print_register’:
>>>>>> or32-opc.c:956:3: warning: passing argument 1 to restrict qualified
>>>>>> parameter aliases with argument 3 [-Wrestrict]
>>>>>>   sprintf (disassembled, "%sr%d", disassembled, regnum);
>>>>>>            ^~~~~~~~~~~~
>>>>>>
>>>>>> instead?
>>>>>
>>>>> I didn't try to implement it, but I think this should be fairly easy to
>>>>> achieve in the C FE, because c_parser_postfix_expression_after_primary
>>>>> has arg_loc, which is a vector of parameter locations.
>>>>
>>>> The C++ FE doesn't have this currently, but it could be added without
>>>> too much trouble: in cp_parser_parenthesized_expression_list, extract
>>>> the locations from the cp_expr return value of
>>>> cp_parser_assignment_expression, and then pass the locations back up
>>>> to cp_parser_postfix_expression.
>>>>
>>>> Jason
>>>>
>>>
>>>
>>> On the topic of how to get this warning working with various
>>> frontends, is there any reason why the Objective C frontend doesn't
>>> handle -Wrestrict? Currently when trying to use it, it just says:
>>>
>>> cc1obj: warning: command line option '-Wrestrict' is valid for C/C++
>>> but not for ObjC
>> Hi Eric,
>> I am not sure if restrict is valid for ObjC/Obj-C++ and hence didn't
>> add the option for these front-ends.
>> If it is valid, I will enable the option for ObjC and Obj-C++.
>
> This is wrong, C/C++ options should always be ObjC/ObjC++ options.
Thanks, I will add the warning for ObjC and ObjC++.

Thanks,
Prathamesh
>

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

end of thread, other threads:[~2016-08-31 15:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-29 13:21 PR35503 - warn for restrict pointer (-Wrestrict) Eric Gallager
2016-08-29 14:28 ` Marek Polacek
2016-08-29 16:54   ` Jason Merrill
2016-08-30 11:41     ` Eric Gallager
2016-08-30 11:57       ` Prathamesh Kulkarni
2016-08-30 22:15         ` Mike Stump
2016-08-31 15:58           ` Prathamesh Kulkarni

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