Correctly compute the type of an assignment expression.

This change enables following types of statements to work correctly:

    a = b = 3;
    if ((a = getchar()) < 0) { ... }

This fixes 2232082 acc: assignment in comparison segfaults
This commit is contained in:
Jack Palevich 2009-11-09 12:52:45 +08:00
parent f6eba8fac8
commit 02effee6a9
3 changed files with 16 additions and 0 deletions

View file

@ -1666,6 +1666,7 @@ class Compiler : public ErrorSink {
pDestType->tag); pDestType->tag);
break; break;
} }
setR0Type(pDestType);
} }
virtual void loadR0FromR0() { virtual void loadR0FromR0() {
@ -2836,6 +2837,7 @@ class Compiler : public ErrorSink {
pTargetType->tag); pTargetType->tag);
break; break;
} }
setR0Type(pTargetType);
} }
virtual void loadR0FromR0() { virtual void loadR0FromR0() {

View file

@ -0,0 +1,9 @@
int main() {
int a = 0;
int b = 1;
a = b = 2; // Test that "b = 2" generates an rvalue.
if (a = 7) { // Test that a = 7 generates an rvalue.
b = 3;
}
return a;
}

View file

@ -424,6 +424,11 @@ result: 0
def testShort(self): def testShort(self):
self.compileCheck(["-R", "data/short.c"], """Executing compiled code: self.compileCheck(["-R", "data/short.c"], """Executing compiled code:
result: -2 result: -2
""","""""")
def testAssignment(self):
self.compileCheck(["-R", "data/assignment.c"], """Executing compiled code:
result: 7
""","""""") ""","""""")
def testArray(self): def testArray(self):