From cc6fe6e5786f53f15c434dc10912418a470bb64a Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Mon, 2 Apr 2018 17:00:35 +0200 Subject: [PATCH] fixes codegen for nil cstrings --- compiler/ccgexprs.nim | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index dc06c84823..471f36d891 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -65,19 +65,24 @@ proc genLiteral(p: BProc, n: PNode, ty: PType): Rope = else: result = rope("NIM_NIL") of nkStrLit..nkTripleStrLit: - if n.strVal.isNil: + case skipTypes(ty, abstractVarRange).kind + of tyNil: result = ropecg(p.module, "((#NimStringDesc*) NIM_NIL)", []) - elif skipTypes(ty, abstractVarRange).kind == tyString: - let id = nodeTableTestOrSet(p.module.dataCache, n, p.module.labels) - if id == p.module.labels: - # string literal not found in the cache: - result = ropecg(p.module, "((#NimStringDesc*) &$1)", - [getStrLit(p.module, n.strVal)]) + of tyString: + if n.strVal.isNil: + result = ropecg(p.module, "((#NimStringDesc*) NIM_NIL)", []) else: - result = ropecg(p.module, "((#NimStringDesc*) &$1$2)", - [p.module.tmpBase, rope(id)]) + let id = nodeTableTestOrSet(p.module.dataCache, n, p.module.labels) + if id == p.module.labels: + # string literal not found in the cache: + result = ropecg(p.module, "((#NimStringDesc*) &$1)", + [getStrLit(p.module, n.strVal)]) + else: + result = ropecg(p.module, "((#NimStringDesc*) &$1$2)", + [p.module.tmpBase, rope(id)]) else: - result = makeCString(n.strVal) + if n.strVal.isNil: result = rope("NIM_NIL") + else: result = makeCString(n.strVal) of nkFloatLit, nkFloat64Lit: result = rope(n.floatVal.toStrMaxPrecision) of nkFloat32Lit: