Skip to content

Commit

Permalink
Fix ICE when returning a void expression
Browse files Browse the repository at this point in the history
Fixes ldc-developers#3094, a regression introduced in v1.16 due to AST changes.
  • Loading branch information
kinke committed Jun 24, 2019
1 parent 3f2a930 commit b8ce275
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
11 changes: 8 additions & 3 deletions gen/statements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,16 @@ class ToIRVisitor : public Visitor {
if (!stmt->exp) {
// implicitly return 0 for the main function
returnValue = LLConstant::getNullValue(funcType->getReturnType());
} else if (f->type->next->toBasetype()->ty == Tvoid && !isMainFunc) {
// evaluate expression for side effects
assert(stmt->exp->type->toBasetype()->ty == Tvoid);
toElemDtor(stmt->exp);
} else if (funcType->getReturnType()->isVoidTy()) {
// if the function's return type is void, it uses sret
// if the IR function's return type is void (but not the D one), it uses
// sret
assert(!f->type->isref);

LLValue *sretPointer = getIrFunc(fd)->sretArg;
LLValue *sretPointer = f->sretArg;
assert(sretPointer);

assert(!f->irFty.arg_sret->rewrite &&
Expand Down Expand Up @@ -185,7 +190,7 @@ class ToIRVisitor : public Visitor {
}
} else {
// no return value expression means it's a void function.
assert(funcType->getReturnType() == LLType::getVoidTy(irs->context()));
assert(funcType->getReturnType()->isVoidTy());
}

// If there are no cleanups to run, we try to keep the IR simple and
Expand Down
13 changes: 13 additions & 0 deletions tests/codegen/gh3094.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: %ldc -run %s

void foo(void delegate() sink)
{
return (0, sink());
}

void main()
{
bool called;
foo(() { called = true; });
assert(called);
}

0 comments on commit b8ce275

Please sign in to comment.