public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/101508] New: Possible undefined behaviour in cpp program using "unsigned" type starting from GCC 9
@ 2021-07-19 10:25 pnarsing at mathworks dot com
  2021-07-19 10:46 ` [Bug tree-optimization/101508] [9/10/11/12 Regression] Possible undefined behaviour in cpp program using "unsigned" type starting with r9-4145 jakub at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: pnarsing at mathworks dot com @ 2021-07-19 10:25 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101508
           Summary: Possible undefined behaviour in cpp program using
                    "unsigned" type starting from GCC 9
           Product: gcc
           Version: 10.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pnarsing at mathworks dot com
  Target Milestone: ---

Hi Team,

I'm observing an optimization issue while compiling with GCC 10.3 .
On investigating figured that issue is reproducible in GCC 9 as well .

This can be reproduced by simple test code mentioned below :

------------------------------------------------------

using int_type = unsigned int; // works without "unsigned"
int_type constexpr start{0};   // works if >= 1
int_type constexpr stop{3};    // works if <= 2
int_type constexpr mult{2};    // works if != 2

int main()
{
    int result = 0;
    for(int_type aa = start; aa < stop; ++aa)
    {
        int_type const bb = aa * mult; // works if volatile
        if (aa > bb)
        {
            return 99;
        }
        ++result;
    }
    return result; // should be == stop
}

----------------------------------------------------------------

This code snippet returns 99 instead of 3 .

You can check the following link to see the issue reproducibility:
https://godbolt.org/z/zd79PPKfn

Modifying compiler option to -O1 and -Og avoids the issue.

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

end of thread, other threads:[~2022-01-24 12:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-19 10:25 [Bug tree-optimization/101508] New: Possible undefined behaviour in cpp program using "unsigned" type starting from GCC 9 pnarsing at mathworks dot com
2021-07-19 10:46 ` [Bug tree-optimization/101508] [9/10/11/12 Regression] Possible undefined behaviour in cpp program using "unsigned" type starting with r9-4145 jakub at gcc dot gnu.org
2021-07-19 11:00 ` rguenth at gcc dot gnu.org
2022-01-17 14:02 ` rguenth at gcc dot gnu.org
2022-01-24 12:15 ` cvs-commit at gcc dot gnu.org
2022-01-24 12:44 ` [Bug tree-optimization/101508] [9/10/11 " rguenth at gcc dot gnu.org
2022-01-24 12:46 ` rguenth 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).