From: kvigor Date: Wed, 20 Sep 2000 19:33:03 +0000 (+0000) Subject: make integer -> generic pointer casts default to XDATA and throw a awrning X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=cb952aa203b35b35e8da933eb16f906b094f7ca4;p=fw%2Fsdcc make integer -> generic pointer casts default to XDATA and throw a awrning git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@390 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCCerr.c b/src/SDCCerr.c index 01a54d36..cdffcddb 100644 --- a/src/SDCCerr.c +++ b/src/SDCCerr.c @@ -156,7 +156,8 @@ struct { { WARNING,"warning *** Indirect call to a banked function not implemented.\n"}, { WARNING,"warning *** Model '%s' not supported for %s, ignored.\n"}, { WARNING,"warning *** Both banked and nonbanked attributes used. nonbanked wins.\n"}, -{ WARNING,"warning *** Both banked and static used. static wins.\n"} +{ WARNING,"warning *** Both banked and static used. static wins.\n"}, +{ WARNING,"warning *** converting integer type to generic pointer: assuming XDATA\n"} }; void vwerror (int errNum, va_list marker) diff --git a/src/SDCCerr.h b/src/SDCCerr.h index cb8472bd..4f7bb87f 100644 --- a/src/SDCCerr.h +++ b/src/SDCCerr.h @@ -136,5 +136,6 @@ #define W_UNSUPPORTED_MODEL 133 /* Unsupported model, ignored */ #define W_BANKED_WITH_NONBANKED 134 /* banked and nonbanked attributes mixed */ #define W_BANKED_WITH_STATIC 135 /* banked and static mixed */ +#define W_INT_TO_GEN_PTR_CAST 136 /* Converting integer type to generic pointer. */ void werror(int, ...); diff --git a/src/ds390/gen.c b/src/ds390/gen.c index 73a4f0bd..77e33dfb 100644 --- a/src/ds390/gen.c +++ b/src/ds390/gen.c @@ -7681,17 +7681,54 @@ static void genCast (iCode *ic) int p_type; link *type = operandType(right); - link *etype = getSpec(type); /* pointer to generic pointer */ if (IS_GENPTR(ctype)) { char *l = zero; if (IS_PTR(type)) + { p_type = DCL_TYPE(type); - else { + } + else + { +#if OLD_CAST_BEHAVIOR + /* KV: we are converting a non-pointer type to + * a generic pointer. This (ifdef'd out) code + * says that the resulting generic pointer + * should have the same class as the storage + * location of the non-pointer variable. + * + * For example, converting an int (which happens + * to be stored in DATA space) to a pointer results + * in a DATA generic pointer; if the original int + * in XDATA space, so will be the resulting pointer. + * + * I don't like that behavior, and thus this change: + * all such conversions will be forced to XDATA and + * throw a warning. If you want some non-XDATA + * type, or you want to suppress the warning, you + * must go through an intermediate cast, like so: + * + * char _generic *gp = (char _xdata *)(intVar); + */ + link *etype = getSpec(type); + /* we have to go by the storage class */ - p_type = PTR_TYPE(SPEC_OCLS(etype)); + if (SPEC_OCLS(etype) != generic) + { + p_type = PTR_TYPE(SPEC_OCLS(etype)); + } + else +#endif + { + /* Converting unknown class (i.e. register variable) + * to generic pointer. This is not good, but + * we'll make a guess (and throw a warning). + */ + p_type = FPOINTER; + werror(W_INT_TO_GEN_PTR_CAST); + } } /* the first two bytes are known */ @@ -7703,6 +7740,7 @@ static void genCast (iCode *ic) offset); offset++; } + /* the last byte depending on type */ switch (p_type) { case IPOINTER: @@ -7721,7 +7759,7 @@ static void genCast (iCode *ic) default: /* this should never happen */ - werror(E_INTERNAL_ERROR,__FILE__,__LINE__, + werror(E_INTERNAL_ERROR,__FILE__,__LINE__, "got unknown pointer type"); exit(1); }