This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug optimization/11210] New: optimizer drops conditional with typecast from signed to unsigned char


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11210

           Summary: optimizer drops conditional with typecast from signed to
                    unsigned char
           Product: gcc
           Version: 3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: guido@clagi.de
                CC: gcc-bugs@gcc.gnu.org

I have a problem compiling the following code portet to
gcc/linux/intel/i686 with turned on optimization (-O). Without the
optimization it will work well.  I know, this code is not very clean
(cast from signed char to unsigned char with negative value), but it
will occur at many places in this project in similar form.

With turned on optimization, gcc will produce the message
test.c:29: Warnung: comparison is always 1
(in c and c++ mode) and the optimizer removes the else part. 
Weird about this is, if you remove the line "Head_t head;" from
struct Telegram_t, the error will not occur and the code works, as I
expect

The compile command was

gcc -Wall -O -S test.c

I've testet the gcc versions 3.3, 3.2.3 and 2.95.4. They all behave same in
respect to this problem.

any suggestions?


----------------------------------------------------------------------------
#include <stdio.h>


typedef struct
{
  long  size; 
} Head_t;


typedef struct 
{
  char data[270]; 
} Data_t;


typedef struct
{
  Head_t head;
  Data_t data;
  
} Telegram_t;


int main(void)
{
  Telegram_t t;
    
  if ( (unsigned char)t.data.data[12] != 2  ||
       (unsigned char)t.data.data[14] != 130 ) { 
      printf("hier\n");
    } else {
      printf("nicht hier\n");
    }
  return 0;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]