Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#2071 Incorrect line number reported for error 2: Initializer elem

closed-fixed
Erik Petrich
5
2013-05-25
2012-08-22
Anonymous
No

I am using Windows 7 64-bit and my sdcc -v is:
SDCC : mcs51/gbz80/z80/z180/r2k/r3ka/ds390/pic16/pic14/TININative/ds400/hc08/s08
3.2.0 #8008 (Jul 6 2012) (MINGW32)

The test code that reproduces the bug is:

const char x = 0;

char foo(){ return 4; }

void main()
{
static const char a = foo();
static const char b = a;
}

static const char c = foo();
static const char d = c;

When I compile the code by running "sdcc test.c", I get the following output:

test.c:1: error 2: Initializer element is not constant
test.c:1: error 2: Initializer element is not constant
test.c:1: error 2: Initializer element is not constant
test.c:11: error 2: Initializer element is not constant
test.c:12: error 2: Initializer element is not constant
test.c:12: error 2: Initializer element is not constant

Clearly there is no error on line 1, so one bug is that SDCC reports the wrong line number. The errors it is reporting on line 1 are actually caused by the definitions of a and b. SDCC generates two errors for b, and I would consider that to be another bug.

If I compile with SDCC 3.1.0 #7066, then the errors for a and b go away and the output is just:

test.c:11: error 2: Initializer element is not constant
test.c:12: error 2: Initializer element is not constant
test.c:12: error 2: Initializer element is not constant

If I comment out c and d, then SDCC 3.1.0 #7066 compiles the program correctly, putting some code in the GSINIT section to call foo and initialize a and b. This was a nice feature and I had some existing code that relied on it.

Clearly something about static const local variables has changed between SDCC 3.1.0 and 3.2.0, and I am not sure if it is a bug. However, the new errors are consistent with gcc: I tested compiling the code with gcc and it gives errors for a, b, c, and d. I checked the change log on the front page of http://sdcc.sourceforge.net/ and the only possibly relevant entry was: "inclusion of some tests from the gcc test suite into the sdcc regression test suite led to many bugs being found and fixed." Does anyone know what changed to cause these new errors?

Discussion


  • Anonymous
    2012-08-22

     
    Attachments
  • Bug #3073647 got fixed.

    Philipp

     
  • Erik Petrich
    Erik Petrich
    2012-09-16

    • labels: --> C-Front End
    • milestone: --> fixed
    • assigned_to: nobody --> epetrich
    • status: open --> closed-fixed
     
  • Erik Petrich
    Erik Petrich
    2012-09-16

    Revision #8106 now uses the correct line numbers and issues the error messages only once.

    What has changed is that SDCC is getting better at conforming to the official C standard. The relevant part is "6.7.8. Initialization: [...] 4. All the expressions in an initializer for an object that has static storage duration shall be constant expressions or string literals."