Bug 33690 - Pointer comparisons skipped in execution
Summary: Pointer comparisons skipped in execution
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 7.0
Hardware: i386
OS: Linux
medium
high
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: David Lawrence
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2001-03-28 21:51 UTC by Need Real Name
Modified: 2007-04-18 16:32 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2001-03-30 07:52:27 UTC
Embargoed:


Attachments (Terms of Use)

Description Need Real Name 2001-03-28 21:51:22 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0; NAI IE4 
Build 4)


Given this code sample:

   #define HKEY_CLASSES_ROOT ((void *)0x80000000)
   #define HKEY_DYN_DATA     ((void *)0x80000005)
   void *hKey =              ((void *)0x80000001);
   
   if (hKey>=HKEY_CLASSES_ROOT && hKey<=HKEY_DYN_DATA)
      printf("In range\n");
   else 
      printf("Out of range\n");
   printf("Low: %u High: %u hKey: %u\n",
          (unsigned long)H_KEY_CLASSES_ROOT,
          (unsigned long)H_KEY_DYN_DATA,
          (unsigned long)hKey);

The comparison is never even performed. It's skipped over in gdb and  
the "else" automatically executes without performing the comparison. 

This, however, works without a problem:

   if ((unsigned long)hKey>=(unsigned long)HKEY_CLASSES_ROOT 
            && (unsigned long)hKey<=(unsigned long)HKEY_DYN_DATA)
      printf("In range\n");


Reproducible: Always
Steps to Reproduce:
1. Enter above code sample.
2. Compile (i.e. gcc sample.c -o sample -g -lc)
3. Execute sample.
	

Actual Results:  A comparison that should have resulted in true, was 
skipped in execution and assumed to have a false result.

Expected Results:  The comparison would be performed and validly determine 
true or false.

gcc-2.96-69
kernel-2.2.16-22
gdb-5.0-7

Comment 1 Jakub Jelinek 2001-03-29 20:37:09 UTC
Verified both in gcc-2.96-80 and gcc-3_0-branch plus gcc-3_1-branch.
Debugging...

Comment 2 Jakub Jelinek 2001-03-29 21:48:03 UTC
Fixed, the fix will appear in 2.96-81. I've mailed it to gcc-patches
too (but gcc.gnu.org is dead ATM, so I cannot provide URL to the
patch).

Comment 3 Jakub Jelinek 2001-03-30 07:52:23 UTC
FYI, the patch is at http://gcc.gnu.org/ml/gcc-patches/2001-03/msg01977.html


Note You need to log in before you can comment on or make changes to this bug.