public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108747] New: Optimization makes user mistake more dangerous when optimization is disabled by flag -O0
@ 2023-02-10  2:01 alireza at hexosys dot com
  2023-02-10  2:11 ` [Bug c++/108747] Dangerous optimization " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: alireza at hexosys dot com @ 2023-02-10  2:01 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108747
           Summary: Optimization makes user mistake more dangerous when
                    optimization is disabled by flag -O0
           Product: gcc
           Version: og11 (devel/omp/gcc-11)
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alireza at hexosys dot com
  Target Milestone: ---

As we can see below link:
https://godbolt.org/z/ze3nhszxx

although the user had a mistake and create undefined behavior maybe he expected
it because of the -O0 flag, the compiler won't do anything smart and use div
for %. so he thinks his code will work correctly.

I think -the O0 flag means no smarty thing for the compiler.

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

* [Bug c++/108747] Dangerous optimization when optimization is disabled by flag -O0
  2023-02-10  2:01 [Bug c++/108747] New: Optimization makes user mistake more dangerous when optimization is disabled by flag -O0 alireza at hexosys dot com
@ 2023-02-10  2:11 ` pinskia at gcc dot gnu.org
  2023-02-10  2:13 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-10  2:11 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED
            Version|og11 (devel/omp/gcc-11)     |13.0

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>        and     eax, 7


What are you asking about? Why GCC decided to still use %8 here (and do &7)
even with the static_cast?

The reasoning is because constexpr causes a const integer expression here so
the front-end will do the replacement.

There is nothing to fix here really because the user asked the compiler to do
the casting away the const via const_cast and everything.

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

* [Bug c++/108747] Dangerous optimization when optimization is disabled by flag -O0
  2023-02-10  2:01 [Bug c++/108747] New: Optimization makes user mistake more dangerous when optimization is disabled by flag -O0 alireza at hexosys dot com
  2023-02-10  2:11 ` [Bug c++/108747] Dangerous optimization " pinskia at gcc dot gnu.org
@ 2023-02-10  2:13 ` pinskia at gcc dot gnu.org
  2023-02-10  2:20 ` alireza at hexosys dot com
  2023-02-10  3:10 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-10  2:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 54446
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54446&action=edit
original testcase

Next time also please don't just link godbolt but either put the testcase
inline or attach it. Without that context (in the bug report) it was even hard
to figure out what you were asking about.

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

* [Bug c++/108747] Dangerous optimization when optimization is disabled by flag -O0
  2023-02-10  2:01 [Bug c++/108747] New: Optimization makes user mistake more dangerous when optimization is disabled by flag -O0 alireza at hexosys dot com
  2023-02-10  2:11 ` [Bug c++/108747] Dangerous optimization " pinskia at gcc dot gnu.org
  2023-02-10  2:13 ` pinskia at gcc dot gnu.org
@ 2023-02-10  2:20 ` alireza at hexosys dot com
  2023-02-10  3:10 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: alireza at hexosys dot com @ 2023-02-10  2:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from alireza at hexosys dot com ---
I Agree with you that the user has made mistake.

but why does the compiler does this optimization that can change the behavior
of the code, when we explicitly asked her to don't do any optimization when we
set the -O0?

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

* [Bug c++/108747] Dangerous optimization when optimization is disabled by flag -O0
  2023-02-10  2:01 [Bug c++/108747] New: Optimization makes user mistake more dangerous when optimization is disabled by flag -O0 alireza at hexosys dot com
                   ` (2 preceding siblings ...)
  2023-02-10  2:20 ` alireza at hexosys dot com
@ 2023-02-10  3:10 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2023-02-10  3:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
-O0 does not mean "let me write invalid code"

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

end of thread, other threads:[~2023-02-10  3:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-10  2:01 [Bug c++/108747] New: Optimization makes user mistake more dangerous when optimization is disabled by flag -O0 alireza at hexosys dot com
2023-02-10  2:11 ` [Bug c++/108747] Dangerous optimization " pinskia at gcc dot gnu.org
2023-02-10  2:13 ` pinskia at gcc dot gnu.org
2023-02-10  2:20 ` alireza at hexosys dot com
2023-02-10  3:10 ` redi 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).