Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1642301 > unrolled thread

Re: [Patch v2] mm/vmscan: fix unsequenced modification and access warning

Started byMichal Hocko <mhocko@kernel.org>
First post2017-05-16 10:30 +0200
Last post2017-05-17 05:10 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [Patch v2] mm/vmscan: fix unsequenced modification and access  warning Michal Hocko <mhocko@kernel.org> - 2017-05-16 10:30 +0200
    Re: [Patch v2] mm/vmscan: fix unsequenced modification and access  warning Nick Desaulniers <nick.desaulniers@gmail.com> - 2017-05-17 05:10 +0200

#1642301 — Re: [Patch v2] mm/vmscan: fix unsequenced modification and access warning

FromMichal Hocko <mhocko@kernel.org>
Date2017-05-16 10:30 +0200
SubjectRe: [Patch v2] mm/vmscan: fix unsequenced modification and access warning
Message-ID<tHG1H-3fa-7@gated-at.bofh.it>
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

[toc] | [next] | [standalone]


#1642925

FromNick Desaulniers <nick.desaulniers@gmail.com>
Date2017-05-17 05:10 +0200
Message-ID<tHXvz-634-3@gated-at.bofh.it>
In reply to#1642301
> I guess it is worth reporting this to clang bugzilla. Could you take
> care of that Nick?

Done: https://bugs.llvm.org//show_bug.cgi?id=33065

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web