diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-06-24 09:06:07 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-06-24 09:06:07 +0200 |
commit | 1742909c02f756cb948aa76335480049038cfafb (patch) | |
tree | 61cf93c063441f988bb3fdeca90592735b1822ac | |
parent | 8810e260f591a780feb251fa5dcaa195b2dcc366 (diff) |
Assert that type2llvm is never called with size 0
-rw-r--r-- | src/codegen.c | 26 |
1 files changed, 14 insertions, 12 deletions
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(); } |