From: SourceForge.net <no...@so...> - 2009-06-01 08:29:06
|
Bugs item #2798646, was opened at 2009-05-30 00:43 Message generated for change (Comment added) made by wek_ You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=2798646&group_id=599 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: C-Front End Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: wek (wek_) Assigned to: Nobody/Anonymous (nobody) Summary: --funsigned-char and typedef pointer bug Initial Comment: 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 ---------------------------------------------------------------------- >Comment By: wek (wek_) Date: 2009-06-01 10:29 Message: 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 ---------------------------------------------------------------------- Comment By: Robert Larice (rlar) Date: 2009-05-31 20:29 Message: 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 ---------------------------------------------------------------------- Comment By: wek (wek_) Date: 2009-05-31 18:51 Message: 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 ---------------------------------------------------------------------- Comment By: wek (wek_) Date: 2009-05-31 11:40 Message: Robert, Thanks, but I don't know how to apply a patch, let alone compile SDCC for Win... Jan (a mere user) ---------------------------------------------------------------------- Comment By: Robert Larice (rlar) Date: 2009-05-30 21:58 Message: 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; ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=2798646&group_id=599 |