[Mesa-dev] [PATCH 11/19] anv: Use GNU C empty brace initializer
Emil Velikov
emil.l.velikov at gmail.com
Thu Sep 14 07:29:26 UTC 2017
On 13 September 2017 at 23:31, Ian Romanick <idr at freedesktop.org> wrote:
> On 08/29/2017 10:19 AM, Emil Velikov wrote:
>> On 29 August 2017 at 18:10, Matt Turner <mattst88 at gmail.com> wrote:
>>> On Tue, Aug 29, 2017 at 3:35 AM, Emil Velikov <emil.l.velikov at gmail.com> wrote:
>>>> On 29 August 2017 at 11:11, Eric Engestrom <eric.engestrom at imgtec.com> wrote:
>>>>> On Monday, 2017-08-28 14:57:13 -0700, Matt Turner wrote:
>>>>>> Avoids Clang's warning about the current code:
>>>>>>
>>>>>> warning: suggest braces around initialization of subobject
>>>>>
>>>>> I'm not sure about this patch [1], but everything else in this series is:
>>>> IIRC "{}" is the least likely way to avoid the warnings, across
>>>> GCC/Clang versions.
>>>> It's not part of the C spec, but since it works - not sure how much to bother.
>>>
>>> I'm surprised to hear you say that. I've tested with gcc-4.9.4, 6.4.0,
>>> 7.1.0; and clang-4.0, and none of them warn about {}
>>>
>> Eric corrected me on IRC, but I forgot to mention here - "s/least/most/"
>>
>>> I think when we went through this before (in NIR) we couldn't use {}
>>> because it needs to compile with MSVC, and MSVC doesn't allow that in
>>> C.
>>>
>> Precisely. The "most" portable solution that I know of is memset().
>
> Except memset generates different code. That will clear the padding
> area between fields, and x = {} (and variations there of) do not.
>
>>>> Would be great to have the issue reported (and fixed) in Clang though.
>>>> AFAICT both {0} and {0,} are valid, if memory serves me right.
>>>
>>> I don't really understand the nuances of {0}, {0,}, {{0}}, etc, and I
>>> get the sense that that's the case for nearly everyone else as well.
>>>
>> AFAICT {0} and {0,} should just work everywhere, modulo bugs.
>
> And I believe most of these generate warnings if you enable other
> warning options (see also this patch series
> https://patchwork.freedesktop.org/patch/68141/).
>
Even with maximum amount of warning flags, what gets flagged depends
on compiler + version.
Aka the "module bugs" mentioned above - feel free to skim through the
bug reports linked.
That said - yes, handling these is rather annoying :-\
>> [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119
>> [2] https://bugs.llvm.org/show_bug.cgi?id=21689
>>
-Emil
More information about the mesa-dev
mailing list