Skip to content

Commit

Permalink
Fix expression evaluation
Browse files Browse the repository at this point in the history
The below code wasn't compiling properly:
----8<----
typedef unsigned uint;

int main(void)
{
  uint a;

  a =  0 + sizeof(char[1])*0;
  a = -0 + sizeof(char[1])*0;
/**/  a = +0 + sizeof(char[1])*0; // error: lvalue expected

  labs( 0 + sizeof(char[1])*0);
  labs(-0 + sizeof(char[1])*0);
/**/  labs(+0 + sizeof(char[1])*0); // error: too many function arguments

  printf("%04X\n", (uint)( 0 + sizeof(char[1])*0));
  printf("%04X\n", (uint)(-0 + sizeof(char[1])*0));
  printf("%04X\n", (uint)(+0 + sizeof(char[1])*0)); // error: 1 printed but must be 0

  return 0;
}
----8<----
  • Loading branch information
alexfru committed Apr 20, 2024
1 parent 14fbce2 commit 07c78cf
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 2 deletions.
Binary file modified v0100/bind/smlrc.exe
Binary file not shown.
Binary file modified v0100/bindp/smlrc.exe
Binary file not shown.
Binary file modified v0100/binl/smlrc
Binary file not shown.
Binary file modified v0100/binm/smlrc
Binary file not shown.
Binary file modified v0100/binw/smlrc.dat
Binary file not shown.
7 changes: 5 additions & 2 deletions v0100/smlrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5720,10 +5720,13 @@ int ParseExpr(int tok, int* GotUnary, int* ExprTypeSynPtr, int* ConstExpr, int*
if (!j)
{
int idx = sp - 1;
int outer;
*ConstVal = exprval(&idx, ExprTypeSynPtr, ConstExpr);
outer = idx;
// remove the unneeded unary +'s that have served their cast-substitute purpose
// also remove dereferences of size 0 (dereferences of pointers to structures)
for (idx = sp - 1; idx >= 0; idx--)
// also remove dereferences of size 0 (dereferences of pointers to structures);
// do this only within the current subexpression
for (idx = sp - 1; idx > outer; idx--)
if (stack[idx][0] == tokUnaryPlus ||
(stack[idx][0] == tokUnaryStar && !stack[idx][1]))
del(idx, 1);
Expand Down

0 comments on commit 07c78cf

Please sign in to comment.