NO

Author Topic: V7.00 internal error: liveness_defsite()  (Read 2872 times)

dnx

  • Guest
V7.00 internal error: liveness_defsite()
« on: August 14, 2012, 04:55:01 PM »
Windows XP - Pelles C V7.00.350

This function gives an internal error: liveness_defsite() when optimization is enabled.
The error disappears when i comment out the line    :   idc.flags[ind] |= k;
or the line :      idc.flags[ind] &= k;



Code: [Select]
//POCC test.c : => NO ERROR
//POCC -std:C11 -Tx86-coff -Ot -Ob1 -fp:precise -W1 -Gd test.c => internal error

#define false 0
#define true !false
typedef int bool;

#define FCT_FLAG_CLEAR 0
#define FCT_FLAG_SET 1


struct str_indic {
unsigned long flags[2]; //64 flags
};
struct str_indic idc;



bool SetResFlag(int i, int fct)
{
int j;
int k,ind;
bool f;

ind=0; if (i>=32) { ind=1; i-=32; }
k=1; for (j=0; j<i; j++) k<<=1;
f=false; if ((idc.flags[ind] & k)!=0) f=true;

if (fct==FCT_FLAG_SET) {
idc.flags[ind] |= k;
} else if (fct==FCT_FLAG_CLEAR) {
k=~k;
idc.flags[ind] &= k;
}
return f;
}


int main(void)
{
int i = 0;
SetResFlag(i, FCT_FLAG_SET);
return 0;
}


« Last Edit: August 14, 2012, 09:16:52 PM by Stefan Pendl »

CommonTater

  • Guest
Re: V7.00 internal error: liveness_defsite()
« Reply #1 on: August 14, 2012, 06:01:40 PM »
Windows XP - Pelles C V7.00.350

This function gives an internal error: liveness_defsite() when optimization is enabled.
The error disappears when i comment out the line    :   idc.flags[ind] |= k;
or the line :      idc.flags[ind] &= k;

Tested it here and I can confirm this is an optimizer bug...
Turning off the optimizations eliminates the error message
Wrapping the function in #pragma optimize (none) and #pragma optimize() eliminates the problem...
 
However this function could be made a lot more efficient...
Code: [Select]
#define false 0
#define true !false
typedef int bool;

#define FCT_FLAG_CLEAR   0
#define FCT_FLAG_SET      1

union str_indic
  {
   unsigned long      flags[2];  //64 flags
   unsigned long long bits;
  } idc;
 
bool SetResFlag(int i, int fct)
  {
    unsigned long long j = 1;
   
    if (fct == FCT_FLAG_SET)
      idc.bits |= (j << i);
    else
      idc.bits &= ~(j << i);

    return (idc.bits >> i) & 1;
  }
 

int main(void)
  {
    SetResFlag(3, FCT_FLAG_SET);
    return 0;
  }

...And in this form there appears to be no optimizer error...
« Last Edit: August 14, 2012, 06:42:09 PM by CommonTater »

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: V7.00 internal error: liveness_defsite()
« Reply #2 on: September 01, 2012, 09:04:51 PM »
This function gives an internal error: liveness_defsite() when optimization is enabled.
OK, I will look at this...
/Pelle