Mercurial > projects > ldc
diff gen/arrays.cpp @ 1292:ad41053c336e
Make static int[] a = [1, 2]; a[0] = 4; not segfault
by making the array data ptr a non-const global variable.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sun, 03 May 2009 11:16:54 +0200 |
parents | 0686701178d3 |
children | c78fd2d30da1 |
line wrap: on
line diff
--- a/gen/arrays.cpp Sat May 02 20:42:58 2009 +0200 +++ b/gen/arrays.cpp Sun May 03 11:16:54 2009 +0200 @@ -317,7 +317,9 @@ return constarr; // for dynamic array we need to make a global with the data, so we have a pointer for the dynamic array - LLGlobalVariable* gvar = new LLGlobalVariable(constarr->getType(), true, LLGlobalValue::InternalLinkage, constarr, ".constarray", gIR->module); + // 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(constarr->getType(), false, LLGlobalValue::InternalLinkage, constarr, ".constarray", gIR->module); LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; LLConstant* gep = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2);