vnmakarov / mir

A lightweight JIT compiler based on MIR (Medium Internal Representation) and C11 JIT compiler and interpreter based on MIR
MIT License
2.24k stars 147 forks source link

c2mir: wrong result type caused by anonymous union #294

Open lone-wolf-akela opened 1 year ago

lone-wolf-akela commented 1 year ago
ubuntu@VM-8-15-ubuntu:~/project/mir$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:  Ubuntu 22.04.1 LTS
Release:  22.04
Codename: jammy
ubuntu@VM-8-15-ubuntu:~/project/mir$ uname -a
Linux VM-8-15-ubuntu 5.15.0-47-generic #51-Ubuntu SMP Thu Aug 11 07:51:15 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

ubuntu@VM-8-15-ubuntu:~/project/mir$ gcc --version
gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

ubuntu@VM-8-15-ubuntu:~/project/mir$ git log -1 --format="%H"
852b1f2e226001f355008004cc5ec2398889becc

ubuntu@VM-8-15-ubuntu:~/project/mir$ make
gcc -I. -MMD -MP -fPIC -g -std=gnu11 -Wno-abi -fsigned-char -fno-tree-sra -fno-ipa-cp-clone -O3 -DNDEBUG -DMIR_PARALLEL_GEN -c mir.c -o mir.o
gcc -I. -MMD -MP -fPIC -g -std=gnu11 -Wno-abi -fsigned-char -fno-tree-sra -fno-ipa-cp-clone -O3 -DNDEBUG -DMIR_PARALLEL_GEN -c mir-gen.c -o mir-gen.o
gcc -I. -MMD -MP -fPIC -g -std=gnu11 -Wno-abi -fsigned-char -fno-tree-sra -fno-ipa-cp-clone -O3 -DNDEBUG -DMIR_PARALLEL_GEN -c c2mir/c2mir.c -o c2mir/c2mir.o
ar rcs libmir.a mir.o mir-gen.o c2mir/c2mir.o
gcc -shared -Wl,-soname,libmir.so.0 -o libmir.so.0.0.3 mir.o mir-gen.o c2mir/c2mir.o
gcc -I. -MMD -MP -fPIC -g -std=gnu11 -Wno-abi -fsigned-char -fno-tree-sra -fno-ipa-cp-clone -O3 -DNDEBUG -DMIR_PARALLEL_GEN -c c2mir/c2mir-driver.c -o c2mir/c2mir-driver.o
gcc  c2mir/c2mir.o c2mir/c2mir-driver.o libmir.a -lm -ldl -lpthread -o c2m
gcc -I. -MMD -MP -fPIC -g -std=gnu11 -Wno-abi -fsigned-char -fno-tree-sra -fno-ipa-cp-clone -O3 -DNDEBUG -DMIR_PARALLEL_GEN -c mir-utils/m2b.c -o mir-utils/m2b.o
gcc  mir-utils/m2b.o libmir.a -lm -ldl -lpthread -o m2b ./libmir.a
gcc -I. -MMD -MP -fPIC -g -std=gnu11 -Wno-abi -fsigned-char -fno-tree-sra -fno-ipa-cp-clone -O3 -DNDEBUG -DMIR_PARALLEL_GEN -c mir-utils/b2m.c -o mir-utils/b2m.o
gcc  mir-utils/b2m.o libmir.a -lm -ldl -lpthread -o b2m ./libmir.a
gcc -I. -MMD -MP -fPIC -g -std=gnu11 -Wno-abi -fsigned-char -fno-tree-sra -fno-ipa-cp-clone -O3 -DNDEBUG -DMIR_PARALLEL_GEN -c mir-utils/b2ctab.c -o mir-utils/b2ctab.o
gcc  mir-utils/b2ctab.o libmir.a -lm -ldl -lpthread -o b2ctab  ./libmir.a

ubuntu@VM-8-15-ubuntu:~/project/mir$ cat test.c 
struct S
{
  int i;
  union {
    long long integer;
  };
};
struct S foo()
{
  struct S s;
  return s;
}

int main()
{
  return 0;
}

ubuntu@VM-8-15-ubuntu:~/project/mir$ ./c2m test.c 
wrong result type in func foo

ubuntu@VM-8-15-ubuntu:~/project/mir$ cat test2.c 
struct S
{
  int i;
  union {
    long long integer;
  } v;
};
struct S foo()
{
  struct S s;
  return s;
}

int main()
{
  return 0;
}

ubuntu@VM-8-15-ubuntu:~/project/mir$ ./c2m test2.c 

(this one success so no output)