* src/SDCCval.c, src/SDCCmain.c, device/include/limits.h,
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 23 Mar 2009 06:21:41 +0000 (06:21 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 23 Mar 2009 06:21:41 +0000 (06:21 +0000)
  device/include/pic/limits.h, device/include/pic16/limits.h,
  device/lib/_fs2schar.c, device/lib/pic/libsdcc/fs2schar.c,
  device/lib/pic16/libsdcc/float/fs2schar.c, doc/sdccman.lyx,
  support/regression/tests/funsigned-char.c:
  applied patch 2704189: character constant sign fix
  thanks to Robert Larice

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5421 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
device/include/limits.h
device/include/pic/limits.h
device/include/pic16/limits.h
device/lib/_fs2schar.c
device/lib/pic/libsdcc/fs2schar.c
device/lib/pic16/libsdcc/float/fs2schar.c
doc/sdccman.lyx
src/SDCCmain.c
src/SDCCval.c
support/regression/tests/funsigned-char.c [new file with mode: 0644]

index c5b7c7e3ba64a2716e4cfa99fb4ad48b01bb10c9..1cbf384eeeee07c14cb1ecdff61483b7a51878e0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-03-23 Borut Razem <borut.razem AT siol.net>
+
+       * src/SDCCval.c, src/SDCCmain.c, device/include/limits.h,
+         device/include/pic/limits.h, device/include/pic16/limits.h,
+         device/lib/_fs2schar.c, device/lib/pic/libsdcc/fs2schar.c,
+         device/lib/pic16/libsdcc/float/fs2schar.c, doc/sdccman.lyx,
+         support/regression/tests/funsigned-char.c:
+         applied patch 2704189: character constant sign fix
+         thanks to Robert Larice
+
 2009-03-22 Borut Razem <borut.razem AT siol.net>
 
        * Small Device C Compiler 2.9.0 released
index 23cbc60ca16dba7b3566b8341012484029d8475c..ba67bb27b4e72c72cd281cf8c17a234004a29e41 100644 (file)
@@ -1,37 +1,42 @@
 /*-------------------------------------------------------------------------
-  limits.h - ANSI defines constants for sizes of integral types 
+  limits.h - ANSI defines constants for sizes of integral types
+
              Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
 
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 2, or (at your option) any
    later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-   
+
    In other words, you are welcome to use, share and improve this program.
    You are forbidden to forbid anyone else to use, share and improve
-   what you give them.   Help stamp out software-hoarding!  
+   what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
 #ifndef __SDC51_LIMITS_H
 #define __SDC51_LIMITS_H 1
 
 #define CHAR_BIT      8    /* bits in a char */
-#define CHAR_MAX    127
-#define CHAR_MIN   -128
-#define SCHAR_MAX   CHAR_MAX
-#define SCHAR_MIN   CHAR_MIN
+#define SCHAR_MAX   127
+#define SCHAR_MIN  -128
 #define UCHAR_MAX   0xff
 #define UCHAR_MIN   0
+#ifdef SDCC_CHAR_UNSIGNED
+#define CHAR_MAX    UCHAR_MAX
+#define CHAR_MIN    UCHAR_MIN
+#else
+#define CHAR_MAX    SCHAR_MAX
+#define CHAR_MIN    SCHAR_MIN
+#endif
 #define INT_MIN    -32768
 #define INT_MAX     32767
 #define SHRT_MAX    INT_MAX
index c928ff45c5cd9bcb7fe69b3b7ae7161fadbc7967..8ab7d52eddbee963dc86bda34588599551277912 100644 (file)
@@ -1,8 +1,8 @@
 /*-------------------------------------------------------------------------
-  limits.h - ANSI defines constants for sizes of integral types 
-       Adopted for the pic16 port by Vangelis Rokas
-               [ vrokas at otenet.gr ] 2004
+  limits.h - ANSI defines constants for sizes of integral types
+
+        Adopted for the pic16 port by Vangelis Rokas
+                [ vrokas at otenet.gr ] 2004
 
              Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
 
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 2, or (at your option) any
    later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-   
+
    In other words, you are welcome to use, share and improve this program.
    You are forbidden to forbid anyone else to use, share and improve
-   what you give them.   Help stamp out software-hoarding!  
+   what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
 #ifndef __LIMITS_H
 #define __LIMITS_H 1
 
 #define CHAR_BIT      8    /* bits in a char */
-#define CHAR_MAX    127
-#define CHAR_MIN   -128
-#define SCHAR_MAX   CHAR_MAX
-#define SCHAR_MIN   CHAR_MIN
+#define SCHAR_MAX   127
+#define SCHAR_MIN  -128
 #define UCHAR_MAX   0xff
 #define UCHAR_MIN   0
+#ifdef SDCC_CHAR_UNSIGNED
+#define CHAR_MAX    UCHAR_MAX
+#define CHAR_MIN    UCHAR_MIN
+#else
+#define CHAR_MAX    SCHAR_MAX
+#define CHAR_MIN    SCHAR_MIN
+#endif
 #define INT_MIN    -32768
 #define INT_MAX     32767
 #define SHRT_MAX    INT_MAX
index c928ff45c5cd9bcb7fe69b3b7ae7161fadbc7967..8ab7d52eddbee963dc86bda34588599551277912 100644 (file)
@@ -1,8 +1,8 @@
 /*-------------------------------------------------------------------------
-  limits.h - ANSI defines constants for sizes of integral types 
-       Adopted for the pic16 port by Vangelis Rokas
-               [ vrokas at otenet.gr ] 2004
+  limits.h - ANSI defines constants for sizes of integral types
+
+        Adopted for the pic16 port by Vangelis Rokas
+                [ vrokas at otenet.gr ] 2004
 
              Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
 
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 2, or (at your option) any
    later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-   
+
    In other words, you are welcome to use, share and improve this program.
    You are forbidden to forbid anyone else to use, share and improve
-   what you give them.   Help stamp out software-hoarding!  
+   what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
 #ifndef __LIMITS_H
 #define __LIMITS_H 1
 
 #define CHAR_BIT      8    /* bits in a char */
-#define CHAR_MAX    127
-#define CHAR_MIN   -128
-#define SCHAR_MAX   CHAR_MAX
-#define SCHAR_MIN   CHAR_MIN
+#define SCHAR_MAX   127
+#define SCHAR_MIN  -128
 #define UCHAR_MAX   0xff
 #define UCHAR_MIN   0
+#ifdef SDCC_CHAR_UNSIGNED
+#define CHAR_MAX    UCHAR_MAX
+#define CHAR_MIN    UCHAR_MIN
+#else
+#define CHAR_MAX    SCHAR_MAX
+#define CHAR_MIN    SCHAR_MIN
+#endif
 #define INT_MIN    -32768
 #define INT_MAX     32767
 #define SHRT_MAX    INT_MAX
index b9b6ac6d4f6820b70eca2f7ab09b96475cdf3ada..70b532885b774324b82d70cb237b0e85eb25c2b0 100644 (file)
 // char __fs2schar (float x)
 static void dummy(void) __naked
 {
-       __asm
-       .globl  ___fs2schar
+        __asm
+        .globl  ___fs2schar
 ___fs2schar:
-       lcall   ___fs2slong
-       jnz     fs2schar_not_zero
-       mov     a, dpl
-       orl     a, dph
-       orl     a, b
-       jnz     fs2schar_clr_a
-       ret
+        lcall   ___fs2slong
+        jnz     fs2schar_not_zero
+        mov     a, dpl
+        orl     a, dph
+        orl     a, b
+        jnz     fs2schar_clr_a
+        ret
 fs2schar_clr_a:
-       clr a
+        clr a
 fs2schar_not_zero:
-       jnb     sign_a, fs2schar_pos
+        jnb     sign_a, fs2schar_pos
 fs2schar_neg:
-       cpl     a
-       jnz     fs2schar_maxval_neg
-       mov     a, b
-       cpl     a
-       jnz     fs2schar_maxval_neg
-       mov     a, dph
-       cpl     a
-       jnz     fs2schar_maxval_neg
-       mov     a, dpl
-       jnb     acc.7, fs2schar_maxval_neg
-       ret
+        cpl     a
+        jnz     fs2schar_maxval_neg
+        mov     a, b
+        cpl     a
+        jnz     fs2schar_maxval_neg
+        mov     a, dph
+        cpl     a
+        jnz     fs2schar_maxval_neg
+        mov     a, dpl
+        jnb     acc.7, fs2schar_maxval_neg
+        ret
 fs2schar_maxval_neg:
-       mov     dpl, #0x80
-       ret
+        mov     dpl, #0x80
+        ret
 fs2schar_pos:
-       jnz     fs2schar_maxval_pos
-       mov     a, b
-       jnz     fs2schar_maxval_pos
-       mov     a, dph
-       jnz     fs2schar_maxval_pos
-       mov     a, dpl
-       jb      acc.7, fs2schar_maxval_pos
-       ret
+        jnz     fs2schar_maxval_pos
+        mov     a, b
+        jnz     fs2schar_maxval_pos
+        mov     a, dph
+        jnz     fs2schar_maxval_pos
+        mov     a, dpl
+        jb      acc.7, fs2schar_maxval_pos
+        ret
 fs2schar_maxval_pos:
-       mov     dpl, #0x7F
-       ret
-       __endasm;
+        mov     dpl, #0x7F
+        ret
+        __endasm;
 }
 
 #else
@@ -77,10 +77,10 @@ fs2schar_maxval_pos:
 signed char __fs2schar (float f)
 {
   signed long sl=__fs2slong(f);
-  if (sl>=CHAR_MAX)
-    return CHAR_MAX;
-  if (sl<=CHAR_MIN)
-    return -CHAR_MIN;
+  if (sl>=SCHAR_MAX)
+    return SCHAR_MAX;
+  if (sl<=SCHAR_MIN)
+    return -SCHAR_MIN;
   return sl;
 }
 
index a482b2d805613ec3794386d9bc1a75ff0b96ede4..325d30b68767c6657483ef99a119cf6d219cfbb6 100644 (file)
@@ -1,8 +1,8 @@
 /*-------------------------------------------------------------------------
-   fs2schar.c :- 
+   fs2schar.c :-
 
    Adopted for float and pic16 port by
-       - Vangelis Rokas, vrokas@otenet.gr (2004)
+        - Vangelis Rokas, vrokas@otenet.gr (2004)
 
    This library is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by the
@@ -36,9 +36,9 @@
 signed char __fs2schar (float f) _FS_REENTRANT
 {
   signed long sl=__fs2slong(f);
-  if (sl>=CHAR_MAX)
-    return CHAR_MAX;
-  if (sl<=CHAR_MIN) 
-    return -CHAR_MIN;
+  if (sl>=SCHAR_MAX)
+    return SCHAR_MAX;
+  if (sl<=SCHAR_MIN)
+    return -SCHAR_MIN;
   return sl;
 }
index a482b2d805613ec3794386d9bc1a75ff0b96ede4..325d30b68767c6657483ef99a119cf6d219cfbb6 100644 (file)
@@ -1,8 +1,8 @@
 /*-------------------------------------------------------------------------
-   fs2schar.c :- 
+   fs2schar.c :-
 
    Adopted for float and pic16 port by
-       - Vangelis Rokas, vrokas@otenet.gr (2004)
+        - Vangelis Rokas, vrokas@otenet.gr (2004)
 
    This library is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by the
@@ -36,9 +36,9 @@
 signed char __fs2schar (float f) _FS_REENTRANT
 {
   signed long sl=__fs2slong(f);
-  if (sl>=CHAR_MAX)
-    return CHAR_MAX;
-  if (sl<=CHAR_MIN) 
-    return -CHAR_MIN;
+  if (sl>=SCHAR_MAX)
+    return SCHAR_MAX;
+  if (sl<=SCHAR_MIN)
+    return -SCHAR_MIN;
   return sl;
 }
index e3a92c5c7c7eded426f8c5045cbe2e388e2a40e3..4d528bf077c291ab369e58f1985b815f5ae0562f 100644 (file)
@@ -24296,6 +24296,49 @@ status collapsed
 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
 \begin_inset Text
 
+\begin_layout Standard
+SDCC_CHAR_UNSIGNED
+\begin_inset LatexCommand index
+name "SDCC\\_CHAR\\_UNSIGNED"
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Standard
+when 
+\emph on
+-
+\begin_inset ERT
+status collapsed
+
+\begin_layout Standard
+
+
+\backslash
+/
+\end_layout
+
+\end_inset
+
+-funsigned-char
+\emph default
+ option is used
+\end_layout
+
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
 \begin_layout Standard
 SDCC_STACK_TENBIT
 \begin_inset LatexCommand index
index 12909d3b01abdb824a3eb09c0f60bd690b8c5223..8b1194ba888fa19275225c1249df88a9d786ab50 100644 (file)
@@ -1988,6 +1988,9 @@ preProcess (char **envp)
       if (options.noOverlay)
         addSet(&preArgvSet, Safe_strdup("-DSDCC_NOOVERLAY"));
 
+      if (options.unsigned_char)
+        addSet(&preArgvSet, Safe_strdup("-DSDCC_CHAR_UNSIGNED"));
+
       /* set the macro for large model  */
       switch (options.model)
         {
index de08d2a6cdb632183032f34cdc0cb97606e4e735..e520aff50004b4956ba99a54493ca600d3e09338 100644 (file)
@@ -840,10 +840,18 @@ value *constCharVal (unsigned char v)
 
   val->type = val->etype = newLink (SPECIFIER); /* create the specifier */
   SPEC_SCLS (val->type) = S_LITERAL;
-  /* let's start with a signed char */
+
   SPEC_NOUN (val->type) = V_CHAR;
-  SPEC_USIGN (val->type) = 1;
-  SPEC_CVAL (val->type).v_uint = v;
+
+  if (options.unsigned_char)
+    {
+      SPEC_USIGN (val->type) = 1;
+      SPEC_CVAL (val->type).v_uint = (unsigned char) v;
+    }
+  else
+    {
+      SPEC_CVAL (val->type).v_int = (signed char) v;
+    }
 
   return val;
 }
diff --git a/support/regression/tests/funsigned-char.c b/support/regression/tests/funsigned-char.c
new file mode 100644 (file)
index 0000000..90d5382
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * check for the correct signness of a char constant
+ *   (signed versus unsigned)
+ *   (indirect via integer promotion)
+ *
+ * Note, the check for the --funsigned-char must be invoked by hand
+ *   see the following emacs sexp
+ *     (compile "SDCCFLAGS=--funsigned-char make -C .. ALL_TESTS='./tests/funsigned-char.c'")
+ *     (compile "make -C .. ALL_TESTS='./tests/funsigned-char.c'")
+ *
+ */
+
+#include <testfwk.h>
+#include <stdint.h>
+#include <limits.h>
+
+int glb_schar_to_int = ~ (signed char)   '\200';
+int glb_uchar_to_int = ~ (unsigned char) '\200';
+int glb_char_to_int  = ~                 '\200';
+
+int tst_schar_to_int()  { return ~ (signed char)   '\200'; }
+int tst_uchar_to_int()  { return ~ (unsigned char) '\200'; }
+int tst_char_to_int()   { return ~                 '\200'; }
+
+
+void
+testBug(void)
+{
+#ifdef SDCC_CHAR_UNSIGNED
+  ASSERT(CHAR_MAX ==  255);
+  ASSERT(CHAR_MIN ==    0);
+#else
+  ASSERT(CHAR_MAX ==  127);
+  ASSERT(CHAR_MIN == -128);
+#endif
+
+  ASSERT(tst_uchar_to_int() == -129);
+  ASSERT(glb_uchar_to_int   == -129);
+
+  ASSERT(tst_schar_to_int() ==  127);
+  ASSERT(glb_schar_to_int   ==  127);
+
+#ifdef SDCC_CHAR_UNSIGNED
+  ASSERT(tst_char_to_int() == -129);
+  ASSERT(glb_char_to_int   == -129);
+#else
+  ASSERT(tst_char_to_int() ==  127);
+  ASSERT(glb_char_to_int   ==  127);
+#endif
+}