This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PR35503 - warn for restrict pointer
- From: Prathamesh Kulkarni <prathamesh dot kulkarni at linaro dot org>
- To: Joseph Myers <joseph at codesourcery dot com>
- Cc: Martin Sebor <msebor at gmail dot com>, David Malcolm <dmalcolm at redhat dot com>, Richard Biener <rguenther at suse dot de>, Tom de Vries <Tom_deVries at mentor dot com>, gcc Patches <gcc-patches at gcc dot gnu dot org>, Marek Polacek <polacek at redhat dot com>, Jason Merrill <jason at redhat dot com>
- Date: Fri, 14 Oct 2016 01:46:26 +0530
- Subject: Re: PR35503 - warn for restrict pointer
- Authentication-results: sourceware.org; auth=none
- References: <CAAgBjMkRNk3f47mXwZ6J_MyMHQym4vo3+zXCZ1R6jjrqDkKRYA@mail.gmail.com> <fcf386ee-6e1c-fb81-d43f-7e825978e0ee@mentor.com> <CAAgBjM=yQGLhxmc155Eg2ggSys0u+z8ieZebxVcoC3h5O7dk0Q@mail.gmail.com> <181560f0-c738-cff9-9002-101686da4c14@mentor.com> <alpine.LSU.2.11.1609010842570.26629@t29.fhfr.qr> <CAAgBjMnakS3C2LX3HLrABJvN3artp-MYJZr_5VZ9Z_ULe+5cwQ@mail.gmail.com> <1472838245.5595.183.camel@redhat.com> <CAAgBjMmDH2tU7HbdFhcotm0NioUs0txnjWhGcSSYnRcEMu-_=g@mail.gmail.com> <b21cb9a4-0233-166a-a293-878b0ebda9c9@gmail.com> <CAAgBjMniry2QSMzoVc5TVDsXgizoQ0RK-U=xGM1hPwYeWzTDGg@mail.gmail.com> <alpine.DEB.2.20.1609201301280.3495@digraph.polyomino.org.uk> <CAAgBjMn4TdXN901wHtgs1TKnAvGA9CHiiCbzVm1R1Tv4-mgMrw@mail.gmail.com> <alpine.DEB.2.20.1609221741380.19208@digraph.polyomino.org.uk> <CAAgBjMkAL=PwFAosgvHuKT0hpRvwbtdX0h5CTaf+Pwwev1J73A@mail.gmail.com>
On 7 October 2016 at 10:33, Prathamesh Kulkarni
<prathamesh.kulkarni@linaro.org> wrote:
> On 22 September 2016 at 23:15, Joseph Myers <joseph@codesourcery.com> wrote:
>> On Thu, 22 Sep 2016, Prathamesh Kulkarni wrote:
>>
>>> Would that be acceptable ? I am not sure how to make %Z check if the
>>> argument has type vec<int> *
>>> since vec<int> is not really a builtin C type.
>>> Could you suggest me a better solution so that the format checker will check
>>> if arg has type vec<int> * instead of checking if it's just a pointer ?
>>> Also for testing, should I create a testcase in g++.dg since
>>> gcc.dg/format/ tests are C-only ?
>>
>> If it's C++-only then it would need to be in g++.dg.
>>
>> The way we handle GCC-specific types in checking these formats is that the
>> code using these formats has to define typedefs which the format-checking
>> code then looks up. In most cases it can just look up names like
>> location_t or tree, but for HOST_WIDE_INT it looks up
>> __gcc_host_wide_int__ which the user must have defined as a typedef.
>> Probably that's the way to go in this case: the user must do "typedef
>> vec<int> __gcc_vec_int__;" or similar, and the code looks up
>> __gcc_vec_int__.
> Thanks for the suggestions. To keep it simple, instead of vec<int>,
> I made %Z take two args: int *v, unsigned len, and prints elements in
> v having length == len.
> Is that OK ?
>
> Bootstrapped+tested on x86_64-unknown-linux-gnu.
> As pointed out earlier in the thread, the patch can give false positives because
> it only checks whether parameters are qualified with restrict, not how
> parameters
> are used inside the function. For instance it warned for example 10
> mentioned in n1570
> under section 6.7.3.1 - "Formal definition of restrict".
> Should we keep the warning in Wall or keep it in Wextra ?
> The attached patch enables it with Wall.
Ping for c, c-family changes:
https://gcc.gnu.org/ml/gcc-patches/2016-10/msg00446.html
Thanks,
Prathamesh
>
> Thanks,
> Prathamesh
>>
>> --
>> Joseph S. Myers
>> joseph@codesourcery.com