public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109750] New: Incorrect code generated for shifted bit field
@ 2023-05-05 17:27 jim.gray at atos dot net
2023-05-05 17:33 ` [Bug c++/109750] " pinskia at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: jim.gray at atos dot net @ 2023-05-05 17:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109750
Bug ID: 109750
Summary: Incorrect code generated for shifted bit field
Product: gcc
Version: 9.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jim.gray at atos dot net
Target Milestone: ---
Created attachment 55008
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55008&action=edit
Tar file with source, assembly listing, compile script, executable
Attached is a simple program that shows the problem encountered.
Bad output when compiling with GCC compiler on Ubuntu
~/gcc-bug$ ./gccbug
Source = 000000020000
Target = 000000000200
Target = 1777777777760000000200
Good output when compiling with MS C++ compiler on Windows:
>gccbug
Source = 000000020000
Target = 000000000200
Target = 020000000200
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/109750] Incorrect code generated for shifted bit field
2023-05-05 17:27 [Bug c++/109750] New: Incorrect code generated for shifted bit field jim.gray at atos dot net
@ 2023-05-05 17:33 ` pinskia at gcc dot gnu.org
2023-05-05 17:37 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-05 17:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109750
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
((UI64)source.sH.lower)
The question is source.sH.lower promoted to int rather than the underlying
type. Note clang has the same behavior as GCC here even. So I am thinking this
is a bug in MSVC rather than GCC ... (or some implemented defined behavior and
both are correct).
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/109750] Incorrect code generated for shifted bit field
2023-05-05 17:27 [Bug c++/109750] New: Incorrect code generated for shifted bit field jim.gray at atos dot net
2023-05-05 17:33 ` [Bug c++/109750] " pinskia at gcc dot gnu.org
@ 2023-05-05 17:37 ` pinskia at gcc dot gnu.org
2023-05-05 17:57 ` jim.gray at atos dot net
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-05 17:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109750
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
MSVC bug:
In [conv.prom] p5 the standard says:
"A prvalue for an integral bit-field (11.4.9) can be converted to a prvalue of
type int if int can represent all the values of the bit-field;"
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/109750] Incorrect code generated for shifted bit field
2023-05-05 17:27 [Bug c++/109750] New: Incorrect code generated for shifted bit field jim.gray at atos dot net
2023-05-05 17:33 ` [Bug c++/109750] " pinskia at gcc dot gnu.org
2023-05-05 17:37 ` pinskia at gcc dot gnu.org
@ 2023-05-05 17:57 ` jim.gray at atos dot net
2023-05-05 18:00 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jim.gray at atos dot net @ 2023-05-05 17:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109750
--- Comment #3 from jim.gray at atos dot net ---
The "correct" answer is also provided by the Intel C++ compiler,
so apparently GCC is the odd one out.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/109750] Incorrect code generated for shifted bit field
2023-05-05 17:27 [Bug c++/109750] New: Incorrect code generated for shifted bit field jim.gray at atos dot net
` (2 preceding siblings ...)
2023-05-05 17:57 ` jim.gray at atos dot net
@ 2023-05-05 18:00 ` pinskia at gcc dot gnu.org
2023-05-05 18:13 ` jim.gray at atos dot net
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-05 18:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109750
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to jim.gray from comment #3)
> The "correct" answer is also provided by the Intel C++ compiler,
> so apparently GCC is the odd one out.
I think MSVC is the odd one out really. see below.
You can also do the testing yourself at https://godbolt.org/ to see that.
Huh? Maybe ICC on windows gives a different answer than ICC on Linux.
Which might make sense if ICC on Windows is trying to provide bug for bug
compatibility with MSVC.
ICC gives:
icc: remark #10441: The Intel(R) C++ Compiler Classic (ICC) is deprecated and
will be removed from product release in the second half of 2023. The Intel(R)
oneAPI DPC++/C++ Compiler (ICX) is the recommended compiler moving forward.
Please transition to use this compiler. Use '-diag-disable=10441' to disable
this message.
ASM generation compiler returned: 0
icc: remark #10441: The Intel(R) C++ Compiler Classic (ICC) is deprecated and
will be removed from product release in the second half of 2023. The Intel(R)
oneAPI DPC++/C++ Compiler (ICX) is the recommended compiler moving forward.
Please transition to use this compiler. Use '-diag-disable=10441' to disable
this message.
Execution build compiler returned: 0
Program returned: 0
Example showing GCC bug:
Source = 000000020000
Target = 000000000200
Target = 1777777777760000000200
clang gives:
<source>:103:14: warning: unused parameter 'argc' [-Wunused-parameter]
int main(int argc, char *argv[]) {
^
<source>:103:26: warning: unused parameter 'argv' [-Wunused-parameter]
int main(int argc, char *argv[]) {
^
2 warnings generated.
ASM generation compiler returned: 0
<source>:103:14: warning: unused parameter 'argc' [-Wunused-parameter]
int main(int argc, char *argv[]) {
^
<source>:103:26: warning: unused parameter 'argv' [-Wunused-parameter]
int main(int argc, char *argv[]) {
^
2 warnings generated.
Execution build compiler returned: 0
Program returned: 0
Example showing GCC bug:
Source = 000000020000
Target = 000000000200
Target = 1777777777760000000200
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/109750] Incorrect code generated for shifted bit field
2023-05-05 17:27 [Bug c++/109750] New: Incorrect code generated for shifted bit field jim.gray at atos dot net
` (3 preceding siblings ...)
2023-05-05 18:00 ` pinskia at gcc dot gnu.org
@ 2023-05-05 18:13 ` jim.gray at atos dot net
2023-05-05 18:21 ` pinskia at gcc dot gnu.org
2023-05-05 18:22 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: jim.gray at atos dot net @ 2023-05-05 18:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109750
--- Comment #5 from jim.gray at atos dot net ---
I don't know if it makes any difference, but I ran with an older version of the
Intel C++ compiler on Linux, with the results below:
Good output when compiling with the Intel C++ compiler
on CentOS Linux release 7.7.1908
[builder@7f936516e827 ~]$ icc --version
icc (ICC) 17.0.2 20170213
Copyright (C) 1985-2017 Intel Corporation. All rights reserved.
[builder@af80ebc5f176 gccbug]$ icc gccbug.cpp
[builder@af80ebc5f176 gccbug]$
[builder@af80ebc5f176 gccbug]$ ls -l
total 28
-rwxrwxr-x 1 builder builder 22592 May 5 18:02 a.out
-rw-rw-r-- 1 builder builder 3553 May 5 18:02 gccbug.cpp
[builder@af80ebc5f176 gccbug]$
[builder@af80ebc5f176 gccbug]$ ./a.out
Example showing GCC bug:
Source = 000000020000
Target = 000000000200
Target = 020000000200
Example showing workaround for bug:
Source = 000000020000
Target = 000000000200
Temp = 000000020000
Temp = 020000000000
Target = 020000000200
[builder@af80ebc5f176 gccbug]$
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/109750] Incorrect code generated for shifted bit field
2023-05-05 17:27 [Bug c++/109750] New: Incorrect code generated for shifted bit field jim.gray at atos dot net
` (4 preceding siblings ...)
2023-05-05 18:13 ` jim.gray at atos dot net
@ 2023-05-05 18:21 ` pinskia at gcc dot gnu.org
2023-05-05 18:22 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-05 18:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109750
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
icc version 2021.1.2 (gcc version 10.1.0 compatibility)
Has the same behavior as GCC.
While:
icc version 19.0.0.117 (gcc version 8.2.0 compatibility)
had the MSVC behavior
clang has the same behavior as GCC since clang 3.0.0.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/109750] Incorrect code generated for shifted bit field
2023-05-05 17:27 [Bug c++/109750] New: Incorrect code generated for shifted bit field jim.gray at atos dot net
` (5 preceding siblings ...)
2023-05-05 18:21 ` pinskia at gcc dot gnu.org
@ 2023-05-05 18:22 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-05 18:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109750
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is also definitely a bug in MSVC and should reported to them.
ICC fixed their bug already even.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-05-05 18:22 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-05 17:27 [Bug c++/109750] New: Incorrect code generated for shifted bit field jim.gray at atos dot net
2023-05-05 17:33 ` [Bug c++/109750] " pinskia at gcc dot gnu.org
2023-05-05 17:37 ` pinskia at gcc dot gnu.org
2023-05-05 17:57 ` jim.gray at atos dot net
2023-05-05 18:00 ` pinskia at gcc dot gnu.org
2023-05-05 18:13 ` jim.gray at atos dot net
2023-05-05 18:21 ` pinskia at gcc dot gnu.org
2023-05-05 18:22 ` 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).