From 57880aed185e9b81e8c66a47c975d61e5d0eaaa3 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sat, 24 Aug 2019 15:04:31 +0300 Subject: [PATCH] compiler: fix linux crash --- compiler/parser.v | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/parser.v b/compiler/parser.v index d19caf5c89..b6c0c49b9f 100644 --- a/compiler/parser.v +++ b/compiler/parser.v @@ -2782,9 +2782,13 @@ fn (p mut Parser) array_init() string { // Need to do this in the second pass, otherwise it goes to the very top of the out.c file if !p.first_pass() { //if i == 0 { - //////p.cgen.set_placeholder(new_arr_ph, '$new_arr($i, $i, sizeof($typ), ($typ[$i]) { 0 ') + //p.cgen.set_placeholder(new_arr_ph, '$new_arr($i, $i, sizeof($typ), ($typ[]) { 0 ') //} else { - p.cgen.set_placeholder(new_arr_ph, '$new_arr($i, $i, sizeof($typ), ($typ[$i]) { ') + // Due to a tcc bug, the length needs to be specified. + // GCC crashes if it is. + cast := if p.pref.ccompiler == 'tcc' { '($typ[$i])' } else { '($typ[])' } + p.cgen.set_placeholder(new_arr_ph, + '$new_arr($i, $i, sizeof($typ), $cast { ') //} } typ = 'array_$typ'