diff --git a/libacc/acc.cpp b/libacc/acc.cpp
index 6d9213c74cf57dc9021be1a31854f30d6ba14e75..808752e3070b03e833e3f9d7472f52c85a903483 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 0000000000000000000000000000000000000000..4fc7801d0a6d3fa9c955adba957365ab145fb262
--- /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 c982d16c36f25fffc06265fa9e343ee9c95d3f84..d9843011168b052b04a891ffe477dccbfc92bb53 100644
--- a/libacc/tests/test.py
+++ b/libacc/tests/test.py
@@ -424,6 +424,11 @@ result: 0
     def testShort(self):
         self.compileCheck(["-R", "data/short.c"], """Executing compiled code:
 result: -2
+""","""""")
+
+    def testAssignment(self):
+        self.compileCheck(["-R", "data/assignment.c"], """Executing compiled code:
+result: 7
 ""","""""")
 
     def testArray(self):