Skip to content

Commit f0a18be

Browse files
committed
Fix #4986 : wrong type for return value
1 parent 4168997 commit f0a18be

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

gen/statements.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "ir/irmodule.h"
3838
#include "llvm/IR/CFG.h"
3939
#include "llvm/IR/InlineAsm.h"
40+
#include "llvm/Support/Casting.h"
4041
#include <fstream>
4142
#include <math.h>
4243
#include <stdio.h>
@@ -307,6 +308,11 @@ class ToIRVisitor : public Visitor {
307308
irs->DBuilder.EmitStopPoint(fd->endloc);
308309
}
309310

311+
if (returnValue->getType() != funcType->getReturnType()) {
312+
assert(llvm::cast<llvm::AllocaInst>(returnValue)->getAllocatedType() == funcType->getReturnType());
313+
returnValue = DtoLoad(funcType->getReturnType(), returnValue);
314+
}
315+
310316
irs->ir->CreateRet(
311317
useRetValSlot ? DtoLoad(funcType->getReturnType(), funcGen.retValSlot)
312318
: returnValue);

tests/codegen/gh4986.d

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %ldc %s -c
2+
3+
struct Test
4+
{
5+
this(ref inout typeof(this) rhs) inout pure {}
6+
const(char)[] toString() const pure => null;
7+
alias toString this;
8+
}
9+
10+
const(char)[] test(ref Test t)
11+
{
12+
return t;
13+
}

0 commit comments

Comments
 (0)