+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
/*-------------------------------------------------------------------------
- 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
/*-------------------------------------------------------------------------
- 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
/*-------------------------------------------------------------------------
- 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
// 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
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;
}
/*-------------------------------------------------------------------------
- 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
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;
}
/*-------------------------------------------------------------------------
- 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
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;
}
<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
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)
{
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;
}
--- /dev/null
+/*
+ * 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
+}