From df7c871421f26a279325f8efa2c04f4600d9eb45 Mon Sep 17 00:00:00 2001 From: epetrich Date: Wed, 12 Nov 2003 08:30:32 +0000 Subject: [PATCH] * src/SDCCsymt.h, * src/SDCCsymt.c (addSymTypeChain, compareTypesExact): fixed bugs #838241 & 780691 (basicly the same bug) * src/SDCCBBlock.c (iCode2eBBlock): fixed bug #840148 * src/SDCCBBlock.c (iCodeFromeBBlock): fixed bug #840162 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3012 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 8 +++ src/SDCCBBlock.c | 31 ++++++++++- src/SDCCsymt.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++- src/SDCCsymt.h | 2 + 4 files changed, 173 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5c771112..07140247 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2003-11-12 Erik Petrich + + * src/SDCCsymt.h, + * src/SDCCsymt.c (addSymTypeChain, compareTypesExact): fixed bugs + #838241 & 780691 (basicly the same bug) + * src/SDCCBBlock.c (iCode2eBBlock): fixed bug #840148 + * src/SDCCBBlock.c (iCodeFromeBBlock): fixed bug #840162 + 2003-11-11 Bernhard Held * src/SDCCmain.c (linkEdit): "fix" #834252 diff --git a/src/SDCCBBlock.c b/src/SDCCBBlock.c index 42c1703f..10053301 100644 --- a/src/SDCCBBlock.c +++ b/src/SDCCBBlock.c @@ -266,6 +266,14 @@ iCode2eBBlock (iCode * ic) ebb->ech = ebb->sch; return ebb; } + + /* if this is a function call */ + if (ic->op == CALL || ic->op == PCALL) + { + ebb->hasFcall = 1; + if (currFunc) + FUNC_HASFCALL(currFunc->type) = 1; + } if ((ic->next && ic->next->op == LABEL) || !ic->next) @@ -685,13 +693,32 @@ iCodeFromeBBlock (eBBlock ** ebbs, int count) (ebbs[i]->entryLabel != entryLabel && ebbs[i]->entryLabel != returnLabel)) { - werror (W_CODE_UNREACH, ebbs[i]->sch->filename, ebbs[i]->sch->lineno); - continue; + iCode *ic = NULL; + bool foundNonlabel = 0; + ic=ebbs[i]->sch; + do + { + if (ic->op != LABEL) + { + foundNonlabel = 1; + break; + } + if (ic==ebbs[i]->ech) + break; + ic = ic->next; + } + while (ic); + if (foundNonlabel && ic) + { + werror (W_CODE_UNREACH, ic->filename, ic->lineno); + continue; + } } lic->next = ebbs[i]->sch; lic->next->prev = lic; lic = ebbs[i]->ech; + } return ric; diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index 35360f20..05423549 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -989,15 +989,19 @@ addSymChain (symbol * symHead) /* one definition extern ? */ if (IS_EXTERN (csym->etype) || IS_EXTERN (sym->etype)) { /* do types match ? */ - if (compareType (csym->type, sym->type) != 1) { + //checkDecl (sym, IS_EXTERN (sym->etype)); + if (compareTypeExact (csym->type, sym->type, sym->level) != 1) { /* no then error */ werror (E_EXTERN_MISMATCH, csym->name); + printFromToType (csym->type, sym->type); continue; } } else { /* not extern */ - if (compareType (csym->type, sym->type) != 1) { + //checkDecl (sym, 0); + if (compareTypeExact (csym->type, sym->type, sym->level) != 1) { werror (E_DUPLICATE, sym->name); + printFromToType (csym->type, sym->type); continue; } } @@ -1619,6 +1623,134 @@ compareType (sym_link * dest, sym_link * src) return 1; } +/*--------------------------------------------------------------------*/ +/* compareTypeExact - will do type check return 1 if match exactly */ +/*--------------------------------------------------------------------*/ +int +compareTypeExact (sym_link * dest, sym_link * src, int level) +{ + STORAGE_CLASS srcScls, destScls; + + if (!dest && !src) + return 1; + + if (dest && !src) + return 0; + + if (src && !dest) + return 0; + + /* if dest is a declarator then */ + if (IS_DECL (dest)) + { + if (IS_DECL (src)) + { + if (DCL_TYPE (src) == DCL_TYPE (dest)) { + if ((DCL_TYPE (src) == ARRAY) && (DCL_ELEM (src) != DCL_ELEM (dest))) + return 0; + if (DCL_PTR_CONST (src) != DCL_PTR_CONST (dest)) + return 0; + if (DCL_PTR_VOLATILE (src) != DCL_PTR_VOLATILE (dest)) + return 0; + if (IS_FUNC(src)) + return compareTypeExact (dest->next, src->next, -1); + return compareTypeExact (dest->next, src->next, level); + } + return 0; + } + return 0; + } + + /* if one is a specifier and the other is not */ + if ((IS_SPEC (src) && !IS_SPEC (dest)) || + (IS_SPEC (dest) && !IS_SPEC (src))) + return 0; + + /* if one of them is a void then ok */ + if (SPEC_NOUN (dest) != SPEC_NOUN (src)) + return 0; + + /* if they are both bitfields then if the lengths + and starts don't match */ + if (IS_BITFIELD (dest) && IS_BITFIELD (src) && + (SPEC_BLEN (dest) != SPEC_BLEN (src) || + SPEC_BSTR (dest) != SPEC_BSTR (src))) + return 0; + + if (IS_INTEGRAL (dest)) + { + /* signedness must match */ + if (SPEC_USIGN (dest) != SPEC_USIGN (src)) + return 0; + /* size must match */ + if (SPEC_LONG (dest) != SPEC_LONG (src)) + return 0; + if (SPEC_SHORT (dest) != SPEC_SHORT (src)) + return 0; + } + + if (IS_STRUCT (dest)) + { + if (SPEC_STRUCT (dest) != SPEC_STRUCT (src)) + return 0; + } + + if (SPEC_CONST (dest) != SPEC_CONST (src)) + return 0; + if (SPEC_VOLATILE (dest) != SPEC_VOLATILE (src)) + return 0; + if (SPEC_STAT (dest) != SPEC_STAT (src)) + return 0; + + destScls = SPEC_SCLS (dest); + srcScls = SPEC_SCLS (src); + + /* Compensate for const to const code change in checkSClass() */ + if (!level & port->mem.code_ro && SPEC_CONST (dest)) + { + if (srcScls == S_CODE && destScls == S_FIXED) + destScls = S_CODE; + if (destScls == S_CODE && srcScls == S_FIXED) + srcScls = S_CODE; + } + + /* compensate for allocGlobal() */ + if ((srcScls == S_FIXED || srcScls == S_AUTO) + && port->mem.default_globl_map == xdata + && !level) + srcScls = S_XDATA; + + if (level>0 && !SPEC_STAT (dest)) + { + /* Compensate for hack-o-matic in checkSClass() */ + if (options.stackAuto || (currFunc && IFFUNC_ISREENT (currFunc->type))) + { + if (destScls == S_FIXED) + destScls = (options.useXstack ? S_XSTACK : S_STACK); + if (srcScls == S_FIXED) + srcScls = (options.useXstack ? S_XSTACK : S_STACK); + } + else if (TARGET_IS_DS390 || TARGET_IS_DS400 || options.useXstack) + { + if (destScls == S_FIXED) + destScls = S_XDATA; + if (srcScls == S_FIXED) + srcScls = S_XDATA; + } + } + + if (srcScls != destScls) + { + printf ("level = %d\n", level); + printf ("SPEC_SCLS (src) = %d, SPEC_SCLS (dest) = %d\n", + SPEC_SCLS (src), SPEC_SCLS (dest)); + printf ("srcScls = %d, destScls = %d\n",srcScls, destScls); + return 0; + } + + return 1; +} + /*------------------------------------------------------------------*/ /* inCalleeSaveList - return 1 if found in callee save list */ /*------------------------------------------------------------------*/ diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index b12b4d3e..c9e2adc3 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -378,6 +378,7 @@ extern sym_link *validateLink(sym_link *l, #define SPEC_NOUN(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.noun #define SPEC_LONG(x) validateLink(x, "SPEC_LONG", #x, SPECIFIER, __FILE__, __LINE__)->select.s._long +#define SPEC_SHORT(x) validateLink(x, "SPEC_LONG", #x, SPECIFIER, __FILE__, __LINE__)->select.s._short #define SPEC_USIGN(x) validateLink(x, "SPEC_USIGN", #x, SPECIFIER, __FILE__, __LINE__)->select.s._unsigned #define SPEC_SCLS(x) validateLink(x, "SPEC_SCLS", #x, SPECIFIER, __FILE__, __LINE__)->select.s.sclass #define SPEC_ENUM(x) validateLink(x, "SPEC_ENUM", #x, SPECIFIER, __FILE__, __LINE__)->select.s._isenum @@ -529,6 +530,7 @@ sym_link *newIntLink (); sym_link *newCharLink (); sym_link *newLongLink (); int compareType (sym_link *, sym_link *); +int compareTypeExact (sym_link *, sym_link *, int); int checkFunction (symbol *, symbol *); void cleanUpLevel (bucket **, int); void cleanUpBlock (bucket **, int); -- 2.30.2