make integer -> generic pointer casts default to XDATA and throw a awrning
authorkvigor <kvigor@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 20 Sep 2000 19:33:03 +0000 (19:33 +0000)
committerkvigor <kvigor@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 20 Sep 2000 19:33:03 +0000 (19:33 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@390 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCerr.c
src/SDCCerr.h
src/ds390/gen.c

index 01a54d36d8d8f60d9bff849662b7ecfd84b23a19..cdffcddb27ac68424c7e93bf9fb88c2f024d27f7 100644 (file)
@@ -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)
index cb8472bd4f9ba4137346a1be6d5d1b1e1d169ead..4f7bb87f6c8e0bfc95378f3301d3a3f3cba395bb 100644 (file)
 #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, ...);
index 73a4f0bdc5a77d037ac90eddae9cd25b4b9777fd..77e33dfb0f70db3fefaecb27cf01f034fc2cda11 100644 (file)
@@ -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);
            }