mirror of
https://github.com/dlang/dmd.git
synced 2025-04-28 06:00:13 +03:00
Merge pull request #20580 from WalterBright/elstreq
optimize s=s where s is a struct
This commit is contained in:
commit
16c013abb9
2 changed files with 28 additions and 0 deletions
|
@ -3521,6 +3521,13 @@ elem * elstruct(elem *e, Goal goal)
|
||||||
return optelem(e, goal);
|
return optelem(e, goal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Replace (e = e) with (e, e)
|
||||||
|
if (e.Eoper == OPstreq && el_match(e.E1, e.E2))
|
||||||
|
{
|
||||||
|
e.Eoper = OPcomma;
|
||||||
|
return optelem(e, goal);
|
||||||
|
}
|
||||||
|
|
||||||
if (!e.ET)
|
if (!e.ET)
|
||||||
return e;
|
return e;
|
||||||
//printf("\tnumbytes = %d\n", cast(int)type_size(e.ET));
|
//printf("\tnumbytes = %d\n", cast(int)type_size(e.ET));
|
||||||
|
|
|
@ -2507,6 +2507,26 @@ void test20574()
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
struct S8
|
||||||
|
{
|
||||||
|
int x,y,z;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test8x(S8 s)
|
||||||
|
{
|
||||||
|
s = s;
|
||||||
|
return s.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
void test8()
|
||||||
|
{
|
||||||
|
S8 s;
|
||||||
|
s.y = 2;
|
||||||
|
assert(test8x(s) == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// All the various integer divide tests
|
// All the various integer divide tests
|
||||||
|
@ -2607,6 +2627,7 @@ int main()
|
||||||
test21835();
|
test21835();
|
||||||
testDoWhileContinue();
|
testDoWhileContinue();
|
||||||
test20574();
|
test20574();
|
||||||
|
test8();
|
||||||
|
|
||||||
printf("Success\n");
|
printf("Success\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue