From 6bdf7f88e7bd9ad4baa61d0f4e6ed256328f3386 Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Fri, 15 Feb 2019 18:17:43 +0100 Subject: [PATCH] Account for front-end implicitly casting vector return values to static arrays (#2991) Fixes #2988. --- gen/tocall.cpp | 18 +++++++++++++++--- tests/compilable/gh2988.d | 11 +++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 tests/compilable/gh2988.d diff --git a/gen/tocall.cpp b/gen/tocall.cpp index ba528cade37..d52bda856e5 100644 --- a/gen/tocall.cpp +++ b/gen/tocall.cpp @@ -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: @@ -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 diff --git a/tests/compilable/gh2988.d b/tests/compilable/gh2988.d new file mode 100644 index 00000000000..007286ad137 --- /dev/null +++ b/tests/compilable/gh2988.d @@ -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]; +}