public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99689] New: Initialized local variable becomes uninitialized after use
@ 2021-03-20 20:11 soren.soe at gonsoe dot com
2021-03-20 20:11 ` [Bug c++/99689] " soren.soe at gonsoe dot com
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: soren.soe at gonsoe dot com @ 2021-03-20 20:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99689
Bug ID: 99689
Summary: Initialized local variable becomes uninitialized after
use
Product: gcc
Version: 9.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: soren.soe at gonsoe dot com
Target Milestone: ---
Created attachment 50439
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50439&action=edit
preprocessed file (*.i*) that triggers the bug
% g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/aarch64-linux-gnu/9/lto-wrapper
Target: aarch64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,gm2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-9
--program-prefix=aarch64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support
--enable-plugin --enable-default-pie --with-system-zlib
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch
--enable-fix-cortex-a53-843419 --disable-werror --enable-checking=release
--build=aarch64-linux-gnu --host=aarch64-linux-gnu --target=aarch64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
% cat bug.cpp
#include <cassert>
#include <string>
#include <utility>
#include <vector>
using vec = std::vector<std::pair<std::string, std::string>>;
void
bad()
{
vec v;
v.emplace_back("abc", "def");
v.emplace_back("abc", "def");
v.emplace_back("abc", "def");
v.emplace_back("abc", "def");
v.emplace_back("abc", "def");
unsigned int m = 0;
for (auto& p : v)
m = std::max<unsigned int>(m, p.first.length());
assert(m == 3);
}
int main()
{
bad();
return 0;
}
% g++ -Wall -Wextra -O3 -std=c++14 bug.cpp
% ./a.out
a.out: bug.cpp:79: void bad(): Assertion `m == 3' failed.
Aborted (core dumped)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/99689] Initialized local variable becomes uninitialized after use
2021-03-20 20:11 [Bug c++/99689] New: Initialized local variable becomes uninitialized after use soren.soe at gonsoe dot com
@ 2021-03-20 20:11 ` soren.soe at gonsoe dot com
2021-03-20 20:46 ` [Bug middle-end/99689] " pinskia at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: soren.soe at gonsoe dot com @ 2021-03-20 20:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99689
--- Comment #1 from Soren Soe <soren.soe at gonsoe dot com> ---
Created attachment 50440
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50440&action=edit
source file
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/99689] Initialized local variable becomes uninitialized after use
2021-03-20 20:11 [Bug c++/99689] New: Initialized local variable becomes uninitialized after use soren.soe at gonsoe dot com
2021-03-20 20:11 ` [Bug c++/99689] " soren.soe at gonsoe dot com
@ 2021-03-20 20:46 ` pinskia at gcc dot gnu.org
2021-03-22 8:11 ` marxin at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-03-20 20:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99689
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|c++ |middle-end
Keywords| |wrong-code
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Works for me on the trunk:
GNU C++17 (GCC) version 11.0.1 20210314 (experimental) [master revision
553488851dd:9748870ecd0:87cbac2b7a78fdfda61a6accf13a1fd858f5ccfe]
(aarch64-unknown-linux-gnu)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/99689] Initialized local variable becomes uninitialized after use
2021-03-20 20:11 [Bug c++/99689] New: Initialized local variable becomes uninitialized after use soren.soe at gonsoe dot com
2021-03-20 20:11 ` [Bug c++/99689] " soren.soe at gonsoe dot com
2021-03-20 20:46 ` [Bug middle-end/99689] " pinskia at gcc dot gnu.org
@ 2021-03-22 8:11 ` marxin at gcc dot gnu.org
2021-03-22 8:17 ` jakub at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-03-22 8:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99689
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |WAITING
Ever confirmed|0 |1
Last reconfirmed| |2021-03-22
CC| |marxin at gcc dot gnu.org
--- Comment #3 from Martin Liška <marxin at gcc dot gnu.org> ---
I also cannot reproduce it with any GCC compiler version newer than 8.1.0.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/99689] Initialized local variable becomes uninitialized after use
2021-03-20 20:11 [Bug c++/99689] New: Initialized local variable becomes uninitialized after use soren.soe at gonsoe dot com
` (2 preceding siblings ...)
2021-03-22 8:11 ` marxin at gcc dot gnu.org
@ 2021-03-22 8:17 ` jakub at gcc dot gnu.org
2021-03-22 19:42 ` gnu at gonsoe dot com
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-03-22 8:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99689
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Have you tried with -fpie and whatever other non-default options Ubuntu enables
by default?
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/99689] Initialized local variable becomes uninitialized after use
2021-03-20 20:11 [Bug c++/99689] New: Initialized local variable becomes uninitialized after use soren.soe at gonsoe dot com
` (3 preceding siblings ...)
2021-03-22 8:17 ` jakub at gcc dot gnu.org
@ 2021-03-22 19:42 ` gnu at gonsoe dot com
2021-03-23 1:52 ` gnu at gonsoe dot com
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: gnu at gonsoe dot com @ 2021-03-22 19:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99689
Soren Soe <gnu at gonsoe dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |gnu at gonsoe dot com
--- Comment #5 from Soren Soe <gnu at gonsoe dot com> ---
I've tried all options. Fails only when compiled with -O3.
I looked at assembler code on https://godbolt.org, and it appears that with ARM
gcc9.3 the unsigned int variable is not initialized. The assembler code is
very different if unsigned int is replaced with size_t, or when using -O2, and
appears to show a variable initialized to 0.
void
good()
{
vec v;
v.emplace_back("abc", "def");
v.emplace_back("abc", "def");
v.emplace_back("abc", "def");
v.emplace_back("abc", "def");
v.emplace_back("abc", "def");
size_t m = 0;
for (auto& p : v)
m = std::max(m, p.first.length());
assert(m==3);
}
void
bad()
{
vec v;
v.emplace_back("abc", "def");
v.emplace_back("abc", "def");
v.emplace_back("abc", "def");
v.emplace_back("abc", "def");
v.emplace_back("abc", "def");
unsigned int m = 0;
for (auto& p : v)
m = std::max<unsigned int>(m, p.first.length());
assert(m==3);
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/99689] Initialized local variable becomes uninitialized after use
2021-03-20 20:11 [Bug c++/99689] New: Initialized local variable becomes uninitialized after use soren.soe at gonsoe dot com
` (4 preceding siblings ...)
2021-03-22 19:42 ` gnu at gonsoe dot com
@ 2021-03-23 1:52 ` gnu at gonsoe dot com
2024-02-28 7:26 ` pinskia at gcc dot gnu.org
2024-02-28 7:51 ` pinskia at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: gnu at gonsoe dot com @ 2021-03-23 1:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99689
--- Comment #6 from Soren Soe <gnu at gonsoe dot com> ---
I should maybe mention that the same problem is reproducible using qemu-aarch64
and qemu-aarch64-static on an x86_64 host.
% aarch64-linux-gnu-g++ -O3 -static bug.cpp
% qemu-aarch64-static ./a.out
a.out: bug.cpp:78: void bad(): Assertion `m == 3' failed.
qemu: uncaught target signal 6 (Aborted) - core dumped
Aborted (core dumped)
Works fine with -O2 or the size_t variant I mentioned.
% aarch64-linux-gnu-g++ -v
Using built-in specs.
COLLECT_GCC=aarch64-linux-gnu-g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/aarch64-linux-gnu/9/lto-wrapper
Target: aarch64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,gm2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-9 --enable-shared
--enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/
--enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-libquadmath --disable-libquadmath-support --enable-plugin
--enable-default-pie --with-system-zlib --without-target-system-zlib
--enable-libpth-m2 --enable-multiarch --enable-fix-cortex-a53-843419
--disable-werror --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=aarch64-linux-gnu
--program-prefix=aarch64-linux-gnu- --includedir=/usr/aarch64-linux-gnu/include
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/99689] Initialized local variable becomes uninitialized after use
2021-03-20 20:11 [Bug c++/99689] New: Initialized local variable becomes uninitialized after use soren.soe at gonsoe dot com
` (5 preceding siblings ...)
2021-03-23 1:52 ` gnu at gonsoe dot com
@ 2024-02-28 7:26 ` pinskia at gcc dot gnu.org
2024-02-28 7:51 ` pinskia at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-28 7:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99689
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
GCC 9.3.0 says:
/app/example.cpp:19:18: missed: can't use a fully-masked loop because the
target doesn't have the appropriate masked load or store.
/app/example.cpp:19:18: note: vect_model_load_cost: aligned.
/app/example.cpp:19:18: note: vect_model_load_cost: inside_cost = 2,
prologue_cost = 0 .
/app/example.cpp:19:18: note: ==> examining statement: _2 = (unsigned int)
_24;
/app/example.cpp:19:18: note: vect_is_simple_use: operand # VUSE <.MEM_12>
MEM[(long unsigned intD.17 *)SR.139_80 + 8B], type of def: internal
...
But GCC 9.4.0 says:
/app/example.cpp:19:18: missed: not falling back to elementwise accesses
/app/example.cpp:20:49: missed: not vectorized: relevant stmt not supported:
_24 = MEM[(long unsigned int *)SR.139_80 + 8B];
/app/example.cpp:19:18: missed: bad operation or unsupported loop bound.
/app/example.cpp:19:18: missed: couldn't vectorize loop
/app/example.cpp:20:49: missed: not vectorized: relevant stmt not supported:
_24 = MEM[(long unsigned int *)SR.139_80 + 8B];
/app/example.cpp:9:1: note: vectorized 0 loops in function.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/99689] Initialized local variable becomes uninitialized after use
2021-03-20 20:11 [Bug c++/99689] New: Initialized local variable becomes uninitialized after use soren.soe at gonsoe dot com
` (6 preceding siblings ...)
2024-02-28 7:26 ` pinskia at gcc dot gnu.org
@ 2024-02-28 7:51 ` pinskia at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-28 7:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99689
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |RESOLVED
Target Milestone|--- |9.4
Resolution|--- |FIXED
See Also|https://gcc.gnu.org/bugzill |https://gcc.gnu.org/bugzill
|a/show_bug.cgi?id=102435 |a/show_bug.cgi?id=97236
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed in GCC 9.4.0. Most likely a dup of bug 97236.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-02-28 7:51 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-20 20:11 [Bug c++/99689] New: Initialized local variable becomes uninitialized after use soren.soe at gonsoe dot com
2021-03-20 20:11 ` [Bug c++/99689] " soren.soe at gonsoe dot com
2021-03-20 20:46 ` [Bug middle-end/99689] " pinskia at gcc dot gnu.org
2021-03-22 8:11 ` marxin at gcc dot gnu.org
2021-03-22 8:17 ` jakub at gcc dot gnu.org
2021-03-22 19:42 ` gnu at gonsoe dot com
2021-03-23 1:52 ` gnu at gonsoe dot com
2024-02-28 7:26 ` pinskia at gcc dot gnu.org
2024-02-28 7:51 ` pinskia 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).