public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/48418] New: Bit shift operator >>=
@ 2011-04-02 20:30 lisp2d at lisp2d dot net
2011-04-02 21:07 ` [Bug c/48418] " ebotcazou at gcc dot gnu.org
` (12 more replies)
0 siblings, 13 replies; 14+ messages in thread
From: lisp2d at lisp2d dot net @ 2011-04-02 20:30 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48418
Summary: Bit shift operator >>=
Product: gcc
Version: 4.5.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: lisp2d@lisp2d.net
int x=1000;
x>>=(sizeof(int)<<3);
x is still 1000
In some cases bit shift operator used with variable (not constant) and compiler
didnot show warning. My opinion is that result must be 0.
Remarked code in my program and code to see what's happened.
/*
ULong::ULong(ULInt const&x):value2(){
if(x.uli){
if(sizeof(unsigned int)==sizeof(unsigned long int)){
value2.push_back(static_cast<unsigned int>(x.uli));
return;}
UInt const ibs(sizeof(unsigned int)<<3);
ULInt x2(x);
do{
value2.push_back(static_cast<unsigned int>(x2.uli));
(x2.uli)>>=(ibs.ui);
}while(x2.uli);}}
*/
#include <iostream>
typedef struct{unsigned int i;}si;
int main(void){
unsigned int x=1000;
si w;
w.i=sizeof(unsigned int)<<3;
std::cout<<"x="<<x<<std::endl;
x>>=w.i;
std::cout<<"x>>=w.i -> x="<<x<<std::endl;
x>>=(sizeof(unsigned int)<<3);
std::cout<<"x>>=(sizeof(unsigned int)<<3) -> x="<<x<<std::endl;
x>>=32;
std::cout<<"x>>=32 -> x="<<x<<std::endl;
}
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/48418] Bit shift operator >>=
2011-04-02 20:30 [Bug c/48418] New: Bit shift operator >>= lisp2d at lisp2d dot net
@ 2011-04-02 21:07 ` ebotcazou at gcc dot gnu.org
2011-04-02 21:43 ` d.g.gorbachev at gmail dot com
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2011-04-02 21:07 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48418
Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
CC| |ebotcazou at gcc dot
| |gnu.org
Resolution| |WONTFIX
--- Comment #1 from Eric Botcazou <ebotcazou at gcc dot gnu.org> 2011-04-02 21:06:47 UTC ---
> int x=1000;
> x>>=(sizeof(int)<<3);
>
> x is still 1000
The warning is clear:
t.cc: In function 'void foo()':
t.cc:4:22: warning: right shift count >= width of type
This invokes undefined behavior, any result is acceptable.
> In some cases bit shift operator used with variable (not constant) and compiler
> didnot show warning. My opinion is that result must be 0.
The compiler cannot warn about values computed only at run time. If the shift
amount is >= width of type at run time, this also invokes undefined behavior.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/48418] Bit shift operator >>=
2011-04-02 20:30 [Bug c/48418] New: Bit shift operator >>= lisp2d at lisp2d dot net
2011-04-02 21:07 ` [Bug c/48418] " ebotcazou at gcc dot gnu.org
@ 2011-04-02 21:43 ` d.g.gorbachev at gmail dot com
2011-04-03 11:09 ` [Bug c/48418] [4.5/4.6/4.7 Regression] " rguenth at gcc dot gnu.org
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: d.g.gorbachev at gmail dot com @ 2011-04-02 21:43 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48418
--- Comment #2 from Dmitry Gorbachev <d.g.gorbachev at gmail dot com> 2011-04-02 21:43:15 UTC ---
GCC 4.x regression, for x >= 5:
$ cat > foo.c
unsigned foo(void)
{
#ifdef CONST
const
#endif
unsigned i = sizeof(unsigned) << 3;
unsigned x = 1000;
return x >> i;
}
^D
$ gcc-4.5.0 -O -S foo.c -DCONST
$ gcc-4.4.6 -O -S foo.c -DCONST
foo.c: In function 'foo':
foo.c:8: warning: right shift count >= width of type
g++ works.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/48418] [4.5/4.6/4.7 Regression] Bit shift operator >>=
2011-04-02 20:30 [Bug c/48418] New: Bit shift operator >>= lisp2d at lisp2d dot net
2011-04-02 21:07 ` [Bug c/48418] " ebotcazou at gcc dot gnu.org
2011-04-02 21:43 ` d.g.gorbachev at gmail dot com
@ 2011-04-03 11:09 ` rguenth at gcc dot gnu.org
2011-04-03 11:21 ` joseph at codesourcery dot com
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-04-03 11:09 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48418
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Keywords| |diagnostic
Last reconfirmed| |2011.04.03 11:09:30
CC| |jsm28 at gcc dot gnu.org
Resolution|WONTFIX |
Ever Confirmed|0 |1
Summary|Bit shift operator >>= |[4.5/4.6/4.7 Regression]
| |Bit shift operator >>=
Target Milestone|--- |4.5.3
--- Comment #3 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-04-03 11:09:30 UTC ---
I suppose some of the warning code needs to be updated with the C constexpr
changes. Joseph?
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/48418] [4.5/4.6/4.7 Regression] Bit shift operator >>=
2011-04-02 20:30 [Bug c/48418] New: Bit shift operator >>= lisp2d at lisp2d dot net
` (2 preceding siblings ...)
2011-04-03 11:09 ` [Bug c/48418] [4.5/4.6/4.7 Regression] " rguenth at gcc dot gnu.org
@ 2011-04-03 11:21 ` joseph at codesourcery dot com
2011-04-10 10:47 ` rguenth at gcc dot gnu.org
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: joseph at codesourcery dot com @ 2011-04-03 11:21 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48418
--- Comment #4 from joseph at codesourcery dot com <joseph at codesourcery dot com> 2011-04-03 11:21:27 UTC ---
It's deliberate that folding of references to const variables is now
delayed - and ideally it would move out of the front end altogether.
While decl_constant_value_for_optimization still exists it would be easy
enough to have a second check for this warning in c_fully_fold_internal,
but in general the alternatives (which are not mutually exclusive) are
predictable warnings in the front end that may not catch all cases and may
sometimes warn in unreachable code, and less-predictable middle-end
warnings if the problem operation is reachable (here, if a shift by an
out-of-range constant is found after optimization, which could include
where the variable with the shift amount isn't marked const).
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/48418] [4.5/4.6/4.7 Regression] Bit shift operator >>=
2011-04-02 20:30 [Bug c/48418] New: Bit shift operator >>= lisp2d at lisp2d dot net
` (3 preceding siblings ...)
2011-04-03 11:21 ` joseph at codesourcery dot com
@ 2011-04-10 10:47 ` rguenth at gcc dot gnu.org
2011-04-28 15:23 ` rguenth at gcc dot gnu.org
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-04-10 10:47 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48418
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/48418] [4.5/4.6/4.7 Regression] Bit shift operator >>=
2011-04-02 20:30 [Bug c/48418] New: Bit shift operator >>= lisp2d at lisp2d dot net
` (4 preceding siblings ...)
2011-04-10 10:47 ` rguenth at gcc dot gnu.org
@ 2011-04-28 15:23 ` rguenth at gcc dot gnu.org
2011-08-24 20:52 ` pinskia at gcc dot gnu.org
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-04-28 15:23 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48418
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|4.5.3 |4.5.4
--- Comment #5 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-04-28 14:51:30 UTC ---
GCC 4.5.3 is being released, adjusting target milestone.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/48418] [4.5/4.6/4.7 Regression] Bit shift operator >>=
2011-04-02 20:30 [Bug c/48418] New: Bit shift operator >>= lisp2d at lisp2d dot net
` (5 preceding siblings ...)
2011-04-28 15:23 ` rguenth at gcc dot gnu.org
@ 2011-08-24 20:52 ` pinskia at gcc dot gnu.org
2011-08-25 7:19 ` rguenth at gcc dot gnu.org
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-08-24 20:52 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48418
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P2 |P3
CC| |rguenth at gcc dot gnu.org
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-08-24 20:47:06 UTC ---
Richard, can you explain why this is a P2? the warning is only a regression in
the sense we would warn about about one case but not any more and the code is
undefined at runtime which means we should warn about it in all cases but
currently don't.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/48418] [4.5/4.6/4.7 Regression] Bit shift operator >>=
2011-04-02 20:30 [Bug c/48418] New: Bit shift operator >>= lisp2d at lisp2d dot net
` (6 preceding siblings ...)
2011-08-24 20:52 ` pinskia at gcc dot gnu.org
@ 2011-08-25 7:19 ` rguenth at gcc dot gnu.org
2012-07-02 11:25 ` [Bug c/48418] [4.5/4.6/4.7/4.8 " rguenth at gcc dot gnu.org
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-08-25 7:19 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48418
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
--- Comment #7 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-08-25 06:51:10 UTC ---
Because it's a regression and it affects primary languages / targets. We
shipped with it, so it isn't P1.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/48418] [4.5/4.6/4.7/4.8 Regression] Bit shift operator >>=
2011-04-02 20:30 [Bug c/48418] New: Bit shift operator >>= lisp2d at lisp2d dot net
` (7 preceding siblings ...)
2011-08-25 7:19 ` rguenth at gcc dot gnu.org
@ 2012-07-02 11:25 ` rguenth at gcc dot gnu.org
2013-01-08 14:45 ` [Bug c/48418] [4.6/4.7/4.8 " jakub at gcc dot gnu.org
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-07-02 11:25 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48418
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|4.5.4 |4.6.4
--- Comment #8 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-07-02 11:24:40 UTC ---
The 4.5 branch is being closed, adjusting target milestone.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/48418] [4.6/4.7/4.8 Regression] Bit shift operator >>=
2011-04-02 20:30 [Bug c/48418] New: Bit shift operator >>= lisp2d at lisp2d dot net
` (8 preceding siblings ...)
2012-07-02 11:25 ` [Bug c/48418] [4.5/4.6/4.7/4.8 " rguenth at gcc dot gnu.org
@ 2013-01-08 14:45 ` jakub at gcc dot gnu.org
2013-01-09 14:51 ` jakub at gcc dot gnu.org
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-08 14:45 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48418
--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-01-08 14:44:51 UTC ---
Created attachment 29104
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29104
gcc48-pr48418.patch
Untested fix. To avoid warning twice, this warns in c_fully_fold_internal
only if orig_op1 isn't INTEGER_CST, but op1 is. And on the testcase I found
that in 4.8 my SIZEOF_EXPR C++ changes regressed the testcase too.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/48418] [4.6/4.7/4.8 Regression] Bit shift operator >>=
2011-04-02 20:30 [Bug c/48418] New: Bit shift operator >>= lisp2d at lisp2d dot net
` (9 preceding siblings ...)
2013-01-08 14:45 ` [Bug c/48418] [4.6/4.7/4.8 " jakub at gcc dot gnu.org
@ 2013-01-09 14:51 ` jakub at gcc dot gnu.org
2013-01-09 15:03 ` [Bug c/48418] [4.6/4.7 " jakub at gcc dot gnu.org
2013-02-01 9:11 ` jakub at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-09 14:51 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48418
--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-01-09 14:51:17 UTC ---
Author: jakub
Date: Wed Jan 9 14:51:09 2013
New Revision: 195051
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195051
Log:
PR c/48418
* c-common.c (c_fully_fold_internal): Warn for LSHIFT_EXPR and
RSHIFT_EXPR, if orig_op1 isn't INTEGER_CST, op1 is INTEGER_CST
and is either negative or bigger or equal to type precision
of the first operand.
* typeck.c (cp_build_binary_op): For LSHIFT_EXPR and RSHIFT_EXPR,
call maybe_constant_value for the negative or too big shift
count warnings.
* c-c++-common/pr48418.c: New test.
Added:
trunk/gcc/testsuite/c-c++-common/pr48418.c
Modified:
trunk/gcc/c-family/ChangeLog
trunk/gcc/c-family/c-common.c
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/typeck.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/48418] [4.6/4.7 Regression] Bit shift operator >>=
2011-04-02 20:30 [Bug c/48418] New: Bit shift operator >>= lisp2d at lisp2d dot net
` (10 preceding siblings ...)
2013-01-09 14:51 ` jakub at gcc dot gnu.org
@ 2013-01-09 15:03 ` jakub at gcc dot gnu.org
2013-02-01 9:11 ` jakub at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-09 15:03 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48418
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
Summary|[4.6/4.7/4.8 Regression] |[4.6/4.7 Regression] Bit
|Bit shift operator >>= |shift operator >>=
--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-01-09 15:03:09 UTC ---
Warning regression fixed for 4.8+ for now.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/48418] [4.6/4.7 Regression] Bit shift operator >>=
2011-04-02 20:30 [Bug c/48418] New: Bit shift operator >>= lisp2d at lisp2d dot net
` (11 preceding siblings ...)
2013-01-09 15:03 ` [Bug c/48418] [4.6/4.7 " jakub at gcc dot gnu.org
@ 2013-02-01 9:11 ` jakub at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-02-01 9:11 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48418
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|REOPENED |RESOLVED
Resolution| |FIXED
--- Comment #12 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-02-01 09:11:05 UTC ---
I don't think this is suitable for older branches, for -Werror it might cause
failures where there weren't with older 4.7.x (or 4.6.x) compilers, something
undesirable on release branches if possible.
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2013-02-01 9:11 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-02 20:30 [Bug c/48418] New: Bit shift operator >>= lisp2d at lisp2d dot net
2011-04-02 21:07 ` [Bug c/48418] " ebotcazou at gcc dot gnu.org
2011-04-02 21:43 ` d.g.gorbachev at gmail dot com
2011-04-03 11:09 ` [Bug c/48418] [4.5/4.6/4.7 Regression] " rguenth at gcc dot gnu.org
2011-04-03 11:21 ` joseph at codesourcery dot com
2011-04-10 10:47 ` rguenth at gcc dot gnu.org
2011-04-28 15:23 ` rguenth at gcc dot gnu.org
2011-08-24 20:52 ` pinskia at gcc dot gnu.org
2011-08-25 7:19 ` rguenth at gcc dot gnu.org
2012-07-02 11:25 ` [Bug c/48418] [4.5/4.6/4.7/4.8 " rguenth at gcc dot gnu.org
2013-01-08 14:45 ` [Bug c/48418] [4.6/4.7/4.8 " jakub at gcc dot gnu.org
2013-01-09 14:51 ` jakub at gcc dot gnu.org
2013-01-09 15:03 ` [Bug c/48418] [4.6/4.7 " jakub at gcc dot gnu.org
2013-02-01 9:11 ` jakub 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).