mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-11 18:33:14 +01:00
Properly handle DMD-internal "reference variables".
Previously, we just had a hack to make ref foreach statements work. This commit enables them to work in other cases as well, like the implicit __result variable for functions with out-contracts (which is such a magic ref variable for ref-returning functions). Fixes DMD testcase 'testcontracts'.
This commit is contained in:
@@ -16,6 +16,8 @@ DVarValue::DVarValue(Type* t, VarDeclaration* vd, LLValue* llvmValue)
|
||||
: DValue(t), var(vd), val(llvmValue)
|
||||
{
|
||||
assert(isaPointer(llvmValue));
|
||||
assert(!isSpecialRefVar(vd) ||
|
||||
isaPointer(isaPointer(llvmValue)->getElementType()));
|
||||
}
|
||||
|
||||
DVarValue::DVarValue(Type* t, LLValue* llvmValue)
|
||||
@@ -27,6 +29,8 @@ DVarValue::DVarValue(Type* t, LLValue* llvmValue)
|
||||
LLValue* DVarValue::getLVal()
|
||||
{
|
||||
assert(val);
|
||||
if (var && isSpecialRefVar(var))
|
||||
return DtoLoad(val);
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -34,9 +38,14 @@ LLValue* DVarValue::getRVal()
|
||||
{
|
||||
assert(val);
|
||||
Type* bt = type->toBasetype();
|
||||
|
||||
LLValue* tmp = val;
|
||||
if (var && isSpecialRefVar(var))
|
||||
tmp = DtoLoad(tmp);
|
||||
|
||||
if (DtoIsPassedByRef(bt))
|
||||
return val;
|
||||
return DtoLoad(val);
|
||||
return tmp;
|
||||
return DtoLoad(tmp);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user