public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/63420] New: GCC 4.8.2: Bitshift second operand range not as per manual.
@ 2014-09-30 17:19 aainscow at uk dot ibm.com
2014-10-06 17:25 ` [Bug c/63420] " jakub at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: aainscow at uk dot ibm.com @ 2014-09-30 17:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63420
Bug ID: 63420
Summary: GCC 4.8.2: Bitshift second operand range not as per
manual.
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: aainscow at uk dot ibm.com
Created attachment 33625
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33625&action=edit
Demo code
Most likely this is simply a problem with the GCC manual.
The GCC documentation states (30th Sept 2014):
--
You use the left-shift operator << to shift its first operand's bits to the
left. The second operand denotes the number of bit places to shift. Bits
shifted off the left side of the value are discarded; new bits added on the
right side will all be 0.
...
For both << and >>, if the second operand is greater than the bit-width of the
first operand, or the second operand is negative, the behavior is undefined.
--
NOTE: "greater than" not "greater than or equal to".
The following code should therefore not be undefined and return 0.
int main() {
int a = sizeof(int)*8;
return ((int)1) << a;
}
However:
aainscow@morwenna:~/cake$ gcc bitshift_bug.c
aainscow@morwenna:~/cake$ ./a.out ; echo $?
1
Most likely this is a problem with documentation.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/63420] GCC 4.8.2: Bitshift second operand range not as per manual.
2014-09-30 17:19 [Bug c/63420] New: GCC 4.8.2: Bitshift second operand range not as per manual aainscow at uk dot ibm.com
@ 2014-10-06 17:25 ` jakub at gcc dot gnu.org
2014-10-06 17:29 ` jakub at gcc dot gnu.org
2015-02-26 19:00 ` mpolacek at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-10-06 17:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63420
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
What matters is what the C and C++ standards (differs between different
versions thereof) say, the documentation is certainly wrong, but even some
shifts where
shift count is smaller than bitsize can be invalid in some standards (for
signed types)).
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/63420] GCC 4.8.2: Bitshift second operand range not as per manual.
2014-09-30 17:19 [Bug c/63420] New: GCC 4.8.2: Bitshift second operand range not as per manual aainscow at uk dot ibm.com
2014-10-06 17:25 ` [Bug c/63420] " jakub at gcc dot gnu.org
@ 2014-10-06 17:29 ` jakub at gcc dot gnu.org
2015-02-26 19:00 ` mpolacek at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-10-06 17:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63420
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Can you explain where in the documentation you find it though?
I can't find any wording like that.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/63420] GCC 4.8.2: Bitshift second operand range not as per manual.
2014-09-30 17:19 [Bug c/63420] New: GCC 4.8.2: Bitshift second operand range not as per manual aainscow at uk dot ibm.com
2014-10-06 17:25 ` [Bug c/63420] " jakub at gcc dot gnu.org
2014-10-06 17:29 ` jakub at gcc dot gnu.org
@ 2015-02-26 19:00 ` mpolacek at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-02-26 19:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63420
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
CC| |mpolacek at gcc dot gnu.org
Resolution|--- |INVALID
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
That words come from http://www.gnu.org/software/gnu-c-manual/gnu-c-manual.html
That is not a part of GCC though, so closing.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-02-26 17:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-30 17:19 [Bug c/63420] New: GCC 4.8.2: Bitshift second operand range not as per manual aainscow at uk dot ibm.com
2014-10-06 17:25 ` [Bug c/63420] " jakub at gcc dot gnu.org
2014-10-06 17:29 ` jakub at gcc dot gnu.org
2015-02-26 19:00 ` mpolacek 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).