This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Implement a warning for bogus sizeof(pointer) / sizeof(pointer[0])
- From: Jason Merrill <jason at redhat dot com>
- To: Bernd Edlinger <bernd dot edlinger at hotmail dot de>
- Cc: Martin Sebor <msebor at gmail dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, Joseph Myers <joseph at codesourcery dot com>, Jeff Law <law at redhat dot com>, Richard Biener <rguenther at suse dot de>, Jakub Jelinek <jakub at redhat dot com>, Marek Polacek <polacek at redhat dot com>
- Date: Wed, 3 May 2017 09:14:07 -0400
- Subject: Re: [PATCH] Implement a warning for bogus sizeof(pointer) / sizeof(pointer[0])
- Authentication-results: sourceware.org; auth=none
- References: <AM4PR0701MB2162D22EC7A12EB0797E231DE41B0@AM4PR0701MB2162.eurprd07.prod.outlook.com> <776bb206-7b8e-1878-5411-3f1cdaabac05@gmail.com> <HE1PR0701MB2169D85858BE3B158B4CD3DBE41D0@HE1PR0701MB2169.eurprd07.prod.outlook.com> <20432ae0-2c58-42a0-cc71-dd128187af45@gmail.com> <AM4PR0701MB2162E9E0B096CBC57645F05CE4130@AM4PR0701MB2162.eurprd07.prod.outlook.com> <c2630692-a843-4396-3c78-12149bf284c4@gmail.com> <AM4PR0701MB216244DC6B64C2EA6C282103E4130@AM4PR0701MB2162.eurprd07.prod.outlook.com> <CADzB+2nAEoFxUNjJNd0_hZWuvc2YL=CvJgLZLNNH9dJ=WTkxEw@mail.gmail.com> <AM4PR0701MB21629746249A715558DE10FFE4170@AM4PR0701MB2162.eurprd07.prod.outlook.com>
On Tue, May 2, 2017 at 9:26 AM, Bernd Edlinger
<bernd.edlinger@hotmail.de> wrote:
> On 05/01/17 17:54, Jason Merrill wrote:
>> On Fri, Apr 28, 2017 at 1:05 PM, Bernd Edlinger
>> <bernd.edlinger@hotmail.de> wrote:
>>> On 04/28/17 17:29, Martin Sebor wrote:
>>>> On 04/28/2017 08:12 AM, Bernd Edlinger wrote:
>>>>>
>>>>> Do you want me to change the %qT format strings to %T ?
>>>>
>>>> Yes, with the surrounding %< and %> the nested directives should
>>>> use the unquoted forms, otherwise the printer would end up quoting
>>>> both the whole expression and the type operand.
>>>>
>>>> FWIW, to help avoid this mistake, I think this might be something
>>>> for GCC -Wformat to warn on and the pretty-printer to detect (and
>>>> ICE on).
>>>>
>>>
>>> Ah, now I understand. That's pretty advanced.
>>>
>>> Here is the modified patch with correct quoting of the expression.
>>>
>>> Bootstrap and reg-testing on x86_64-pc-linux-gnu.
>>
>>> * cp-gimplify.c (cp_fold): Implement the -Wsizeof_pointer_div warning.
>>
>> I think this warning belongs in cp_build_binary_op rather than cp_fold.
>>
>
> Done, as suggested.
The pattern in that function is to treat all *_DIV_EXPR the same; I
don't think we need to break that pattern with this patch. So please
move the new code after the other DIV case labels. With that the C++
changes are OK.
Jason