Mercurial > projects > ldc
diff gen/toir.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 | dd4766851b37 |
children | a41a40deff73 |
line wrap: on
line diff
--- a/gen/toir.cpp Sat May 02 20:42:58 2009 +0200 +++ b/gen/toir.cpp Sun May 03 11:16:54 2009 +0200 @@ -2405,7 +2405,9 @@ return initval; // for dynamic arrays we need to put the initializer in a global, and build a constant dynamic array reference with the .ptr field pointing into this global - LLConstant* globalstore = new LLGlobalVariable(arrtype, true, LLGlobalValue::InternalLinkage, initval, ".dynarrayStorage", p->module); + // Important: don't make the global constant, since this const initializer might + // be used as an initializer for a static T[] - where modifying contents is allowed. + LLConstant* globalstore = new LLGlobalVariable(arrtype, false, LLGlobalValue::InternalLinkage, initval, ".dynarrayStorage", p->module); LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; LLConstant* globalstorePtr = llvm::ConstantExpr::getGetElementPtr(globalstore, idxs, 2);