mescc: Tinycc support: sizeof: Bugfix for c-array.

* module/language/c99/compiler.mes (->size): Bugfix for c-array.
* scaffold/tests/85-sizeof.c: Test it.
This commit is contained in:
Jan Nieuwenhuizen 2018-05-12 11:25:35 +02:00
parent ad9f171c49
commit e8969af4ca
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
2 changed files with 14 additions and 4 deletions

View file

@ -1552,7 +1552,7 @@
(apply max (map (compose ->size cdr) (struct->fields o))))
((type? o) (type:size o))
((pointer? o) %pointer-size)
((c-array? o) %pointer-size)
((c-array? o) (* (c-array:count o) ((compose type:size c-array:type) o)))
((local? o) ((compose ->size local:type) o))
((global? o) ((compose ->size global:type) o))
;; FIXME
@ -2087,7 +2087,8 @@
(info (if (null? strings) info
(clone info #:globals (append (.globals info) strings))))
(count (expr->number info count))
(type (make-c-array (rank++ type) count)))
(count1 (expr->number info count1))
(type (rank++ (make-c-array type (* %pointer-size count count1)))))
(if (.function info) (local->info type name o init info)
(global->info type name o init info))))
(_ (error "init-declr->info: not supported: " o))))

View file

@ -18,10 +18,19 @@
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
*/
struct foo
{
int length;
char buf[16];
};
int
main ()
{
char **p;
if (sizeof (*p) != 4) return 2;
return sizeof (**p) - 1;
if (sizeof (*p) != 4) return 1;
if (sizeof (**p) != 1) return 2;
puts ("size: "); puts (itoa (sizeof (struct foo))); puts ("\n");
if (sizeof (struct foo) != 20) return 3;
return 0;
}