V7.00 internal error: liveness_defsite()

Started by dnx, August 14, 2012, 04:55:01 PM

Previous topic - Next topic

dnx

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;



//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;
}




CommonTater

#1
Quote from: dnx 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;

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...

#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...

Pelle

Quote from: dnx on August 14, 2012, 04:55:01 PM
This function gives an internal error: liveness_defsite() when optimization is enabled.
OK, I will look at this...
/Pelle