From dd3cc5f682483d8365c6e36ebe7b9e0ef394e39e Mon Sep 17 00:00:00 2001 From: Kai Nacke Date: Mon, 16 Dec 2013 17:32:01 +0100 Subject: [PATCH 1/2] Fix for issue #553. This version uses the skipboundscheck member variable. --- gen/arrays.cpp | 20 ++------------------ gen/toir.cpp | 4 ++-- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/gen/arrays.cpp b/gen/arrays.cpp index ac203a20..db56c051 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -1135,24 +1135,8 @@ void DtoArrayBoundsCheck(Loc& loc, DValue* arr, DValue* index, DValue* lowerBoun assert((arrty->ty == Tsarray || arrty->ty == Tarray || arrty->ty == Tpointer) && "Can only array bounds check for static or dynamic arrays"); - // Do not emit bounds check code if the index is statically known to be - // within bounds. - if (arrty->ty == Tsarray && isaConstantInt(index->getRVal())) { - assert(!arr->isSlice()); - assert(!arr->isNull()); - assert(!lowerBound); - - TypeSArray *sarray = static_cast(arrty); - llvm::ConstantInt *constIndex = static_cast(index->getRVal()); - if (sarray->dim->toUInteger() < constIndex->getZExtValue()) { - // If this happens then it is possible a frontend bug. - // Just output a warning and continue generating a runtime check. - // This could be generic code which is never executed. - warning(loc, "Static array index out of bounds (should have been detected during semantic analysis)"); - } - else - return ; - } + // We do not check if the bounds check can be omitted. This is the + // responsibility of the caller and performed in IndexExp::toElem(). // runtime check diff --git a/gen/toir.cpp b/gen/toir.cpp index 777ab052..c75b5fd0 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -1715,12 +1715,12 @@ DValue* IndexExp::toElem(IRState* p) arrptr = DtoGEP1(l->getRVal(),r->getRVal()); } else if (e1type->ty == Tsarray) { - if (gIR->emitArrayBoundsChecks()) + if (gIR->emitArrayBoundsChecks() && !skipboundscheck) DtoArrayBoundsCheck(loc, l, r); arrptr = DtoGEP(l->getRVal(), zero, r->getRVal()); } else if (e1type->ty == Tarray) { - if (gIR->emitArrayBoundsChecks()) + if (gIR->emitArrayBoundsChecks() && !skipboundscheck) DtoArrayBoundsCheck(loc, l, r); arrptr = DtoArrayPtr(l); arrptr = DtoGEP1(arrptr,r->getRVal()); From e7fdbafe2dc5a63b100154df51d7edd89c31364a Mon Sep 17 00:00:00 2001 From: Kai Nacke Date: Wed, 18 Dec 2013 16:54:49 +0100 Subject: [PATCH 2/2] Fix generation of position-independent code. The new module discovery scheme requires the following section order: .minfo_beg .minfo .minfo_end This works for non-PIC code because the segments have the same attributes. However, if -relocation-model=pic is passed to ldc2 then the .minfo section becomes writeable and the sequence of sections is changed. The quick fix is to mark the data always as writeable. Then all sections are always writeable. I think a better solution would be to base this in the used relocation model. But this information is currently only available in the driver. This fixes the failure in test case runnable/eh2.d --- gen/module.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gen/module.cpp b/gen/module.cpp index ecf34baf..49988a86 100644 --- a/gen/module.cpp +++ b/gen/module.cpp @@ -394,7 +394,7 @@ static void build_dso_registry_calls(llvm::Constant* thisModuleInfo) llvm::GlobalVariable* minfoBeg = new llvm::GlobalVariable( *gIR->module, moduleInfoPtrTy, - true, + false, // FIXME: mRelocModel != llvm::Reloc::PIC_ llvm::GlobalValue::LinkOnceODRLinkage, getNullPtr(moduleInfoPtrTy), "_minfo_beg" @@ -408,7 +408,7 @@ static void build_dso_registry_calls(llvm::Constant* thisModuleInfo) llvm::GlobalVariable* thismref = new llvm::GlobalVariable( *gIR->module, moduleInfoPtrTy, - true, + false, // FIXME: mRelocModel != llvm::Reloc::PIC_ llvm::GlobalValue::LinkOnceODRLinkage, DtoBitCast(thisModuleInfo, moduleInfoPtrTy), thismrefname @@ -419,7 +419,7 @@ static void build_dso_registry_calls(llvm::Constant* thisModuleInfo) llvm::GlobalVariable* minfoEnd = new llvm::GlobalVariable( *gIR->module, moduleInfoPtrTy, - true, + false, // FIXME: mRelocModel != llvm::Reloc::PIC_ llvm::GlobalValue::LinkOnceODRLinkage, getNullPtr(moduleInfoPtrTy), "_minfo_end"