Merge pull request #2242 from acqn/SwitchFix

[cc65] Fixed type promotion of switch case values
This commit is contained in:
Bob Andrews
2023-10-26 16:56:01 +02:00
committed by GitHub
2 changed files with 122 additions and 43 deletions

View File

@@ -0,0 +1,77 @@
/* Bug #2019 - Type promotion in switch statements seems to be broken */
#include <limits.h>
#include <stdio.h>
unsigned failures;
int f1(void)
{
unsigned char c = 0xFF;
switch (c) {
case (signed char)0xFF: break;
case (unsigned char)0xFF: return 0;
}
return -1;
}
int f2(void)
{
signed char c = SCHAR_MIN;
switch (c) {
case (unsigned char)SCHAR_MIN: break;
case SCHAR_MIN: return 0;
}
return -1;
}
int f3(void)
{
signed int c = (int)UINT_MAX;
switch (c) {
case UINT_MAX: return 0;
}
return -1;
}
int f4(void)
{
unsigned int c = UINT_MAX;
switch (c) {
case -1L: return 0;
}
return -1;
}
int main(void)
{
if (f1())
{
++failures;
printf("f1() failed\n");
}
if (f2())
{
++failures;
printf("f2() failed\n");
}
if (f3())
{
++failures;
printf("f3() failed\n");
}
if (f4())
{
++failures;
printf("f4() failed\n");
}
if (failures > 0)
{
printf("failures: %u\n", failures);
}
return failures;
}