Skip to content

Commit

Permalink
codegen: Support {Not,Logical,Identity}Exp with non-bool type (for im…
Browse files Browse the repository at this point in the history
…portC AST)

Fixing failing LDC assertions.
  • Loading branch information
kinke committed Apr 30, 2022
1 parent 952e63b commit 7384bb7
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions gen/toir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ void pushVarDtorCleanup(IRState *p, VarDeclaration *vd) {
toElemDtor(vd->edtor);
p->funcGen().scopes.pushCleanup(beginBB, p->scopebb());
}

DImValue *zextInteger(LLValue *val, Type *to) {
assert(val->getType()->isIntegerTy());
LLType *llTy = DtoType(to);
if (val->getType() != llTy) {
assert(llTy->isIntegerTy());
val = gIR->ir->CreateZExt(val, llTy);
}
return new DImValue(to, val);
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1331,14 +1341,7 @@ class ToElemVisitor : public Visitor {
llvm_unreachable("Unsupported EqualExp type.");
}

// optionally zero-extend i1 to larger integer type
LLType *llTy = DtoType(e->type);
if (eval->getType() != llTy) {
assert(llTy->isIntegerTy());
eval = new llvm::ZExtInst(eval, llTy, "", gIR->scopebb());
}

result = new DImValue(e->type, eval);
result = zextInteger(eval, e->type);
}

//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1713,7 +1716,7 @@ class ToElemVisitor : public Visitor {
LLConstant *zero = DtoConstBool(false);
b = p->ir->CreateICmpEQ(b, zero);

result = new DImValue(e->type, b);
result = zextInteger(b, e->type);
}

//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1789,7 +1792,7 @@ class ToElemVisitor : public Visitor {
resval = phi;
}

result = new DImValue(e->type, resval);
result = zextInteger(resval, e->type);
}

//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1889,12 +1892,12 @@ class ToElemVisitor : public Visitor {

// handle dynarray specially
if (t1->ty == TY::Tarray) {
result = new DImValue(e->type, DtoDynArrayIs(e->op, l, r));
result = zextInteger(DtoDynArrayIs(e->op, l, r), e->type);
return;
}
// also structs
if (t1->ty == TY::Tstruct) {
result = new DImValue(e->type, DtoStructEquals(e->op, l, r));
result = zextInteger(DtoStructEquals(e->op, l, r), e->type);
return;
}

Expand Down Expand Up @@ -1941,7 +1944,7 @@ class ToElemVisitor : public Visitor {
: EXP::notEqual);
}
}
result = new DImValue(e->type, eval);
result = zextInteger(eval, e->type);
}

//////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 7384bb7

Please sign in to comment.