aboutsummaryrefslogtreecommitdiffstats
path: root/libacc
diff options
context:
space:
mode:
authorJack Palevich <jackpal@google.com>2009-11-09 12:52:45 +0800
committerJack Palevich <jackpal@google.com>2009-11-09 12:52:45 +0800
commit02effee6a9224b531cb3fe6eac8278b46b9fbe86 (patch)
tree310b38e74c5942a86975af4bcb32d3adab9b6e88 /libacc
parentf6eba8fac812c70087af225f207f2d924f6e1ffa (diff)
downloadsystem_core-02effee6a9224b531cb3fe6eac8278b46b9fbe86.tar.gz
system_core-02effee6a9224b531cb3fe6eac8278b46b9fbe86.tar.bz2
system_core-02effee6a9224b531cb3fe6eac8278b46b9fbe86.zip
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
Diffstat (limited to 'libacc')
-rw-r--r--libacc/acc.cpp2
-rw-r--r--libacc/tests/data/assignment.c9
-rw-r--r--libacc/tests/test.py5
3 files changed, 16 insertions, 0 deletions
diff --git a/libacc/acc.cpp b/libacc/acc.cpp
index 6d9213c7..808752e3 100644
--- a/libacc/acc.cpp
+++ b/libacc/acc.cpp
@@ -1666,6 +1666,7 @@ class Compiler : public ErrorSink {
pDestType->tag);
break;
}
+ setR0Type(pDestType);
}
virtual void loadR0FromR0() {
@@ -2836,6 +2837,7 @@ class Compiler : public ErrorSink {
pTargetType->tag);
break;
}
+ setR0Type(pTargetType);
}
virtual void loadR0FromR0() {
diff --git a/libacc/tests/data/assignment.c b/libacc/tests/data/assignment.c
new file mode 100644
index 00000000..4fc7801d
--- /dev/null
+++ b/libacc/tests/data/assignment.c
@@ -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;
+}
diff --git a/libacc/tests/test.py b/libacc/tests/test.py
index c982d16c..d9843011 100644
--- a/libacc/tests/test.py
+++ b/libacc/tests/test.py
@@ -426,6 +426,11 @@ result: 0
result: -2
""","""""")
+ def testAssignment(self):
+ self.compileCheck(["-R", "data/assignment.c"], """Executing compiled code:
+result: 7
+""","""""")
+
def testArray(self):
self.compileCheck(["-R", "data/array.c"], """Executing compiled code:
localInt: 3