From dcf005213b9bb6482271bcb04ef2a0032ce1b566 Mon Sep 17 00:00:00 2001 From: Alexey Prokhin Date: Sun, 8 Dec 2013 13:13:43 +0400 Subject: [PATCH] Implement cast to void --- gen/llvmhelpers.cpp | 8 -------- gen/toir.cpp | 10 +++------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 99309520..54df6b63 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -576,14 +576,6 @@ DValue* DtoCastInt(Loc& loc, DValue* val, Type* _to) return new DImValue(_to, rval); } - // Check for special DMD hack to avoid "has no effect" error. - // See expression.c, method AssignExp::semantic(), around line 11499 - llvm::ConstantInt* isConstInt = isaConstantInt(rval); - if (from == Type::tint32 && to == Type::tvoid && isConstInt->isNullValue()) - { - return val; - } - size_t fromsz = from->size(); size_t tosz = to->size(); diff --git a/gen/toir.cpp b/gen/toir.cpp index 537d5495..59db9692 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -1140,13 +1140,9 @@ DValue* CastExp::toElem(IRState* p) // get the value to cast DValue* u = e1->toElem(p); - // a constructor expression is casted to void in order to mark - // the value as unused. See expression.d, method AssignExp::semantic(), - // around line 11681 - if (to == Type::tvoid && e1->op == TOKconstruct) - { - return new DNullValue(Type::tvoid, 0); - } + // handle cast to void (usually created by frontend to avoid "has no effect" error) + if (to == Type::tvoid) + return new DImValue(Type::tvoid, llvm::UndefValue::get(voidToI8(DtoType(Type::tvoid)))); // cast it to the 'to' type, if necessary DValue* v = u;