1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-22 21:32:57 +00:00

Merge pull request #2233 from acqn/ArraySubscriptFix

[cc65] Fixed array subscript with a bit-field with patch by kugelfuhr
This commit is contained in:
Bob Andrews 2023-10-18 12:51:36 +02:00 committed by GitHub
commit bb1b5c363e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 2 deletions

View File

@ -3001,8 +3001,9 @@ static void parseadd (ExprDesc* Expr, int DoArrayRef)
}
if (!AddDone) {
if (ED_IsLocQuasiConst (&Expr2) &&
rscale == 1 &&
if (ED_IsLocQuasiConst (&Expr2) &&
!IsTypeBitField (Expr2.Type) &&
rscale == 1 &&
CheckedSizeOf (rhst) == SIZEOF_CHAR) {
/* Change the order back */
RemoveCode (&Mark);

39
test/val/bug2186.c Normal file
View File

@ -0,0 +1,39 @@
/* Bug #2186 - Wrong array indexing when index comes from bit-field */
#include <stdio.h>
unsigned failures;
typedef struct {
char flag : 1;
char index : 7;
} weird_type;
const char array[] = { '6', '5', '0', '2' };
weird_type data;
int main(void) {
data.flag = 1;
data.index = 0;
if (array[data.index] != array[0])
{
++failures;
printf("Got '%c', expected '%c'\n", array[data.index], array[0]);
}
data.index = 1;
if (array[data.index] != array[1])
{
++failures;
printf("Got '%c', expected '%c'\n", array[data.index], array[1]);
}
if (failures > 0)
{
printf("Failures: %u\n", failures);
}
return failures;
}