From 2428285694099da27a4a4cff1ed9c446ca2d4f9e Mon Sep 17 00:00:00 2001 From: mrdudz Date: Thu, 9 Jul 2020 16:17:31 +0200 Subject: [PATCH] test for issue #327 --- test/todo/bug327.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/todo/bug327.c diff --git a/test/todo/bug327.c b/test/todo/bug327.c new file mode 100644 index 000000000..f6a79962b --- /dev/null +++ b/test/todo/bug327.c @@ -0,0 +1,34 @@ +/* bug #327 - Promoting u8 to s16 gives wrong result */ + +#include +#include + +static const uint8_t arr[2] = { + 0, + 255 +}; + +static int16_t get16() { + return -arr[1]; +} + +static int16_t get16_2() { + return -(int16_t) arr[1]; +} + +char res = 0; + +int main() { + + printf("Value %d, should be -255\n", get16()); + printf("Value %d, should be -255\n", get16_2()); + + if (get16() != -255) { + res++; + } + if (get16_2() != -255) { + res++; + } + + return res; +}