Skip to content

[BUG] Stack overflow in some web browsers for an ocaml program that uses menhir to generate its parser #2122

@relokin

Description

@relokin

Apologies in advance, I haven't been able to isolate the problem and create a minimal test case. I will attempt to explain how the bug manifests itself hoping that I can get some help to debug further.

Describe the bug
herdtools7 uses js_of_ocaml to create a js interface for the herd7 memory model simulator. When running the js through certain browsers (for example, Chrome 141.0.7390.123 (Official Build) (arm64) on MacOS 15.1), we run into a Stack overflow exception. The bug can be reproduced here: https://diy.inria.fr/www/ by clicking at the play button at the bottom of the page. The Stack overflow exception is generated when the litmus test is parsed (left hand side window) and more specifically when the body of the main body of the litmus test is parsed (first instruction of P0, in the case of the default litmus test that is MOV W0,#1). The parser is generated using menhir and the parsing rules can be found here: https://github.com/herd/herdtools7/blob/master/lib/AArch64Parser.mly.

The Stack overflow exception is generated for AArch64 (one of the architecture supported in herd7), if we switch to x86 (using the drop down menu in the centre of the web page), the simulator works as expected. x86 (https://github.com/herd/herdtools7/blob/master/lib/X86Parser.mly) has simpler parser than AArch64. I've tried using --table to enable menhir's table backend but that didn't help either.

Expected behavior
Normally we would expect the parser to correctly parse the default litmus test and herd7 would proceed as normally. I can get the correct output if I run the generated js with some browsers (for example Safari Version 18.1 (20619.2.8.11.10) on MacOS 15.1) or node.js.

Versions

js_of_ocaml 5.5.0

I have found that this commit 29c693b seems to be the culprit, prior to it the generated js works as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions