From 3c4db7bc873c884b95fea2a69c1f45d7fa2adf9f Mon Sep 17 00:00:00 2001 From: Alexey Prokhin Date: Sun, 2 Jan 2011 17:43:02 +0300 Subject: [PATCH] Fixed initialization of the static arrays --- gen/arrays.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gen/arrays.cpp b/gen/arrays.cpp index 8e3fe73d..54a3c113 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -435,10 +435,17 @@ LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit) if (arrty->ty == Tsarray) return constarr; - // for dynamic array we need to make a global with the data, so we have a pointer for the dynamic array + // we need to make a global with the data, so we have a pointer to the array // Important: don't make the gvar constant, since this const initializer might // be used as an initializer for a static T[] - where modifying contents is allowed. LLGlobalVariable* gvar = new LLGlobalVariable(*gIR->module, constarr->getType(), false, LLGlobalValue::InternalLinkage, constarr, ".constarray"); + +#if DMDV2 + if (arrty->ty == Tpointer) + // we need to return pointer to the static array. + return gvar; +#endif + LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; LLConstant* gep = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2);