fix #20960 i = i && 1; fails at runtime (#20961)

This commit is contained in:
Walter Bright 2025-03-06 19:42:12 -08:00 committed by GitHub
parent 4c4b9aef4d
commit 8812065e8b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 8 deletions

View file

@ -1445,8 +1445,10 @@ final class CParser(AST) : Parser!AST
auto e = cparseOrExp();
while (token.value == TOK.andAnd)
{
e = new AST.CastExp(loc, e, AST.Type.tbool);
nextToken();
auto e2 = cparseOrExp();
e2 = new AST.CastExp(loc, e2, AST.Type.tbool);
e = new AST.LogicalExp(loc, EXP.andAnd, e, e2);
}
return e;
@ -1465,8 +1467,10 @@ final class CParser(AST) : Parser!AST
auto e = cparseAndAndExp();
while (token.value == TOK.orOr)
{
e = new AST.CastExp(loc, e, AST.Type.tbool);
nextToken();
auto e2 = cparseAndAndExp();
e2 = new AST.CastExp(loc, e2, AST.Type.tbool);
e = new AST.LogicalExp(loc, EXP.orOr, e, e2);
}
return e;

View file

@ -28,7 +28,6 @@ int testcppcomment()
void elemi()
{
#if 0 // TODO ImportC
int i;
i = 47;
@ -81,12 +80,10 @@ void elemi()
assert(i == 1);
i = ((i = 1),(!(i & 5))) && (i == 6);
assert(i == 0);
#endif
}
void elems()
{
#if 0 // TODO ImportC
short i;
i = 47;
@ -139,13 +136,11 @@ void elems()
assert(i == 1);
i = ((i = 1),(!(i & 5))) && (i == 6);
assert(i == 0);
#endif
}
void eleml()
{ long l;
#if 0 // TODO ImportC
l = 47;
l = l && 0;
assert(l == 0);
@ -196,13 +191,11 @@ void eleml()
assert(l == 1);
l = ((l = 1),(!(l & 5))) && (l == 6);
assert(l == 0);
#endif
}
void elemc()
{ char c;
#if 0 // TODO ImportC
c = 47;
c = c && 0;
assert(c == 0);
@ -253,7 +246,6 @@ void elemc()
assert(c == 1);
c = ((c = 1),(!(c & 5))) && (c == 6);
assert(c == 0);
#endif
}
void align() /* test alignment */