Thread overview
Error: Incompatible declaration of runtime function `_d_arraybounds`
Aug 23
kinke
Aug 23
kinke
Aug 27
Kagamin
August 23
A little known fact is dmd actually provides index and length for RangeError in e2ir.d, but druntime doesn't do anything with it.

I just tried defining an object.d in ldc with this:

extern(C) void _d_arraybounds(string file, size_t line, size_t lwr, size_t upr, size_t length) {}


to take advantage of this data and ldc outright rejected it. I don't really know my way around the ldc source... what can I do about this?
August 23
On Sunday, 23 August 2020 at 13:25:30 UTC, Adam D. Ruppe wrote:
> A little known fact is dmd actually provides index and length for RangeError in e2ir.d, but druntime doesn't do anything with it.
>
> I just tried defining an object.d in ldc with this:
>
> extern(C) void _d_arraybounds(string file, size_t line, size_t lwr, size_t upr, size_t length) {}
>
>
> to take advantage of this data and ldc outright rejected it. I don't really know my way around the ldc source... what can I do about this?

Such hacks don't work with LDC and its strongly typed IR, so we don't pass these unused extra args. You can grep the src for `_d_arraybounds`, adjusting the signature of this runtime hook and the call site in DtoBoundsCheckFailCall(), but will have to adapt more code to forward the extra args to the latter function.
August 23
[e2ir.d is part of DMD's glue layer, not included by LDC.]
August 23
On 23 Aug 2020, at 14:25, Adam D. Ruppe via digitalmars-d-ldc wrote:
> I don't really know my way around the ldc source... what can I do about this?

Use grep. :P

---

~/ldc $ rg arraybounds
gen/runtime.cpp
554:  // void _d_arraybounds(string file, uint line)
555:  createFwdDecl(LINKc, Type::tvoid, {"_d_assert", "_d_arraybounds"},

gen/arrays.cpp
1365:        getRuntimeFunction(loc, irs->module, "_d_arraybounds");
---

You can add the extra parameters in gen/runtime.cpp (first hit), but you'll also need to update the bounds checking code to emit the extra argument (second hit).

 — David
August 23
On Sunday, 23 August 2020 at 13:41:18 UTC, kinke wrote:
> Such hacks don't work with LDC and its strongly typed IR, so we don't pass these unused extra args. You can grep the src for `_d_arraybounds`, adjusting the signature of this runtime hook and the call site in DtoBoundsCheckFailCall(), but will have to adapt more code to forward the extra args to the latter function.

Blargh.

I plan to get that info used in upstream dmd druntime eventually, but meh I'll keep living in darkness for now.

oh well
August 27
On Sunday, 23 August 2020 at 14:19:13 UTC, Adam D. Ruppe wrote:
> I plan to get that info used in upstream dmd druntime eventually, but meh I'll keep living in darkness for now.

Just call the extended function _d_arraybounds2 and you can live with both.