public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95226] New: Faulty aggregate initialization of vector with struct with float
@ 2020-05-19 23:30 fboranek at atlas dot cz
2020-05-20 6:52 ` [Bug c++/95226] " fboranek at gmail dot com
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: fboranek at atlas dot cz @ 2020-05-19 23:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95226
Bug ID: 95226
Summary: Faulty aggregate initialization of vector with struct
with float
Product: gcc
Version: 8.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: fboranek at atlas dot cz
Target Milestone: ---
# Steps to reproduce
//prog.cc
#include <vector>
#include <iostream>
struct T {
uint32_t a;
float b {.8};
};
int main()
{
T t = {1};
std::vector<T> tt = {{1}, {2}};
std::cout << t.a << ", " << t.b << std::endl;
std::cout << tt[0].a << ", " << tt[0].b << std::endl;
std::cout << tt[1].a << ", " << tt[1].b << std::endl;
}
// g++ prog.cc -Wall -Wextra -std=c++17
For gcc 9.3.0, 9.2.0, 9.1.0, 8.1.0 the behavior is correct and output of the
program is:
1, 0.8
1, 0.8
1, 0.8
For gcc 8.3.0, 8.2.0 the output of the program is:
1, 0.8
1, -1.58819e-23
1072273817, 2.8026e-45
The second object in the vector is wrongly initialized.
The code can be fixed by changing of initialization of float T::b to {.8f}, {0}
or {}. It seems that only initialization by double is affected.
I used wandbox.org to test diffrent version of gcc and prevous and newer
version are OK. It sound like regression in 8.3.0 and 8.2.0, but 8.3.0 is in a
current stable Debian, which worried me.
# Used gcc from Debina Buster (current stable)
gcc (Debian 8.3.0-6) 8.3.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/95226] Faulty aggregate initialization of vector with struct with float
2020-05-19 23:30 [Bug c++/95226] New: Faulty aggregate initialization of vector with struct with float fboranek at atlas dot cz
@ 2020-05-20 6:52 ` fboranek at gmail dot com
2021-04-21 1:26 ` [Bug c++/95226] [8 Regression] " pinskia at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: fboranek at gmail dot com @ 2020-05-20 6:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95226
--- Comment #1 from Frantisek Boranek <fboranek at gmail dot com> ---
Luckily, the behaviour is the same on old stable Stretch as on Buster. So this
version is also affected, but it is probably not serious as was my first
impression.
gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/95226] [8 Regression] Faulty aggregate initialization of vector with struct with float
2020-05-19 23:30 [Bug c++/95226] New: Faulty aggregate initialization of vector with struct with float fboranek at atlas dot cz
2020-05-20 6:52 ` [Bug c++/95226] " fboranek at gmail dot com
@ 2021-04-21 1:26 ` pinskia at gcc dot gnu.org
2021-05-14 13:39 ` jakub at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-04-21 1:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95226
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |8.1.0, 9.1.0, 9.2.0, 9.3.0
Summary|Faulty aggregate |[8 Regression] Faulty
|initialization of vector |aggregate initialization of
|with struct with float |vector with struct with
| |float
Target Milestone|--- |8.5
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/95226] [8 Regression] Faulty aggregate initialization of vector with struct with float
2020-05-19 23:30 [Bug c++/95226] New: Faulty aggregate initialization of vector with struct with float fboranek at atlas dot cz
2020-05-20 6:52 ` [Bug c++/95226] " fboranek at gmail dot com
2021-04-21 1:26 ` [Bug c++/95226] [8 Regression] " pinskia at gcc dot gnu.org
@ 2021-05-14 13:39 ` jakub at gcc dot gnu.org
2021-05-14 14:27 ` jakub at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-05-14 13:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95226
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
CC| |jakub at gcc dot gnu.org
Target Milestone|8.5 |9.0
Status|UNCONFIRMED |RESOLVED
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The GCC 8 branch is being closed, fixed in GCC 9.1.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/95226] [8 Regression] Faulty aggregate initialization of vector with struct with float
2020-05-19 23:30 [Bug c++/95226] New: Faulty aggregate initialization of vector with struct with float fboranek at atlas dot cz
` (2 preceding siblings ...)
2021-05-14 13:39 ` jakub at gcc dot gnu.org
@ 2021-05-14 14:27 ` jakub at gcc dot gnu.org
2021-05-14 14:31 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-05-14 14:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95226
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org,
| |mpolacek at gcc dot gnu.org
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Seems on the 8 branch this regressed with
r8-8138-gbdc2c1ea35c16d3bbd3711430d8035dd54cfcf20
change aka PR85873 fix.
Slightly simplified testcase:
#include <vector>
struct T {
unsigned a;
float b {8.};
};
int main()
{
T t = {1};
std::vector<T> tt = {{1}, {2}};
if (t.a != 1 || t.b != 8.0f || tt[0].a != 1 || tt[0].b != 8.0f || tt[1].a !=
2 || tt[1].b != 8.0f)
__builtin_abort ();
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/95226] [8 Regression] Faulty aggregate initialization of vector with struct with float
2020-05-19 23:30 [Bug c++/95226] New: Faulty aggregate initialization of vector with struct with float fboranek at atlas dot cz
` (3 preceding siblings ...)
2021-05-14 14:27 ` jakub at gcc dot gnu.org
@ 2021-05-14 14:31 ` cvs-commit at gcc dot gnu.org
2023-06-02 14:09 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-05-14 14:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95226
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:4206171605de65df9674a14dd9db75bf4f4ed037
commit r12-801-g4206171605de65df9674a14dd9db75bf4f4ed037
Author: Jakub Jelinek <jakub@redhat.com>
Date: Fri May 14 16:29:49 2021 +0200
testsuite: Add testcase for already fixed PR [PR95226]
2021-05-14 Jakub Jelinek <jakub@redhat.com>
PR c++/95226
* g++.dg/cpp1y/pr95226.C: New test.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/95226] [8 Regression] Faulty aggregate initialization of vector with struct with float
2020-05-19 23:30 [Bug c++/95226] New: Faulty aggregate initialization of vector with struct with float fboranek at atlas dot cz
` (4 preceding siblings ...)
2021-05-14 14:31 ` cvs-commit at gcc dot gnu.org
@ 2023-06-02 14:09 ` cvs-commit at gcc dot gnu.org
2024-02-05 22:25 ` cvs-commit at gcc dot gnu.org
2024-02-05 22:25 ` cvs-commit at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-06-02 14:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95226
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:
https://gcc.gnu.org/g:e7cc4d703bceb9095316c106eba0d1939c6c8044
commit r14-1498-ge7cc4d703bceb9095316c106eba0d1939c6c8044
Author: Jason Merrill <jason@redhat.com>
Date: Thu Jun 1 14:41:07 2023 -0400
varasm: check float size
In PR95226, the testcase was failing because we tried to output_constant a
NOP_EXPR to float from a double REAL_CST, and so we output a double where
the caller wanted a float. That doesn't happen anymore, but with the
output_constant hunk we will ICE in that situation rather than emit the
wrong number of bytes.
Part of the problem was that initializer_constant_valid_p_1 returned true
for that NOP_EXPR, because it compared the sizes of integer types but not
floating-point types. So the C++ front end assumed it didn't need to fold
the initializer.
PR c++/95226
gcc/ChangeLog:
* varasm.cc (output_constant) [REAL_TYPE]: Check that sizes match.
(initializer_constant_valid_p_1): Compare float precision.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/95226] [8 Regression] Faulty aggregate initialization of vector with struct with float
2020-05-19 23:30 [Bug c++/95226] New: Faulty aggregate initialization of vector with struct with float fboranek at atlas dot cz
` (5 preceding siblings ...)
2023-06-02 14:09 ` cvs-commit at gcc dot gnu.org
@ 2024-02-05 22:25 ` cvs-commit at gcc dot gnu.org
2024-02-05 22:25 ` cvs-commit at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-05 22:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95226
--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:
https://gcc.gnu.org/g:470f501f31a4bdb9fa04c691ca7db2915ac3ae5b
commit r12-10136-g470f501f31a4bdb9fa04c691ca7db2915ac3ae5b
Author: Jason Merrill <jason@redhat.com>
Date: Thu Jun 1 14:41:07 2023 -0400
varasm: check float size [PR109359]
In PR95226, the testcase was failing because we tried to output_constant a
NOP_EXPR to float from a double REAL_CST, and so we output a double where
the caller wanted a float. That doesn't happen anymore, but with the
output_constant hunk we will ICE in that situation rather than emit the
wrong number of bytes.
Part of the problem was that initializer_constant_valid_p_1 returned true
for that NOP_EXPR, because it compared the sizes of integer types but not
floating-point types. So the C++ front end assumed it didn't need to fold
the initializer.
This also fixed the test for PR109359.
PR c++/95226
PR c++/109359
gcc/ChangeLog:
* varasm.cc (output_constant) [REAL_TYPE]: Check that sizes match.
(initializer_constant_valid_p_1): Compare float precision.
gcc/testsuite/ChangeLog:
* g++.dg/ext/frounding-math1.C: New test.
(cherry picked from commit e7cc4d703bceb9095316c106eba0d1939c6c8044)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/95226] [8 Regression] Faulty aggregate initialization of vector with struct with float
2020-05-19 23:30 [Bug c++/95226] New: Faulty aggregate initialization of vector with struct with float fboranek at atlas dot cz
` (6 preceding siblings ...)
2024-02-05 22:25 ` cvs-commit at gcc dot gnu.org
@ 2024-02-05 22:25 ` cvs-commit at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-05 22:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95226
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:
https://gcc.gnu.org/g:9b8e82ab45d1ad976a824cfd7c9bd2640c8bc8e3
commit r13-8282-g9b8e82ab45d1ad976a824cfd7c9bd2640c8bc8e3
Author: Jason Merrill <jason@redhat.com>
Date: Thu Jun 1 14:41:07 2023 -0400
varasm: check float size [PR109359]
In PR95226, the testcase was failing because we tried to output_constant a
NOP_EXPR to float from a double REAL_CST, and so we output a double where
the caller wanted a float. That doesn't happen anymore, but with the
output_constant hunk we will ICE in that situation rather than emit the
wrong number of bytes.
Part of the problem was that initializer_constant_valid_p_1 returned true
for that NOP_EXPR, because it compared the sizes of integer types but not
floating-point types. So the C++ front end assumed it didn't need to fold
the initializer.
This also fixed the test for PR109359.
PR c++/95226
PR c++/109359
gcc/ChangeLog:
* varasm.cc (output_constant) [REAL_TYPE]: Check that sizes match.
(initializer_constant_valid_p_1): Compare float precision.
gcc/testsuite/ChangeLog:
* g++.dg/ext/frounding-math1.C: New test.
(cherry picked from commit e7cc4d703bceb9095316c106eba0d1939c6c8044)
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-02-05 22:25 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-19 23:30 [Bug c++/95226] New: Faulty aggregate initialization of vector with struct with float fboranek at atlas dot cz
2020-05-20 6:52 ` [Bug c++/95226] " fboranek at gmail dot com
2021-04-21 1:26 ` [Bug c++/95226] [8 Regression] " pinskia at gcc dot gnu.org
2021-05-14 13:39 ` jakub at gcc dot gnu.org
2021-05-14 14:27 ` jakub at gcc dot gnu.org
2021-05-14 14:31 ` cvs-commit at gcc dot gnu.org
2023-06-02 14:09 ` cvs-commit at gcc dot gnu.org
2024-02-05 22:25 ` cvs-commit at gcc dot gnu.org
2024-02-05 22:25 ` cvs-commit 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).