Mercurial > projects > ldc
comparison 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 |
comparison
equal
deleted
inserted
replaced
1291:875afb7a93b6 | 1292:ad41053c336e |
---|---|
2403 // if static array, we're done | 2403 // if static array, we're done |
2404 if (!dyn) | 2404 if (!dyn) |
2405 return initval; | 2405 return initval; |
2406 | 2406 |
2407 // 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 | 2407 // 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 |
2408 LLConstant* globalstore = new LLGlobalVariable(arrtype, true, LLGlobalValue::InternalLinkage, initval, ".dynarrayStorage", p->module); | 2408 // Important: don't make the global constant, since this const initializer might |
2409 // be used as an initializer for a static T[] - where modifying contents is allowed. | |
2410 LLConstant* globalstore = new LLGlobalVariable(arrtype, false, LLGlobalValue::InternalLinkage, initval, ".dynarrayStorage", p->module); | |
2409 LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; | 2411 LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; |
2410 LLConstant* globalstorePtr = llvm::ConstantExpr::getGetElementPtr(globalstore, idxs, 2); | 2412 LLConstant* globalstorePtr = llvm::ConstantExpr::getGetElementPtr(globalstore, idxs, 2); |
2411 | 2413 |
2412 return DtoConstSlice(DtoConstSize_t(elements->dim), globalstorePtr); | 2414 return DtoConstSlice(DtoConstSize_t(elements->dim), globalstorePtr); |
2413 } | 2415 } |