From 1742909c02f756cb948aa76335480049038cfafb Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Mon, 24 Jun 2024 09:06:07 +0200 Subject: Assert that type2llvm is never called with size 0 --- src/codegen.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/codegen.c b/src/codegen.c index d036b74..e33e864 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -378,20 +378,22 @@ type2llvm(struct cgctx ctx, type_t t) case TYPE_FN: err("codegen: %s: Not implemented for function types", __func__); case TYPE_NUM: + assert(t.size != 0); assert((unsigned)t.size * 8 <= 128); - if (t.isfloat) { - switch (t.size) { - case 2: return LLVMHalfTypeInContext(ctx.ctx); - case 4: return LLVMFloatTypeInContext(ctx.ctx); - case 0: - case 8: return LLVMDoubleTypeInContext(ctx.ctx); - case 16: return LLVMFP128TypeInContext(ctx.ctx); - default: __builtin_unreachable(); - } + if (!t.isfloat) + return LLVMIntTypeInContext(ctx.ctx, t.size * 8); + switch (t.size) { + case 2: + return LLVMHalfTypeInContext(ctx.ctx); + case 4: + return LLVMFloatTypeInContext(ctx.ctx); + case 8: + return LLVMDoubleTypeInContext(ctx.ctx); + case 16: + return LLVMFP128TypeInContext(ctx.ctx); + default: + __builtin_unreachable(); } - if (t.size == 0) - return LLVMIntPtrTypeInContext(ctx.ctx, ctx.td); - return LLVMIntTypeInContext(ctx.ctx, t.size * 8); default: __builtin_unreachable(); } -- cgit v1.2.3