#1537 --funsigned-char and typedef pointer bug

closed-accepted
5
2013-05-25
2009-05-29
wek
No

When compiling with --funsigned-char a file containing only #include <stdio.h>, a somewhat surprising error occurs:
Internal error: validateLink failed in SPEC_NOUN((yyvsp[(1) - (2)].lnk)) @ /home/sdcc-builder/build/sdcc-build/orig/sdcc/src/SDCC.y:1297: expected SPECIFIER, got DECLARATOR

A very similar error occurs when compiling with sdcc --funsigned-char a file containing:
typedef unsigned char * Tbyteptr;
Tbyteptr c;

The error:
Internal error: validateLink failed in SPEC_NOUN(lnk) @ /home/sdcc-builder/build/sdcc-build/orig/sdcc/src/SDCC.y:482: expected SPECIFIER, got DECLARATOR

SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.9.1 #5464 (May 27 2009) (MINGW32); running on W98SE.

Jan Waclawek

Discussion

  • Robert Larice

    Robert Larice - 2009-05-30

    Hello `wek'
    would you like to try the following experimental patch ?
    Robert Larice

    #------------------------------------------------------------------------------------------------------------------------------------
    # an experimental fix for
    # [ 2798646 ] --funsigned-char and typedef pointer bug
    # http://sourceforge.net/tracker/index.php?func=detail&group_id=599&atid=100599&aid=2798646

    Index: src/SDCCsymt.c

    --- src/SDCCsymt.c (revision 5420)
    +++ src/SDCCsymt.c (working copy)
    @@ -595,6 +595,25 @@
    }

    /*------------------------------------------------------------------*/
    +/* finalizeSpec */
    +/* currently just a V_CHAR is forced to be unsigned */
    +/* when it's neither signed nor unsigned */
    +/* and the --funsigned-char command line switch is active */
    +/*------------------------------------------------------------------*/
    +sym_link *
    +finalizeSpec(sym_link * lnk)
    +{
    + if(options.unsigned_char) {
    + sym_link *p = lnk;
    + while (p && !IS_SPEC(p))
    + p = p->next;
    + if(SPEC_NOUN(p) == V_CHAR && !SPEC_USIGN(p) && !p->select.s.b_signed)
    + SPEC_USIGN(p) = 1;
    + }
    + return lnk;
    +}
    +
    +/*------------------------------------------------------------------*/
    /* mergeSpec - merges two specifiers and returns the new one */
    /*------------------------------------------------------------------*/
    sym_link *
    Index: src/SDCCsymt.h
    ===================================================================
    --- src/SDCCsymt.h (revision 5420)
    +++ src/SDCCsymt.h (working copy)
    @@ -593,6 +593,7 @@
    sym_link *newFloatLink ();
    structdef *newStruct (char *);
    void addDecl (symbol *, int, sym_link *);
    +sym_link *finalizeSpec(sym_link *);
    sym_link *mergeSpec (sym_link *, sym_link *, char *name);
    symbol *reverseSyms (symbol *);
    sym_link *reverseLink (sym_link *);
    Index: src/SDCC.y
    ===================================================================
    --- src/SDCC.y (revision 5420)
    +++ src/SDCC.y (working copy)
    @@ -108,9 +108,9 @@
    %type <sym> declaration init_declarator_list init_declarator
    %type <sym> declaration_list identifier_list
    %type <sym> declarator2_function_attributes while do for critical
    -%type <lnk> pointer type_specifier_list type_specifier type_name
    +%type <lnk> pointer type_specifier_list type_specifier_list_ type_specifier type_name
    %type <lnk> storage_class_specifier struct_or_union_specifier function_specifier
    -%type <lnk> declaration_specifiers sfr_reg_bit sfr_attributes type_specifier2
    +%type <lnk> declaration_specifiers declaration_specifiers_ sfr_reg_bit sfr_attributes type_specifier2
    %type <lnk> function_attribute function_attributes enum_specifier
    %type <lnk> abstract_declarator abstract_declarator2 unqualified_pointer
    %type <val> parameter_type_list parameter_list parameter_declaration opt_assign_expr
    @@ -183,8 +183,6 @@
    | declaration_specifiers function_declarator function_body
    {
    pointerTypes($2->type,copyLinkChain($1));
    - if (options.unsigned_char && SPEC_NOUN($1) == V_CHAR && !($1)->select.s.b_signed)
    - SPEC_USIGN($1) = 1;
    addDecl($2,0,$1);
    $$ = createFunction($2,$3);
    }
    @@ -479,8 +477,6 @@

    for (sym1 = sym = reverseSyms($2);sym != NULL;sym = sym->next) {
    sym_link *lnk = copyLinkChain($1);
    - if (options.unsigned_char && SPEC_NOUN(lnk) == V_CHAR && !lnk->select.s.b_signed)
    - SPEC_USIGN(lnk) = 1;
    /* do the pointer stuff */
    pointerTypes(sym->type,lnk);
    addDecl (sym,0,lnk) ;
    @@ -491,9 +487,11 @@
    }
    ;

    -declaration_specifiers
    +declaration_specifiers : declaration_specifiers_ { $$ = finalizeSpec($1); } ;
    +
    +declaration_specifiers_
    : storage_class_specifier { $$ = $1; }
    - | storage_class_specifier declaration_specifiers {
    + | storage_class_specifier declaration_specifiers_ {
    /* if the decl $2 is not a specifier */
    /* find the spec and replace it */
    if ( !IS_SPEC($2)) {
    @@ -507,7 +505,7 @@
    $$ = mergeSpec($1,$2, "storage_class_specifier declaration_specifiers");
    }
    | type_specifier { $$ = $1; }
    - | type_specifier declaration_specifiers {
    + | type_specifier declaration_specifiers_ {
    /* if the decl $2 is not a specifier */
    /* find the spec and replace it */
    if ( !IS_SPEC($2)) {
    @@ -521,7 +519,7 @@
    $$ = mergeSpec($1,$2, "type_specifier declaration_specifiers");
    }
    | function_specifier { $$ = $1; }
    - | function_specifier declaration_specifiers {
    + | function_specifier declaration_specifiers_ {
    /* if the decl $2 is not a specifier */
    /* find the spec and replace it */
    if ( !IS_SPEC($2)) {
    @@ -883,8 +881,6 @@
    symbol *sym ;
    for ( sym = $2 ; sym != NULL ; sym = sym->next ) {
    sym_link *btype = copyLinkChain($1);
    - if (options.unsigned_char && SPEC_NOUN(btype) == V_CHAR && !(btype)->select.s.b_signed)
    - SPEC_USIGN(btype) = 1;

    /* make the symbol one level up */
    sym->level-- ;
    @@ -1248,10 +1244,12 @@
    }
    ;

    -type_specifier_list
    +type_specifier_list : type_specifier_list_ { $$ = finalizeSpec($1); } ;
    +
    +type_specifier_list_
    : type_specifier
    - //| type_specifier_list type_specifier { $$ = mergeSpec ($1,$2, "type_specifier_list"); }
    - | type_specifier_list type_specifier {
    + //| type_specifier_list_ type_specifier { $$ = mergeSpec ($1,$2, "type_specifier_list"); }
    + | type_specifier_list_ type_specifier {
    /* if the decl $2 is not a specifier */
    /* find the spec and replace it */
    if ( !IS_SPEC($2)) {
    @@ -1294,8 +1292,6 @@
    {
    symbol *loop ;
    pointerTypes($2->type,$1);
    - if (options.unsigned_char && SPEC_NOUN($1) == V_CHAR && !($1)->select.s.b_signed)
    - SPEC_USIGN($1) = 1;
    addDecl ($2,0,$1);
    for (loop=$2;loop;loop->_isparm=1,loop=loop->next);
    addSymChain (&$2);
    @@ -1304,8 +1300,6 @@
    }
    | type_name {
    $$ = newValue() ;
    - if (options.unsigned_char && SPEC_NOUN($1) == V_CHAR && !($1)->select.s.b_signed)
    - SPEC_USIGN($1) = 1;
    $$->type = $1;
    $$->etype = getSpec($$->type);
    ignoreTypedefType = 0;

     
  • wek

    wek - 2009-05-31

    Robert,

    Thanks, but I don't know how to apply a patch, let alone compile SDCC for Win...

    Jan (a mere user)

     
  • wek

    wek - 2009-05-31

    OK so I learned how to compile SDCC on a WinXP machine under Cygwin/MINGW32 (after several failed attempts to get the include directories working properly I found out that this is extensively described in the manual.. :-( ); then fixed the patch (as the sourceforge machine distorted it severely, wrapping long lines in the mail and eating up all the spaces in the HTML - maybe it's better to append next time as a file?) and it appears to work for me now.

    What's next?

    Jan Waclawek

     
  • Robert Larice

    Robert Larice - 2009-05-31

    Hello Jan,

    Sorry for the patch distortion, I allways feel like a fool when cutting and pasting.
    (By the way its displayed in proportional font on my browser, very clever ...)
    But I don't find a button to attach a file to the bug tracker.

    Did you actually successfully compile *and* run a non-trivial piece of C
    with the patched sdcc ?

    I glanced again at the patch, and can be confident it doesn't do harm to sdcc
    when --funsigned-char isn't given. And when it's given, the current sdcc is obviously
    broken, so there can't be much harm either.
    So may I ask one of the developpers to consider its inclusion ?

    Robert Larice

     
  • wek

    wek - 2009-06-01
     
  • wek

    wek - 2009-06-01

    Robert,

    I discovered the file addition mechanism far below ;-) please check if I haven't distorted the patch somehow.

    I haven't actually _run_ the compiled file, just checked the .lst files and they look fine; but will try to arrange for some sort of a real world check.

    JW

     
  • Maarten Brock

    Maarten Brock - 2009-06-01

    I already looked again, but SF really does not allow others than the OP or administrators to attach files. I don't know why.

    Robert, I applied the patch locally and tried to rebuild SDCC and its libraries and it failed. Are you sure it doesn't do any harm?

    I must agree that --funsigned-char is broken.

     
  • Robert Larice

    Robert Larice - 2009-06-01

    Hello,
    Jan's mended/corrected and attached version shows only whitespace differences to mine,
    so I suppose it should do.
    I bet a rebuild of SDCC + libs nowhere makes use of --funsigned-char,
    so I'm a bit puzzled/irritated if it fails.
    I will try within the next few days to checkout HEAD, apply the patch, and configure/make for mcs51.
    If you've done more to force failure, please give me a hint.
    But, isn't this what Jan already did ? (checkout/configure/make)
    He didn't report any make-failures.

     
  • Maarten Brock

    Maarten Brock - 2009-06-01

    Sorry, my bad. I had some other changes hanging around that broke things.

    I'm trying again and will also try with --funsigned-char on for both the libs and the regression tests. If all works out it will be applied later today.

     
  • Maarten Brock

    Maarten Brock - 2009-06-01

    Applied patch along with several more fixes in SDCC 2.9.1 #5467. Now can build libraries and passes almost all regression tests with -funsigned-char. Only arithcse.c fails for mcs51-large.

    Thanks Robert, esp. for the SDCC.y stuff.

     
  • Maarten Brock

    Maarten Brock - 2009-06-01
    • milestone: --> fixed
    • assigned_to: nobody --> maartenbrock
    • status: open --> closed-accepted
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks