diff options
author | Bung <crc32@qq.com> | 2022-12-30 07:50:12 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-30 00:50:12 +0100 |
commit | c598d0b6eccd3133bfca710fc5fcc4576501862c (patch) | |
tree | ddc11b73bc0c389118c3c02bfea73d7798d1bd90 | |
parent | ebd1c678be5e0acee4fca67e1b7060234821ccf6 (diff) | |
download | Nim-c598d0b6eccd3133bfca710fc5fcc4576501862c.tar.gz |
fix #15117 zero size array cause incorrect codegen for VCC compiler (#21197)
fix #15117
-rw-r--r-- | compiler/ccgexprs.nim | 2 | ||||
-rw-r--r-- | tests/array/t15117.nim | 27 |
2 files changed, 29 insertions, 0 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index e2885a294..844a37997 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -3331,6 +3331,8 @@ proc genConstObjConstr(p: BProc; n: PNode; isConst: bool; result: var Rope) = proc genConstSimpleList(p: BProc, n: PNode; isConst: bool; result: var Rope) = result.add "{" + if p.vccAndC and n.len == 0 and n.typ.kind == tyArray: + getDefaultValue(p, n.typ[1], n.info, result) for i in 0..<n.len: let it = n[i] if i > 0: result.add ",\n" diff --git a/tests/array/t15117.nim b/tests/array/t15117.nim new file mode 100644 index 000000000..157b04bee --- /dev/null +++ b/tests/array/t15117.nim @@ -0,0 +1,27 @@ +discard """ + matrix: "--cc:vcc" + disabled: "linux" + disabled: "bsd" + disabled: "osx" + disabled: "unix" + disabled: "posix" +""" +{.experimental: "views".} + +let a: array[0, byte] = [] +discard a + +type B = object + a:int +let b: array[0, B] = [] +let c: array[0, ptr B] = [] +let d: array[0, ref B] = [] +discard b +discard c +discard d + +discard default(array[0, B]) + +type + View1 = openArray[byte] +discard default(View1) |