public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/115291] New: armv8-a GCC emits float32x2_t loads from uninitialized stack @ 2024-05-30 10:02 akihiko.odaki at daynix dot com 2024-05-30 12:14 ` [Bug c++/115291] " pinskia at gcc dot gnu.org ` (2 more replies) 0 siblings, 3 replies; 4+ messages in thread From: akihiko.odaki at daynix dot com @ 2024-05-30 10:02 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115291 Bug ID: 115291 Summary: armv8-a GCC emits float32x2_t loads from uninitialized stack Product: gcc Version: 14.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: akihiko.odaki at daynix dot com Target Milestone: --- Run the following commands: git clone https://gitlab.com/libeigen/eigen.git -b 38b9cc263bbaeb03ce408a4e26084543a6c0dedb cat main.cpp <<'EOF' #include "Eigen/Core" auto f() -> Eigen::Matrix2f { return Eigen::Matrix2f::Zero(); } auto g() -> Eigen::Vector2f { auto v = Eigen::Product(f(), Eigen::Vector2f::Zero()); return v; } EOF c++ -Ieigen -O1 -DNDEBUG main.cpp -S Now main.s looks like: .arch armv8-a .file "main.cpp" .text .align 2 .global _Z1fv .type _Z1fv, %function _Z1fv: .LFB13241: .cfi_startproc mov x0, x8 str wzr, [x8] str wzr, [x8, 4] str wzr, [x8, 8] str wzr, [x8, 12] ret .cfi_endproc .LFE13241: .size _Z1fv, .-_Z1fv .align 2 .global _Z1gv .type _Z1gv, %function _Z1gv: .LFB13246: .cfi_startproc sub sp, sp, #16 .cfi_def_cfa_offset 16 mov x0, x8 movi v30.2s, 0 ldr d31, [sp] fmul v31.2s, v31.2s, v30.2s ldr d29, [sp, 8] fmla v31.2s, v29.2s, v30.2s str d31, [x8] add sp, sp, 16 .cfi_def_cfa_offset 0 ret .cfi_endproc .LFE13246: .size _Z1gv, .-_Z1gv .align 2 .type _GLOBAL__sub_I__Z1fv, %function _GLOBAL__sub_I__Z1fv: .LFB14439: .cfi_startproc ret .cfi_endproc .LFE14439: .size _GLOBAL__sub_I__Z1fv, .-_GLOBAL__sub_I__Z1fv .ident "GCC: (GNU) 14.1.1 20240507 (Red Hat 14.1.1-1)" .section .note.GNU-stack,"",@progbits In _Z1gv, "ldr d31, [sp]" loads values from nowhere. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/115291] armv8-a GCC emits float32x2_t loads from uninitialized stack 2024-05-30 10:02 [Bug c++/115291] New: armv8-a GCC emits float32x2_t loads from uninitialized stack akihiko.odaki at daynix dot com @ 2024-05-30 12:14 ` pinskia at gcc dot gnu.org 2024-05-30 22:39 ` pinskia at gcc dot gnu.org 2024-05-31 7:03 ` akihiko.odaki at daynix dot com 2 siblings, 0 replies; 4+ messages in thread From: pinskia at gcc dot gnu.org @ 2024-05-30 12:14 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115291 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |INVALID Status|UNCONFIRMED |RESOLVED --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- D.198035 = f (); [return slot optimization] v.m_lhs = &D.198035; MEM[(struct CwiseNullaryOp *)&v + 8B] ={v} {CLOBBER(bob)}; MEM[(struct scalar_constant_op *)&v + 12B] ={v} {CLOBBER(bob)}; MEM[(struct scalar_constant_op *)&v + 12B].m_other = 0.0; D.198035 ={v} {CLOBBER(eos)}; _6 = &MEM[(struct Matrix *)_4(D)].D.198029; _12 = v.m_lhs; auto v = Eigen::Product(f(), Eigen::Vector2f::Zero()); The bug is there is a temporary created for the return value of f but that is destoried at the end of the full statement but the product does not happen until afterwards in the use of v happens. Rewriting the code like: ``` auto t = f(); auto v = Eigen::Product(t, Eigen::Vector2f::Zero()); ``` Fixes the code. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/115291] armv8-a GCC emits float32x2_t loads from uninitialized stack 2024-05-30 10:02 [Bug c++/115291] New: armv8-a GCC emits float32x2_t loads from uninitialized stack akihiko.odaki at daynix dot com 2024-05-30 12:14 ` [Bug c++/115291] " pinskia at gcc dot gnu.org @ 2024-05-30 22:39 ` pinskia at gcc dot gnu.org 2024-05-31 7:03 ` akihiko.odaki at daynix dot com 2 siblings, 0 replies; 4+ messages in thread From: pinskia at gcc dot gnu.org @ 2024-05-30 22:39 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115291 --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- See https://libeigen.gitlab.io/docs/TopicPitfalls.html section "C++11 and the auto keyword" explictly. "In short: do not use the auto keywords with Eigen's expressions, unless you are 100% sure about what you are doing. In particular, do not use the auto keyword as a replacement for a Matrix<> type." Describes the issue you are having. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/115291] armv8-a GCC emits float32x2_t loads from uninitialized stack 2024-05-30 10:02 [Bug c++/115291] New: armv8-a GCC emits float32x2_t loads from uninitialized stack akihiko.odaki at daynix dot com 2024-05-30 12:14 ` [Bug c++/115291] " pinskia at gcc dot gnu.org 2024-05-30 22:39 ` pinskia at gcc dot gnu.org @ 2024-05-31 7:03 ` akihiko.odaki at daynix dot com 2 siblings, 0 replies; 4+ messages in thread From: akihiko.odaki at daynix dot com @ 2024-05-31 7:03 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115291 --- Comment #3 from Akihiko Odaki <akihiko.odaki at daynix dot com> --- You are right. Sorry for bothering and thanks for pointing out the issue in the code (and even the relevant documentation!) ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-05-31 7:03 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-05-30 10:02 [Bug c++/115291] New: armv8-a GCC emits float32x2_t loads from uninitialized stack akihiko.odaki at daynix dot com 2024-05-30 12:14 ` [Bug c++/115291] " pinskia at gcc dot gnu.org 2024-05-30 22:39 ` pinskia at gcc dot gnu.org 2024-05-31 7:03 ` akihiko.odaki at daynix 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).