From 9656560f144380bcebade03a6c10b8c186ad3874 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Sat, 3 Sep 2016 23:55:54 +0200 Subject: Fix sizeof(char[a]) The sizes of VLAs need to be evaluated even inside sizeof, i.e. when nocode_wanted is set. --- tests/tcctest.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/tcctest.c b/tests/tcctest.c index daf788c..4e51ea1 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -2456,6 +2456,16 @@ void sizeof_test(void) printf("__alignof__(char) = %d\n", __alignof__(char)); printf("__alignof__(unsigned char) = %d\n", __alignof__(unsigned char)); printf("__alignof__(func) = %d\n", __alignof__ sizeof_test()); + + /* sizes of VLAs need to be evaluated even inside sizeof: */ + a = 2; + printf("sizeof(char[1+2*a]) = %d\n", sizeof(char[1+2*a])); + /* And checking if sizeof compound literal works. Parenthesized: */ + printf("sizeof( (struct {int i; int j;}){4,5} ) = %d\n", + sizeof( (struct {int i; int j;}){4,5} )); + /* And as direct sizeof argument (as unary expression): */ + printf("sizeof (struct {short i; short j;}){4,5} = %d\n", + sizeof (struct {short i; short j;}){4,5} ); } void typeof_test(void) -- cgit v1.3.1