mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 21:21:48 +03:00
Fix 24072 - cast(__vector) array literal incorrectly triggers GC error
This commit is contained in:
parent
b9f8e7cf24
commit
3d552df287
4 changed files with 29 additions and 8 deletions
|
@ -1630,6 +1630,13 @@ Expression castTo(Expression e, Scope* sc, Type t, Type att = null)
|
|||
}
|
||||
else if (tob.ty == Tvector && t1b.ty != Tvector)
|
||||
{
|
||||
if (t1b.ty == Tsarray)
|
||||
{
|
||||
// Casting static array to vector with same size, e.g. `cast(int4) int[4]`
|
||||
if (t1b.size(e.loc) != tob.size(e.loc))
|
||||
goto Lfail;
|
||||
return new VectorExp(e.loc, e, tob).expressionSemantic(sc);
|
||||
}
|
||||
//printf("test1 e = %s, e.type = %s, tob = %s\n", e.toChars(), e.type.toChars(), tob.toChars());
|
||||
TypeVector tv = tob.isTypeVector();
|
||||
Expression result = new CastExp(e.loc, e, tv.elementType());
|
||||
|
|
|
@ -8489,14 +8489,6 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
|
|||
return setError();
|
||||
}
|
||||
|
||||
// Look for casting to a vector type
|
||||
if (tob.ty == Tvector && t1b.ty != Tvector)
|
||||
{
|
||||
result = new VectorExp(exp.loc, exp.e1, exp.to);
|
||||
result = result.expressionSemantic(sc);
|
||||
return;
|
||||
}
|
||||
|
||||
Expression ex = exp.e1.castTo(sc, exp.to);
|
||||
if (ex.op == EXP.error)
|
||||
{
|
||||
|
|
|
@ -119,3 +119,12 @@ void f(bool cond, string s) @nogc {
|
|||
alias Unused2 = typeof(&inner); // (Does not) INFERS GC (anymore)
|
||||
enum Unused3 = __traits(compiles , &inner);
|
||||
}
|
||||
|
||||
// https://issues.dlang.org/show_bug.cgi?id=24072
|
||||
|
||||
version (D_SIMD) void f24072() @nogc
|
||||
{
|
||||
alias int4 = __vector(int[4]);
|
||||
int4 b = cast(int4)[1, 2, 3, 4];
|
||||
int4 c = cast(int4)[1, 2];
|
||||
}
|
||||
|
|
13
compiler/test/fail_compilation/vector_cast.d
Normal file
13
compiler/test/fail_compilation/vector_cast.d
Normal file
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
REQUIRED_ARGS: -m64
|
||||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/vector_cast.d(11): Error: cannot cast expression `a` of type `int[3]` to `__vector(int[4])`
|
||||
fail_compilation/vector_cast.d(13): Error: cannot cast expression `a` of type `int[5]` to `__vector(int[4])`
|
||||
---
|
||||
*/
|
||||
|
||||
alias int4 = __vector(int[4]);
|
||||
int4 convtest3(int[3] a) { return cast(int4) a; }
|
||||
int4 convtest4(int[4] a) { return cast(int4) a; }
|
||||
int4 convtest5(int[5] a) { return cast(int4) a; }
|
Loading…
Add table
Add a link
Reference in a new issue