lkml.org 
[lkml]   [2017]   [May]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [Patch v2] mm/vmscan: fix unsequenced modification and access warning
I have discussed this with our gcc guys and here is what they say:

On Wed 10-05-17 10:38:44, Michal Hocko wrote:
[...]
> But I
> still do not understand which part of the code is undefined and why. My
> reading and understanding of the C specification is that
> struct A {
> int a;
> int b;
> };
>
> struct A f = { .a = c = foo(c), .b = c};
>
> as long as foo(c) doesn't have any side effects because because .a is
> initialized before b and the assignment ordering will make sure that c
> is initialized before a.
>
> 6.7.8 par 19 (ISO/IEC 9899)
> 19 The initialization shall occur in initializer list order, each
> initializer provided for a particular subobject overriding any
> previously listed initializer for the same subobject; all subobjects
> that are not initialized explicitly shall be initialized implicitly
> the same as objects that have static storage duration.
>
> So is my understanding of the specification wrong or is this a bug in
> -Wunsequenced in Clang?

: This is not the reason why the above is okay. The following part:
: { .a = c = ..., .b = c }
: is okay because there's a sequence point after each full expression, and
: an initializer is a full expression, so there's a sequence point between
: both initializers. The following part:
: { ... c = foo(c) ... }
: is okay as well, because there's a sequence point after evaluating all
: arguments and before the actual call (otherwise the common 'i=next(i)'
: idiom doesn't work). So both constructs that potentially could be sources
: of sequence point violations actually aren't and hence okay. clangs
: warning is invalid.

I guess it is worth reporting this to clang bugzilla. Could you take
care of that Nick?
--
Michal Hocko
SUSE Labs

\
 
 \ /
  Last update: 2017-05-16 10:28    [W:0.072 / U:13.164 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site