public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101277] New: Assert in constructor generates code for statically checkable expression
@ 2021-07-01 6:26 p.waydan at gmail dot com
2021-07-01 7:24 ` [Bug c++/101277] " rguenth at gcc dot gnu.org
2021-07-09 3:51 ` p.waydan at gmail dot com
0 siblings, 2 replies; 3+ messages in thread
From: p.waydan at gmail dot com @ 2021-07-01 6:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101277
Bug ID: 101277
Summary: Assert in constructor generates code for statically
checkable expression
Product: gcc
Version: 10.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: p.waydan at gmail dot com
Target Milestone: ---
Created attachment 51092
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51092&action=edit
-v output for Compiler Explorer compilation
Given the following code segment compiled with C++14 and above:
#include <cassert>
struct Positive { constexpr Positive(int x) {assert(x >= 0);} };
int foo(Positive) {return 1;}
int main()
{
return foo(Positive{1});
}
GCC 10.1 and 10.2 will generate code to check if the assertion is true even
though it is statically checkable. This occurs for optimization levels -O0,
-Os, and -O2, but the assertion is elided for optimization levels -Og, -O1, and
-O3.
The assertion is always elided in GCC 9.4 and below as well as GCC 10.3 and
above.
Please see https://godbolt.org/z/3scPr1P7W for a comparison of x86-64 assembly
with different GCC versions.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/101277] Assert in constructor generates code for statically checkable expression
2021-07-01 6:26 [Bug c++/101277] New: Assert in constructor generates code for statically checkable expression p.waydan at gmail dot com
@ 2021-07-01 7:24 ` rguenth at gcc dot gnu.org
2021-07-09 3:51 ` p.waydan at gmail dot com
1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-07-01 7:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101277
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Keywords| |missed-optimization
Status|UNCONFIRMED |RESOLVED
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
There's simply differences in inlining. It looks like GCC 10.3 improved here
as well as GCC 11 and trunk - so there's nothing to see (GCC 10.3 is a bugfix
release over 10.1/10.2)?
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/101277] Assert in constructor generates code for statically checkable expression
2021-07-01 6:26 [Bug c++/101277] New: Assert in constructor generates code for statically checkable expression p.waydan at gmail dot com
2021-07-01 7:24 ` [Bug c++/101277] " rguenth at gcc dot gnu.org
@ 2021-07-09 3:51 ` p.waydan at gmail dot com
1 sibling, 0 replies; 3+ messages in thread
From: p.waydan at gmail dot com @ 2021-07-09 3:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101277
--- Comment #2 from Daniel Way <p.waydan at gmail dot com> ---
Thank you Richard. I'm glad this was fixed in 10.3 and later. Unfortunately the
latest arm-none-eabi-gcc toolchain is based on 10.2, but that's out of the GCC
maintainers' purview.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-07-09 3:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-01 6:26 [Bug c++/101277] New: Assert in constructor generates code for statically checkable expression p.waydan at gmail dot com
2021-07-01 7:24 ` [Bug c++/101277] " rguenth at gcc dot gnu.org
2021-07-09 3:51 ` p.waydan at gmail dot com
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).