motoko icon indicating copy to clipboard operation
motoko copied to clipboard

Potential bug in compiler: local variable read before written in generated code

Open osa1 opened this issue 4 years ago • 5 comments

https://github.com/dfinity/motoko/blob/0b05b2428fcf427ba58fa70223dd587f18d21dce/src/codegen/compile.ml#L5308

In this line get_refs_start is used but there are no uses of set_refs_start in the same function. Wasm zero initializes local variables, so I'm guessing 0 is a valid value for "refs_start", but since we never update that local, if this local is deliberately not initialized (or updated), we could use a constant instead to be more direct and avoid confusion.

I'm also surprised that we don't get "unused variable" warnings in compile.ml. This could hide a lot of bugs. Was enabling "unused variable" warnings considered before?

osa1 avatar Sep 27 '21 08:09 osa1

I’d just rip out all the reference buffer handling code. We don’t have these kinds of references anywhere on the IC , and I expect by the time we get them (if at all), we’ll have rewritten that code plenty of times.

(Technically, the code is correct: The reference buffer lives at position 0 with size 0. But yeah, this better be cleaned up.)

nomeata avatar Sep 27 '21 09:09 nomeata

I’d just rip out all the reference buffer handling code. We don’t have these kinds of references anywhere on the IC

Which code do you mean? I don't understand this code in detail and have no idea which part you mean.

osa1 avatar Sep 27 '21 11:09 osa1

Did you read https://www.joachim-breitner.de/blog/786-A_Candid_explainer__Quirks? The first section is relevant.

nomeata avatar Sep 27 '21 13:09 nomeata

Is it really worth ripping this out? We might get them some day.... At least, record the commit that removes support in an issue somewhere... so we can easily recover it.

crusso avatar Sep 28 '21 10:09 crusso

We can also just leave it as it. But I'd rip it out before investing more into it

nomeata avatar Sep 28 '21 11:09 nomeata