From 86563a2ee181ef88afe4eb1b876e0cddc9b96ad3 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Fri, 14 Jun 2013 16:01:09 +0200 Subject: [PATCH] Allow casting AAs to bool. Fixed DMD testcase 'nulltype'. --- gen/llvmhelpers.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index d78c8e26..1339dc1b 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -821,6 +821,13 @@ DValue* DtoCast(Loc& loc, DValue* val, Type* to) LLValue *rval = DtoBitCast(val->getRVal(), DtoType(to)); return new DImValue(to, rval); } + else if (totype->ty == Tbool) + { + IF_LOG Logger::println("Casting AA to bool."); + LLValue* rval = val->getRVal(); + LLValue* zero = LLConstant::getNullValue(rval->getType()); + return new DImValue(to, gIR->ir->CreateICmpNE(rval, zero)); + } // Else try dealing with the rewritten (struct) type. fromtype = static_cast(fromtype)->getImpl()->type;