Fix miscompilation / liveness errors for string operations [superceded] #3940
+566
−179
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes the random CI failures seen on arm64.
It turns out that the Cmm machtypes given to "pointer + offset" calculations used for all of the different varieties of string reads and writes are wrong. Some of them have been wrong for a very long time (30 years). They are currently given type
Int
, but in the case where the pointers may be into the OCaml heap (e.g. forstring
andbytes
rather thanBigstring.t
) they must have typeAddr
. Otherwise, CSE may apply, causing pointers into the middle of values to be live across a GC. For example inwarnings.ml
:This patch affects the system compiler as well as the flambda-backend compiler, hence the use of a patch file to fix the former. I will deal with getting this fixed upstream. The system compiler patch isn't currently as good as the flambda-backend patch since it doesn't special-case out-of-heap accesses.
There are a couple of other changes currently in here too, which can be discussed and maybe split:
Comballoc
acrossCcheckbound
, which can raise an exception. I need to discuss this with @stedolan though, maybe this is only required if the allocation is on the major heap? (This problem does not arise with the flambda-backend compiler since bounds checks are expanded before Flambda 2.)This bug was very troublesome to track down and @xclerc must be thanked for his help with this, especially since we thought there was a second bug, which was actually caused by a mistake in my hack for tracking down the first bug! Some of the CI changes in this PR were written by @xclerc .
Once the dust has settled I will re-enable the arm64 builds as required.