windelbouwman / ppci

A compiler for ARM, X86, MSP430, xtensa and more implemented in pure Python
https://ppci.readthedocs.io/en/latest/
BSD 2-Clause "Simplified" License
335 stars 35 forks source link

ppci-cc: cannot compile combined struct assignment #108

Open tstreiff opened 4 years ago

tstreiff commented 4 years ago
#include <assert.h>

struct S { int a; } s1, s2, s3;

int main() {
    // simple struct assignment
    s1.a = 100;
    assert(s1.a == 100);
    s2 = s1;        // works
    assert(s2.a == 100);

    // combined struct assignment
    s1.a = 200;
    assert(s1.a == 200);
    s3 = s2 = s1;        // compiler exception, AssertionError
    assert(s2.a == 200);
    assert(s3.a == 200);
    return 0;
}

The compiler raises the following exception:

File "/home/tsf/sandbox/ppci/ppci/lang/c/codegenerator.py", line 1032, in gen_expr assert expr.lvalue AssertionError

Note that if "struct" is replaced by "union", it works.