Skip to content

Commit

Permalink
Account for front-end implicitly casting vector return values to stat…
Browse files Browse the repository at this point in the history
…ic arrays (#2991)

Fixes #2988.
  • Loading branch information
kinke committed Feb 15, 2019
1 parent 79a22f7 commit 6bdf7f8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
18 changes: 15 additions & 3 deletions gen/tocall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,8 +930,19 @@ DValue *DtoCallFunction(Loc &loc, Type *resulttype, DValue *fnval,
break;

case Tsarray:
// nothing ?
break;
if (nextbase->ty == Tvector && !tf->isref) {
if (retValIsLVal) {
retllval = DtoBitCast(retllval, DtoType(rbase->pointerTo()));
} else {
// static arrays need to be dumped to memory; use vector alignment
retllval =
DtoAllocaDump(retllval, DtoType(rbase), DtoAlignment(nextbase),
".vector_to_sarray_tmp");
retValIsLVal = true;
}
break;
}
goto unknownMismatch;

case Tclass:
case Taarray:
Expand All @@ -957,9 +968,10 @@ DValue *DtoCallFunction(Loc &loc, Type *resulttype, DValue *fnval,
retValIsLVal = true;
break;
}
// Fall through.
goto unknownMismatch;

default:
unknownMismatch:
// Unfortunately, DMD has quirks resp. bugs with regard to name
// mangling: For voldemort-type functions which return a nested
// struct, the mangled name of the return type changes during
Expand Down
11 changes: 11 additions & 0 deletions tests/compilable/gh2988.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %ldc -c %s

import core.simd;

float4 getVector() { return float4(1.0f); }

void foo()
{
// front-end implicitly casts from float4 to float[4]
float x = getVector()[0];
}

0 comments on commit 6bdf7f8

Please sign in to comment.