Bug 33690

Summary: Pointer comparisons skipped in execution
Product: [Retired] Red Hat Linux Reporter: Need Real Name <swade>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED RAWHIDE QA Contact: David Lawrence <dkl>
Severity: high Docs Contact:
Priority: medium    
Version: 7.0   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2001-03-30 07:52:27 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

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