public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "burnus at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/105345] New: [OpenMP] Wrong iteration loop count when mixing signed and unsigned
Date: Fri, 22 Apr 2022 10:38:21 +0000	[thread overview]
Message-ID: <bug-105345-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 105345
           Summary: [OpenMP] Wrong iteration loop count when mixing signed
                    and unsigned
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: openmp, wrong-code
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
                CC: frederik at gcc dot gnu.org, jakub at gcc dot gnu.org
  Target Milestone: ---

The following program has a loop count of 0 without OpenMP (-fno-openmp)
but is executed 1010 times with -fopenmp in GCC.


The problem is that the following is not honored:

"If var has a signed integer type and the var operand of test-expr after usual
 arithmetic conversions has an unsigned integer type then the loop iteration
count
 is computed from lb, test-expr and incr using an unsigned integer type
corresponding
 to the type of var."  (OpenMP 5.2, 4.4.2 OpenMP Loop-Iteration Spaces and
Vectors)
 (Likewise: OpenMP 5.1, 2.11.1 Canonical Loop Nest Form)

The wording seems to be new since OpenMP 5.1 - and to ensure that the OpenMP
and C loop counts are the same:


int
main ()
{
  #pragma omp for
  for (int i = -1000; i < 10u; ++i) {
    __builtin_printf("%d\n", i);
    __builtin_abort ();
  } 
}

                 reply	other threads:[~2022-04-22 10:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-105345-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).