Skip to content

Commit 09a2b97

Browse files
committed
Final fix for issue ldc-developers#424
1 parent 978912e commit 09a2b97

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

dmd2/expression.h

+3
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,9 @@ class VectorExp : public UnaExp
13511351
Expression *semantic(Scope *sc);
13521352
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
13531353
elem *toElem(IRState *irs);
1354+
#if IN_LLVM
1355+
llvm::Constant *toConstElem(IRState *irs);
1356+
#endif
13541357
#if IN_DMD
13551358
dt_t **toDt(dt_t **pdt);
13561359
#endif

dmd2/init.c

-4
Original file line numberDiff line numberDiff line change
@@ -887,10 +887,6 @@ Initializer *ExpInitializer::semantic(Scope *sc, Type *t, NeedInterpret needInte
887887

888888
// Look for the case of statically initializing an array
889889
// with a single member.
890-
#if IN_LLVM
891-
// Fix for part 1 of issue 424.
892-
if (tb->ty == Tvector) tb = static_cast<TypeVector *>(tb)->basetype;
893-
#endif
894890
if (tb->ty == Tsarray &&
895891
!tb->nextOf()->equals(ti->toBasetype()->nextOf()) &&
896892
exp->implicitConvTo(tb->nextOf())

gen/toir.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -3551,6 +3551,32 @@ DValue* VectorExp::toElem(IRState* p)
35513551

35523552
//////////////////////////////////////////////////////////////////////////////////////////
35533553

3554+
llvm::Constant* VectorExp::toConstElem(IRState* p)
3555+
{
3556+
Logger::print("VectorExp::toConstElem: %s @ %s\n", toChars(), type->toChars());
3557+
LOG_SCOPE;
3558+
3559+
TypeVector *tv = static_cast<TypeVector*>(to->toBasetype());
3560+
assert(tv->ty == Tvector);
3561+
3562+
// The AST for
3563+
// static immutable ubyte16 vec1 = 123;
3564+
// differs from
3565+
// static immutable ubyte[16] vec1 = 123;
3566+
// In the vector case the AST contains an IntegerExp (of type int) and a
3567+
// CastExp to type ubyte. In the static array case the AST only contains an
3568+
// IntegerExp of type ubyte. Simply call optimize to get rid of the cast.
3569+
// FIXME: Check DMD source to understand why two different ASTs are
3570+
// constructed.
3571+
llvm::Constant *val = e1->optimize(WANTvalue)->toConstElem(p);
3572+
3573+
dinteger_t elemCount =
3574+
static_cast<TypeSArray *>(tv->basetype)->dim->toInteger();
3575+
return llvm::ConstantVector::getSplat(elemCount, val);
3576+
}
3577+
3578+
//////////////////////////////////////////////////////////////////////////////////////////
3579+
35543580
#define STUB(x) DValue *x::toElem(IRState * p) {error("Exp type "#x" not implemented: %s", toChars()); fatal(); return 0; }
35553581
STUB(Expression)
35563582
STUB(ScopeExp)

0 commit comments

Comments
 (0)