tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] [PATCH v3] forbid invalid comparison of struct


From: Hitoshi Mitake
Subject: Re: [Tinycc-devel] [PATCH v3] forbid invalid comparison of struct
Date: Mon, 5 Nov 2012 22:53:16 +0900

On Mon, Nov 5, 2012 at 10:13 PM, Thomas Preud'homme <address@hidden> wrote:
> Le lundi 5 novembre 2012 14:01:20, Hitoshi Mitake a écrit :
>> Hi tcc folks.
>>
>> I found a trivial bug of tcc. Current tcc permits comparison of
>> structs and comparison between struct and other typed values. This
>> patch can fix the bug.
>>
>> I'm new to tcc. Sorry if this patch contains wrong part.
>> I'd like to hear your comments.
>>
>> v2: fix on the bug of mod branch
>> v3: fix the silly bug of v2
>>
>> Thanks,
>> ---
>>  tccgen.c |    2 ++
>>  1 files changed, 2 insertions(+), 0 deletions(-)
>>
>> diff --git a/tccgen.c b/tccgen.c
>> index 4e58ef0..f183913 100644
>> --- a/tccgen.c
>> +++ b/tccgen.c
>> @@ -1700,6 +1700,8 @@ ST_FUNC void gen_op(int op)
>>              (t2 & (VT_BTYPE | VT_UNSIGNED)) == (VT_LLONG | VT_UNSIGNED))
>>              t |= VT_UNSIGNED;
>>          goto std_op;
>> +    } else if (bt1 == VT_STRUCT || bt2 == VT_STRUCT) {
>> +        tcc_error("comparison of struct");
>>      } else {
>>          /* integer operations */
>>          t = VT_INT;
>
> Looks good. Thank you for making me realize that even struct equality is not
> possible in C. Because the assignment of struct is possible I was sure struct
> equality was possible. I let you commit it.
>

Thanks, I committed the change on the mob branch.

BTW, I've intended to implement comparison between structs
originally. And I found the bug accidentally.

Of course, comparison between different typed structs or structs and
scalar typed values should cause compile error. But I feel that if we
can write comparison between same struct typed values with ==
operator, a compiler will be very useful. Because we can avoid the
possibility of passing wrong value as 3rd parameter of memcmp().

The standard of C doesn't allow this behaviour. But I think it may be
worth implementing it on TCC. Can TCC accept this behaviour as
implementation specific dialect?

Thanks,

--
Hitoshi Mitake
address@hidden



reply via email to

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