View unanswered posts | View active topics It is currently Tue Sep 17, 2019 7:24 pm






Reply to topic  [ 1 post ] 
Interesting Compiler Bug 
Author Message
Rookie

Joined: Mon Feb 15, 2010 10:46 am
Posts: 1
Post Interesting Compiler Bug
Hiya, found an interesting compiler bug. I couldn't find anywhere to submit it. So, here it is:

Code:
#define ABS(a) (((a) > 0)?(a):(-(a)))
#define DEAD_ZONE (0.03)

bool needs_adjustment()
//
//Code segment: needs_adjustment(); Procedure: 1
//
{
  float ld = light_difference();
0000: 1702                     callSub(light_difference)         
0002: 262B4600330000           G70(float) = functionReturnValue    // long/float
  //float ald = ABS(ld);
  return (ABS(ld) > DEAD_ZONE);
0009: 3F013218002B46000B00     TestAndBranchFloatFar(0.000000 >= G70(float), L001C)
0013: AE2B49002B4600           G73 = G70(float)                    // Convert 'float' to 'short'
001A: 2716                     BranchNear(L0031)                 
001C: 262B4A00321800    L001C: G74(float) = 0.000000               // long/float
0023: 392B4A002B4600           G74(float) -= G70(float)            // float
002A: AE2B49002B4A00           G73 = G74(float)                    // Convert 'float' to 'short'
0031: AC2B4A002B4900    L0031: G74(float) = 0.03                   // Convert 'short' to 'float'
0038: 3F01323C002B4A000700     TestAndBranchFloatFar(0.030000 >= G74(float), L0047)
0042: 2B4801                   G72 = true                         
0045: 2704                     BranchNear(L004A)                 
0047: 2B4800            L0047: G72 = false                       
004A: 3633002B48        L004A: functionReturnValue = G72         
}
004F: F6                       Return()                            // needs_adjustment()


So the code is

Code:
#define ABS(a) (((a) > 0)?(a):(-(a)))
#define DEAD_ZONE (0.03)

bool needs_adjustment()
{
  float ld = light_difference();
  return (ABS(ld) > DEAD_ZONE);
}


Which gets compiled in to something like this:

Code:
bool needs_adjustment()
{
  float ld = light_difference();
  float temp;
  short temp1;
  if(0.0 >= ld)
  {
    temp = 0;
    temp -= ld;
    temp1 = (short)temp;
  }
  else
  {
    temp1 = (short)temp;
  }
  temp = 0.03;
  if(0.03 >= temp)
    return false;
  return true;
}


As you can see, this reduces to just the function returning (0.03 >= 0.03) which, assuming no float failure, is always true. So the function always returns false.
I'm pretty sure this is a compiler bug, and a weird one at that. Any ideas what's going on?


Mon Feb 15, 2010 10:56 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.