[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] missing check after calling type_size in classify_x86

From: Michael Matz
Subject: Re: [Tinycc-devel] missing check after calling type_size in classify_x86_64_arg
Date: Sat, 22 Jun 2019 01:17:16 +0200 (CEST)
User-agent: Alpine 2.21 (LSU 202 2017-01-01)


On Thu, 20 Jun 2019, Pascal Cuoq wrote:

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) {

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

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.

Yes, there are generally two contexts, and in one of them (e.g. decls with initializers) incomplete types are temporarily valid. So you'd either need two modes of type_size (one complaining), or two functions (or, as now, checking the size sometimes). If you want to invest more work than just adding a check in classify_x86_64_arg, instead add a function ctype_size (c for complete) which complains on incomplete types, and use it in places where the code really needs complete types (and doesn't yet check on its own).


reply via email to

[Prev in Thread] Current Thread [Next in Thread]