public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/59324] New: C++11: -Wsequence-point
@ 2013-11-28  8:23 mathieu.malaterre at gmail dot com
  2015-03-16 16:20 ` [Bug c++/59324] " manu at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: mathieu.malaterre at gmail dot com @ 2013-11-28  8:23 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59324

            Bug ID: 59324
           Summary: C++11: -Wsequence-point
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mathieu.malaterre at gmail dot com

It would be nice to remove the following warning about UB when compiling in
C++11 mode:


$ cat t.cxx
int main()
{
  int b = 1;    
  int m = (b++) + (++b);
  (void)m;
  return 0;
}

$ g++ -std=c++11 -Wsequence-point t.cxx
t.cxx: In function 'int main()':
t.cxx:4:23: warning: operation on 'b' may be undefined [-Wsequence-point]
   int m = (b++) + (++b);
                       ^


$ g++ --version
g++ (Debian 4.8.2-1) 4.8.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/59324] C++11: -Wsequence-point
  2013-11-28  8:23 [Bug c++/59324] New: C++11: -Wsequence-point mathieu.malaterre at gmail dot com
@ 2015-03-16 16:20 ` manu at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: manu at gcc dot gnu.org @ 2015-03-16 16:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59324

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu.org

--- Comment #1 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
Clang also thinks this is UB:

warning: multiple unsequenced modifications to 'b' [-Wunsequenced]
>From gcc-bugs-return-480478-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Mar 16 16:25:15 2015
Return-Path: <gcc-bugs-return-480478-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 62717 invoked by alias); 16 Mar 2015 16:25:15 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 62678 invoked by uid 48); 16 Mar 2015 16:25:07 -0000
From: "vries at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/65443] Don't peel last iteration from loop in transform_to_exit_first_loop
Date: Mon, 16 Mar 2015 16:25:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: tree-optimization
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: vries at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-65443-4-vsyjhz8Hou@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-65443-4@http.gcc.gnu.org/bugzilla/>
References: <bug-65443-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-03/txt/msg01622.txt.bz2
Content-length: 1912

https://gcc.gnu.org/bugzilla/show_bug.cgi?ide443

--- Comment #1 from vries at gcc dot gnu.org ---
Consider test.c, compiled with -O2 -tree-parallelize-loops=2:
...
#include <stdio.h>

extern unsigned int *a;

void
f (unsigned int n)
{
  int i;
  unsigned int sum = 1;

#pragma omp parallel
  {
#pragma omp for
    for (i = 0; i < n; ++i)
      sum += a[i];
  }

  printf ("%u\n", sum);
}
...

Before tranform_to_exit_first_loop, the loop looks like this:
...
  <bb 4>:
  # sum_18 = PHI <1(11), sum_11(6)>
  # ivtmp_25 = PHI <0(11), ivtmp_6(6)>
  i_17 = (int) ivtmp_25;
  _7 = (long unsigned int) i_17;
  _8 = _7 * 4;
  _9 = pretmp_24 + _8;
  _10 = *_9;
  sum_11 = _10 + sum_18;
  i_12 = i_17 + 1;
  i.1_3 = (unsigned int) i_12;
  if (ivtmp_25 < _20)
    goto <bb 6>;
  else
    goto <bb 5>;

  <bb 5>:
  # sum_21 = PHI <sum_11(4), sum_26(8)>
  goto <bb 7>;

  <bb 6>:
  ivtmp_6 = ivtmp_25 + 1;
  goto <bb 4>;
...

You might say that the transformation applied by tranform_to_exit_first_loop is
that all the statements in bb4 before the if are moved past the if, into both
bb5 and bb6.

After, it looks like:
...
  <bb 4>:
  # sum_28 = PHI <1(11), sum_11(6)>
  # ivtmp_29 = PHI <0(11), ivtmp_6(6)>
  if (ivtmp_29 < _20)
    goto <bb 13>;
  else
    goto <bb 14>;

  <bb 13>:
  # sum_18 = PHI <sum_28(4)>
  # ivtmp_25 = PHI <ivtmp_29(4)>
  i_17 = (int) ivtmp_25;
  _7 = (long unsigned int) i_17;
  _8 = _7 * 4;
  _9 = pretmp_24 + _8;
  _10 = *_9;
  sum_11 = _10 + sum_18;
  i_12 = i_17 + 1;
  i.1_3 = (unsigned int) i_12;
  goto <bb 6>;

  <bb 14>:
  # sum_30 = PHI <sum_28(4)>
  ivtmp_31 = _20;
  i_32 = (int) ivtmp_31;
  _33 = (long unsigned int) i_32;
  _34 = _33 * 4;
  _35 = pretmp_24 + _34;
  _36 = *_35;
  sum_37 = _36 + sum_30;
  i_38 = i_32 + 1;
  i.1_39 = (unsigned int) i_38;

  <bb 5>:
  # sum_21 = PHI <sum_37(14), sum_26(8)>
  goto <bb 7>;

  <bb 6>:
  ivtmp_6 = ivtmp_25 + 1;
  goto <bb 4>;
...


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-03-16 16:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-28  8:23 [Bug c++/59324] New: C++11: -Wsequence-point mathieu.malaterre at gmail dot com
2015-03-16 16:20 ` [Bug c++/59324] " manu at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).