summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Palevich2009-11-08 22:52:45 -0600
committerJack Palevich2009-11-08 22:52:45 -0600
commit02effee6a9224b531cb3fe6eac8278b46b9fbe86 (patch)
tree310b38e74c5942a86975af4bcb32d3adab9b6e88
parentf6eba8fac812c70087af225f207f2d924f6e1ffa (diff)
downloadplatform-system-core-02effee6a9224b531cb3fe6eac8278b46b9fbe86.tar.gz
platform-system-core-02effee6a9224b531cb3fe6eac8278b46b9fbe86.tar.xz
platform-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
-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 6d9213c74..808752e30 100644
--- a/libacc/acc.cpp
+++ b/libacc/acc.cpp
@@ -1666,6 +1666,7 @@ class Compiler : public ErrorSink {
1666 pDestType->tag); 1666 pDestType->tag);
1667 break; 1667 break;
1668 } 1668 }
1669 setR0Type(pDestType);
1669 } 1670 }
1670 1671
1671 virtual void loadR0FromR0() { 1672 virtual void loadR0FromR0() {
@@ -2836,6 +2837,7 @@ class Compiler : public ErrorSink {
2836 pTargetType->tag); 2837 pTargetType->tag);
2837 break; 2838 break;
2838 } 2839 }
2840 setR0Type(pTargetType);
2839 } 2841 }
2840 2842
2841 virtual void loadR0FromR0() { 2843 virtual void loadR0FromR0() {
diff --git a/libacc/tests/data/assignment.c b/libacc/tests/data/assignment.c
new file mode 100644
index 000000000..4fc7801d0
--- /dev/null
+++ b/libacc/tests/data/assignment.c
@@ -0,0 +1,9 @@
1int main() {
2 int a = 0;
3 int b = 1;
4 a = b = 2; // Test that "b = 2" generates an rvalue.
5 if (a = 7) { // Test that a = 7 generates an rvalue.
6 b = 3;
7 }
8 return a;
9}
diff --git a/libacc/tests/test.py b/libacc/tests/test.py
index c982d16c3..d98430111 100644
--- a/libacc/tests/test.py
+++ b/libacc/tests/test.py
@@ -426,6 +426,11 @@ result: 0
426result: -2 426result: -2
427""","""""") 427""","""""")
428 428
429 def testAssignment(self):
430 self.compileCheck(["-R", "data/assignment.c"], """Executing compiled code:
431result: 7
432""","""""")
433
429 def testArray(self): 434 def testArray(self):
430 self.compileCheck(["-R", "data/array.c"], """Executing compiled code: 435 self.compileCheck(["-R", "data/array.c"], """Executing compiled code:
431localInt: 3 436localInt: 3