------- Comment #4 from pinskia at gcc dot gnu dot org 2007-07-08 10:19 ------- (In reply to comment #3) > > We don't reject as invalid code either: > > unsigned char p; > > unsigned char p1 = p & 0; > > Why should we? There is no overflow here, you mean that p is not constant? I > think we have two issues in the first testcase, one is folding (X op 0), the > other is converting 512 to uchar before performing the operation. Am I wrong?
Yes, the converting 512 to uchar is a valid optimization. That is: (char)(((int) a) & b) is the same as: a & ((char)b) if a is of type char. as there are no overflow concerns with AND. The folding gets us to the case where we have "a & 0" which is not a valid constant initializer at all. Note I found this while working on fixing PR 32628, where the patch which fixes that caues us to no longer emit a warning/error for the first testcase. -- pinskia at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- OtherBugsDependingO| |32628 nThis| | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32643