Applied patch #2762516
[fw/sdcc] / src / pic16 / genarith.c
index fbb240bf8c8995176b03379e18926bb311846fda..1e06e7b911d71762f34a9bef7aec569fea0a3a17 100644 (file)
@@ -424,19 +424,30 @@ static void genAddLit (iCode *ic, int lit)
 {
 
   int size,same;
-  int lo;
+  int lo, offset;
 
   operand *result;
   operand *left;
 
-    FENTRY;
-
+  FENTRY;
 
   left = IC_LEFT(ic);
   result = IC_RESULT(ic);
   same = pic16_sameRegs(AOP(left), AOP(result));
   size = pic16_getDataSize(result);
 
+  if ((AOP_PCODE == AOP_TYPE(left))
+          && (PO_IMMEDIATE == AOP(left)->aopu.pcop->type))
+  {
+      /* see #1888004 for an example case for this */
+      for (offset = 0; offset < size; offset++) {
+          pic16_emitpcode(POC_MOVLW, pic16_newpCodeOpImmd(AOP(left)->aopu.pcop->name,
+                  offset, PCOI(AOP(left)->aopu.pcop)->index + lit, 0));
+          pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result), offset));
+      } // for
+      return;
+  } // if
+
   if(same) {
 
     /* Handle special cases first */