1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-14 20:05:05 +00:00

Reverted E_ADDRESS_OF logic fix.

Added testcase.
This commit is contained in:
acqn 2022-09-01 12:56:46 +08:00
parent ce6ee1b891
commit dc001cb4be
4 changed files with 51 additions and 4 deletions

View File

@ -93,7 +93,8 @@ int ED_IsLocPrimaryOrExpr (const ExprDesc* Expr)
int ED_IsIndExpr (const ExprDesc* Expr)
/* Check if the expression is a reference to its value */
{
return (Expr->Flags & E_ADDRESS_OF) == 0 && !ED_IsLocNone (Expr);
return (Expr->Flags & E_ADDRESS_OF) == 0 &&
!ED_IsLocNone (Expr) && !ED_IsLocPrimary (Expr);
}
#endif
@ -281,7 +282,7 @@ ExprDesc* ED_AddrExpr (ExprDesc* Expr)
case E_LOC_EXPR:
Expr->Flags &= ~(E_MASK_LOC | E_MASK_RTYPE);
Expr->Flags |= E_ADDRESS_OF | E_LOC_PRIMARY | E_RTYPE_RVAL;
Expr->Flags |= E_LOC_PRIMARY | E_RTYPE_RVAL;
break;
default:

View File

@ -507,7 +507,8 @@ INLINE int ED_IsAddrExpr (const ExprDesc* Expr)
INLINE int ED_IsIndExpr (const ExprDesc* Expr)
/* Check if the expression is a reference to its value */
{
return (Expr->Flags & E_ADDRESS_OF) == 0 && !ED_IsLocNone (Expr);
return (Expr->Flags & E_ADDRESS_OF) == 0 &&
!ED_IsLocNone (Expr) && !ED_IsLocPrimary (Expr);
}
#else
int ED_IsIndExpr (const ExprDesc* Expr);

View File

@ -92,7 +92,6 @@ static void LoadAddress (unsigned Flags, ExprDesc* Expr)
g_leasp (Expr->IVal);
break;
case E_LOC_PRIMARY:
case E_LOC_EXPR:
if (Expr->IVal != 0) {
/* We have an expression in the primary plus a constant

View File

@ -0,0 +1,46 @@
/* Bug #1847 - struct field access */
#include <stdio.h>
struct TestStruct {
char a;
char b;
char c;
};
struct TestStruct s0[2] = { {0xFF, 0, 0xFF}, {0, 0x42, 0xFF} };
struct TestStruct* s0Ptr = s0;
#define TEST_READ_SUB(X, E) \
if ((X) != (E)) { \
printf(#X ": 0x%X, expected: 0x%X\n", (X), (E)); \
++failures; \
}
#define TEST_READ(S, I, F, E) \
TEST_READ_SUB(S[I].F, E) \
TEST_READ_SUB((&S[I])->F, E) \
TEST_READ_SUB((&S[I])[0].F, E) \
TEST_READ_SUB(S##Ptr[I].F, E) \
TEST_READ_SUB((&S##Ptr[I])->F, E) \
TEST_READ_SUB((&(S##Ptr[I]))[0].F, E) \
TEST_READ_SUB((&(*S##Ptr))[I].F, E) \
TEST_READ_SUB((&(*S##Ptr)+I)->F, E) \
TEST_READ_SUB((S##Ptr+I)->F, E) \
TEST_READ_SUB((S##Ptr+I)[0].F, E)
static unsigned failures = 0;
int main(void) {
struct TestStruct s1[2] = { {0xFF, 0, 0xFF}, {0, 42, 0xFF} };
struct TestStruct* s1Ptr = s1;
TEST_READ(s0, 1, b, 0x42)
TEST_READ(s1, 1, b, 42)
if (failures > 0) {
printf("Failures: %u\n", failures);
}
return 0;
}