* src/SDCCast.c (decorateType): fix promotion of unary minus
* src/SDCCsymt.c (computeType): beautified
* src/SDCCval.c (cheapestVal): beautified, old non-Ansi version removed,
- (valUnaryPM, valComplement, valNot): fix sign and promotion
+ (valUnaryPM, valComplement): fix sign and promotion,
+ (valNot): ANSI: result type is int (SDCC: unsigned char)
* support/regression/tests/uminus.c: speedup by removing superflous
test case 'int'
* support/regression/tests/onebyte.c: added promotion and signedness
tests for unary minus
* support/regressions/tests/bug-477927.c: disable warning about
uninitialized variables
+ * support/regression/tests/not.c: added
2005-12-28 Bernhard Held <bernhard AT bernhardheld.de>
}
/*--------------------------------------------------------------------*/
-/* cheapestVal - convert a val to the cheapest as possible value */
+/* cheapestVal - try to reduce 'signed int' to 'char' */
/*--------------------------------------------------------------------*/
static value *
cheapestVal (value *val)
{
- if (IS_FLOAT (val->type) || IS_FIXED (val->type) || IS_CHAR (val->type))
+ /* only int can be reduced */
+ if (!IS_INT(val->type))
return val;
/* long must not be changed */
if (SPEC_LONG(val->type))
return val;
- /* only int can be reduced */
- if (!IS_INT(val->type))
- return val;
-
/* unsigned must not be changed */
if (SPEC_USIGN(val->type))
return val;
else
SPEC_CVAL (val->etype).v_int = !SPEC_CVAL (val->etype).v_int;
- if (SPEC_NOUN(val->etype) == V_CHAR)
- {
- /* promote to 'signed int', cheapestVal() might reduce it again */
- SPEC_USIGN(val->etype) = 0;
- SPEC_NOUN(val->etype) = V_INT;
- }
- return cheapestVal (val);
}
+ /* ANSI: result type is int, value is 0 or 1 */
+ /* sdcc will hold this in an 'unsigned char' */
+ SPEC_USIGN(val->etype) = 1;
+ SPEC_LONG (val->etype) = 0;
+ SPEC_NOUN(val->etype) = V_CHAR;
return val;
}
--- /dev/null
+/** not.c test ! operator
+
+ ANSI: return type is int
+
+ attr: volatile,
+*/
+#include <testfwk.h>
+
+void
+testNot(void)
+{
+ signed char {attr} sc;
+ unsigned char {attr} uc;
+ unsigned int {attr} ui;
+ unsigned long {attr} ul;
+
+ sc = 0;
+ uc = 0;
+ ui = 0;
+ ul = 0;
+ /* remember: unsigned * signed -> unsigned */
+ /* signed * signed -> signed */
+ ASSERT(!( signed char) 0 * -1 < 0);
+ ASSERT(!(unsigned char) 0 * -1 < 0);
+ ASSERT(!sc * -1 < 0);
+ ASSERT(!uc * -1 < 0);
+ ASSERT(! 0 * -1 < 0);
+ ASSERT(! 0u * -1 < 0);
+ ASSERT(!ui * -1 < 0);
+ ASSERT(! 0l * -1 < 0);
+ ASSERT(! 0ul * -1 < 0);
+ ASSERT(!ul * -1 < 0);
+
+ ASSERT(!(char) 0 << 8 == 0x100);
+ ASSERT(!sc << 8 == 0x100);
+#if !defined(PORT_HOST)
+ ASSERT(!0 << 16 == 0);
+ ASSERT(!0l << 16 == 0);
+ ASSERT(!ui << 16 == 0);
+ ASSERT(!ul << 16 == 0);
+#endif
+}
uc = 0x80; r16 = ~uc; ASSERT(r16 == (short) 0xff7f); ASSERT(~uc < 0);
ASSERT(~ (char) 0x80 == (short) 0x007f); ASSERT(~ (char) 0x80 > 0);
ASSERT(~ (unsigned char) 0x80 == (short) 0xff7f); ASSERT(~ (unsigned char) 0x80 < 0);
+
+ ASSERT(~ 1 < 0);
+ ASSERT(~ 1u > 0);
+ ASSERT(~ 1l < 0);
+ ASSERT(~ 1ul > 0);
}
void
-testComp(void)
+testCompare(void)
{
{attrL} signed char c;
{attrR} unsigned char uc;
{
signed char {attrL} sc;
unsigned char {attrL} uc;
- unsigned int {attrL} us;
+ signed int {attrL} si;
+ unsigned int {attrL} ui;
+ signed long {attrL} sl;
unsigned long {attrL} ul;
- ASSERT (-(53ul) > 0);
+ ASSERT(-(53l ) < 0);
+ ASSERT(-(53ul) > 0);
ul = 53;
- ASSERT (-ul > 0);
-
- ASSERT (-(53u ) > 0);
- us = 53;
- ASSERT (-us > 0);
-
- ASSERT (-( 250 ) == -250);
+ ASSERT(-ul > 0);
+ sl = 53;
+ ASSERT(-sl < 0);
+
+ ASSERT(-(53 ) < 0);
+ ASSERT(-(53u ) > 0);
+ ui = 53;
+ ASSERT(-ui > 0);
+ si = 53;
+ ASSERT(-si < 0);
+
+ ASSERT(-( 250 ) == -250);
uc = 250;
- ASSERT (-uc == -250);
+ ASSERT(-uc == -250);
- ASSERT (-(-128 ) == 128);
+ ASSERT(-(-128 ) == 128);
sc = -128;
- ASSERT (-sc == 128);
+ ASSERT(-sc == 128);
}