Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of OCaml code by ocamlyacc #1012

merged 10 commits into from May 17, 2017

Fix parsing of OCaml code by ocamlyacc #1012

merged 10 commits into from May 17, 2017


Copy link

ocamlyacc would missparse certain valid OCaml code. As shown in MPR#7454 and MPR#7455, this can cause valid .mly files to be rejected, and for certain invalid files to be compiled to OCaml code that segfaults, without the .mly file containing any unsafe functions.

This patch fixes both problems.

yacc/closure.c Outdated Show resolved Hide resolved
yacc/main.c Outdated Show resolved Hide resolved
yacc/reader.c Show resolved Hide resolved
Copy link

dra27 commented Jan 15, 2017

Thanks for the patch - a few things, though, please. There are various things which look unrelated to the two PRs (sorry if I'm misreading the code) - this single commit seems to combine some tidying, some necessary refactoring and fixing two PRs. I think I'm correct that fixing the actual code changes for the two PRs are not directly related, so please could you split it into four commits to create a slightly more bisect-able story:

  1. Tidying any superfluous code (is that just a legacy of its original porting from yacc?)
  2. Refactoring: the moving of caml_ident_start, etc. and moving unchanged bodies of code out to process_quoted_string, etc.
  3. Fix one PR
  4. Fix the other PR

Please also do a Changes entry (again, these aren't related so it should be really be two entries - it's fine fixing in one pull request, of course) and if you could bear to turn the two sample files you sent into testsuite tests, that would be great (I can do that afterwards if you don't have time/inclination).

The %ident and %union directives don't make sense for OCaml,
and generated broken OCaml code.  Just drop support for them.
The processing of apostrophes, quoted strings and comments was
duplicated in at least two places.  This refactors both into

Also move the bitmap code, for use by later changes.
This adds support for parsing of raw OCaml strings.
This uses an explicit stack to keep track of parentheses and curly
braces in actions.
A'"'" was misparsed (the ' was not associated with the A as it should
This adds a partial testcase for the better lexing of
OCaml code by ocamlyacc, as well as a bug fix.
It was left from the conversion of Berkely Yacc to ocamlyacc
Copy link
Contributor Author

@dra27 done.

Copy link

dra27 commented May 16, 2017

Sorry for the delay looking at this - many thanks for the refactoring and the extra parts! I'm just running it through the full CI at Inria, as that includes a few other C compilers, but I propose merging once that's complete.

@dra27 dra27 added the approved label May 16, 2017
Copy link

dra27 commented May 17, 2017

OK, the failures in precheck on mingw32/mingw64 are unrelated, so merging.

@dra27 dra27 merged commit 472ee2c into ocaml:trunk May 17, 2017
Copy link

gasche commented Jul 12, 2017

In the Changes file, this change is marked as compatibility-breaking (use of the * bullet instead of -). @DemiMarie, how does it break compatibility (besides fixing wrong behaviors)?

Copy link
Contributor Author

DemiMarie commented Jul 14, 2017 via email

Copy link

gasche commented Jul 14, 2017

Thanks, I fixed the Changes in #1241.

sadiqj pushed a commit to sadiqj/ocaml that referenced this pull request Feb 21, 2023
stedolan pushed a commit to stedolan/ocaml that referenced this pull request Mar 21, 2023
stedolan pushed a commit to stedolan/ocaml that referenced this pull request Mar 21, 2023
b11eea1 flambda-backend: Introduce Import_info (ocaml#1036)
bc5b135 flambda-backend: Fix `ocamlobjinfo` on flambda2 .cmx files (ocaml#1029)
c8babbd flambda-backend: Compilation_unit optimisations (ocaml#1035)
e8d3e22 flambda-backend: Use 4.14.0 opam switch for building (includes upgrading ocamlformat to 0.24.1) (ocaml#1030)
eb14a86 flambda-backend: Port PR81 from ocaml-jst (ocaml#1024)
131bc12 flambda-backend: Merge ocaml-jst 2022-12-13 (ocaml#1022)
06c189a flambda-backend: Make stack allocation the default (ocaml#1013)
98debd5 flambda-backend: Initial support for value slots not of value kind (ocaml#946)
deb1714 flambda-backend: Add is_last flag to closinfo words (ocaml#938)
d07fce1 flambda-backend: Disable poll insertion in Configure (ocaml#967)
0f1ce0e flambda-backend: Regenerate ocaml/configure autoconf 2.69 (instead of 2.71) (ocaml#1012)
27132d8 flambda-backend: Fix for spurious typing error related to expanding through functor arguments (ocaml#997)
724fb68 flambda-backend: Use `Compilation_unit.t` instead of `Ident.t` for globals (ocaml#871)
396d5b8 flambda-backend: Add a test for frametable setup in natdynlinked libraries (ocaml#983)
b73ab12 flambda-backend: Fix invocation of `caml_shared_startup` in native dynlink (ocaml#980)
7c7d75a flambda-backend: Fix split_default_wrapper which did not trigger anymore with flambda2 (ocaml#970)
8fb75bd flambda-backend: Port ocaml#11727 and ocaml#11732 (ocaml#965)
fdb7987 flambda-backend: Fix include functor issue after 4.14 merge. (ocaml#948)
9745cdb flambda-backend: Print -dprofile/-dtimings output to stdout like 4.12 (ocaml#943)
5f51f21 flambda-backend: Merge pull request ocaml#932 from mshinwell/4.14-upgrade
841687d flambda-backend: Run make alldepend in ocaml/ (ocaml#936)
72a7658 flambda-backend: Remove reformatting changes only in dynlink/dune (preserving PR889 and adjusting to minimise diff)
6d758cd flambda-backend: Revert whitespace changes in dune files, to match upstream
c86bf6e flambda-backend: Remove duplicate tests for polling
971dbeb flambda-backend: Testsuite fixes
32f8356 flambda-backend: Topeval fix for symbols patch
befea01 flambda-backend: Compilation fixes / rectify merge faults
a84543f flambda-backend: Merge ocaml-jst
8e65056 flambda-backend: Merge ocaml-jst
4d70045 flambda-backend: Remove filename from system frametable (amd64) (ocaml#920)
5e57b7d flambda-backend: Bugfix for runtime frame_descr logic for C frames (ocaml#918)
6423d5e flambda-backend: Merge pull request ocaml#914 from mshinwell/merge-ocaml-jst-2022-10-24
ead605c flambda-backend: Add a missing Extract_exception (ocaml#916)
c8f1481 flambda-backend: Resolve conflicts and add specialise/specialised attributes to Builtin_attributes
cf4d0d3 flambda-backend: Merge fixes (ocaml#21)
c2f742f flambda-backend: Re-enable some tests for Flambda2 (ocaml#881)
3d38d13 flambda-backend: Long frames in frametable (ocaml#797)
85aec7b flambda-backend: Add loop attribute to Builtin_attributes
c0f16e3 flambda-backend: Compilation fixes
90dea23 flambda-backend: Merge flambda-backend/main
5acc6ea flambda-backend: Fixes after merge
e501946 flambda-backend: Merge ocaml-jst
115083b flambda-backend: Merge ocaml-jst
9943b2e flambda-backend: Revert "Revert "Transform tail-recursive functions into recursive continuations (ocaml#893)"" (ocaml#909)
ce339f1 flambda-backend: Fix alloc modes and call kinds for overapplications (ocaml#902)
e6a317c flambda-backend: Revert "Transform tail-recursive functions into recursive continuations (ocaml#893)"
853c488 flambda-backend: Transform tail-recursive functions into recursive continuations (ocaml#893)
5a977e4 flambda-backend: Fix missing End_region primitives on switch arms (ocaml#898)
7fa7f9d flambda-backend: Add missing dependencies to Dune files (ocaml#889)
3cd36f0 flambda-backend: Have Lambda `Pgetglobal` and `Psetglobal` take `Compilation_unit.t` (ocaml#896)
7565915 flambda-backend: [@poll error] attribute (ocaml#745)
9eb9448 flambda-backend: Backport the main safepoints PRs (ocaml#740)
689bdda flambda-backend: Add strict mode for ocamldep (ocaml#892)

git-subtree-dir: ocaml
git-subtree-split: b11eea1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging this pull request may close these issues.

None yet

3 participants