Hello,

the function type_size can fail and return -1 for an incomplete enum:

https://repo.or.cz/tinycc.git/blob/944fe7036c53613889deb66cb9d03da2407d6c85:/tccgen.c#l2800

In this case it leaves *a untouched.

When this happens when called from the function classify_x86_64_arg, it leads 
to using the automatic variable align uninitialized:

https://repo.or.cz/tinycc.git/blob/944fe7036c53613889deb66cb9d03da2407d6c85:/x86_64-gen.c#l1142

This scenario happens for some inputs files. I expect all inputs files that 
cause this to be invalid C programs, but a compiler that emits an error on 
invalid inputs is better than a compiler that displays undefined behavior on 
invalid inputs. An example of an input file causing execution to go through 
classify_x86_64_arg with type_size returning -1 is the following:

enum t f(int x) {
  while(1);
}

I was thinking of inserting a check like “if (size < 0) tcc_error("incomplete 
enum");” after the call to type_size in classify_x86_64_arg.

The function type_size is called from a lot of places so I didn't even consider 
making it abort directly instead, but if someone suggests it might be better I 
can look into it.

Pascal

_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to