mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-22 15:53:14 +01:00
Fixed problem in AssignExp where the result value might be uninitialized. see mini/assign1.d
This commit is contained in:
17
gen/toir.cpp
17
gen/toir.cpp
@@ -448,7 +448,7 @@ LLConstant* StringExp::toConstElem(IRState* p)
|
||||
|
||||
DValue* AssignExp::toElem(IRState* p)
|
||||
{
|
||||
Logger::print("AssignExp::toElem: %s | %s = %s\n", toChars(), e1->type->toChars(), e2->type ? e2->type->toChars() : 0);
|
||||
Logger::print("AssignExp::toElem: %s | (%s)(%s = %s)\n", toChars(), type->toChars(), e1->type->toChars(), e2->type ? e2->type->toChars() : 0);
|
||||
LOG_SCOPE;
|
||||
|
||||
if (e1->op == TOKarraylength)
|
||||
@@ -472,13 +472,16 @@ DValue* AssignExp::toElem(IRState* p)
|
||||
if (l->isSlice() || l->isComplex())
|
||||
return l;
|
||||
|
||||
LLValue* v;
|
||||
if (l->isVar() && l->isVar()->lval)
|
||||
v = l->getLVal();
|
||||
if (type->toBasetype()->ty == Tstruct && e2->type->isintegral())
|
||||
{
|
||||
// handle struct = 0;
|
||||
return l;
|
||||
}
|
||||
else
|
||||
v = l->getRVal();
|
||||
|
||||
return new DVarValue(type, v, true);
|
||||
{
|
||||
assert(type->equals(e2->type));
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
17
tests/mini/assign1.d
Normal file
17
tests/mini/assign1.d
Normal file
@@ -0,0 +1,17 @@
|
||||
module mini.assign1;
|
||||
|
||||
extern(C) int printf(char*, ...);
|
||||
|
||||
struct X
|
||||
{
|
||||
int a;
|
||||
alias a b;
|
||||
}
|
||||
void main()
|
||||
{
|
||||
X e = void;
|
||||
e.a = e.b = 5;
|
||||
printf("%d - %d\n", e.a, e.b);
|
||||
assert(e.a == 5);
|
||||
assert(e.a == e.b);
|
||||
}
|
||||
Reference in New Issue
Block a user