Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006805OCamlback end (clambda to assembly)public2015-03-08 17:042015-12-03 18:03
Reporterchambart 
Assigned To 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version4.02.1 
Target Version4.03.0+dev / +beta1Fixed in Version4.03.0+dev / +beta1 
Summary0006805: Duplicated expression when compiling with -g
DescriptionWhen compiling this example extracted from frama-c, some expression
get duplicated, including variable declarations. Note that without -g
the generated output is correct.

This may no trigger any real bug with the current compiler, but the
absence of duplicated variables is something that I expect in my
flambda branch.
Steps To Reproducecompile with
  ocamlc -c -g -dlambda example.ml

the outputs contains this:

  (switch* switcher/1070
   case int 0:
    (let
      (match/1039 =a (field 1 match/1030)
       match/1040 =a (field 0 match/1039)
       match/1041 =a (field 0 match/1040))
      (catch
        (if (!= match/1041 1)
          (if (>= match/1041 3) (exit 2) (exit 6))
          (exit 2))
       with (6)
        (let
          (match/1055 =a (field 2 match/1030)
           match/1056 =a (field 0 match/1055)
           match/1057 =a (field 0 match/1056))
          (catch
            (if (!= match/1057 1)
              (if (>= match/1057 3) (exit 2) (exit 7))
              (exit 2))
           with (7) (exit 1)))))
   case int 1:
    (let
      (match/1039 =a (field 1 match/1030)
       match/1040 =a (field 0 match/1039)
       match/1041 =a (field 0 match/1040))
      (catch
        (if (!= match/1041 1)
          (if (>= match/1041 3) (exit 2) (exit 6))
          (exit 2))
       with (6)
        (let
          (match/1055 =a (field 2 match/1030)
           match/1056 =a (field 0 match/1055)
           match/1057 =a (field 0 match/1056))
          (catch
            (if (!= match/1057 1)
              (if (>= match/1057 3) (exit 2) (exit 7))
              (exit 2))
           with (7) (exit 1)))))
TagsNo tags attached.
Attached Files? file icon example.ml [^] (663 bytes) 2015-03-08 17:04 [Show Content]
diff file icon 6805.diff [^] (918 bytes) 2015-12-03 11:37 [Show Content]

- Relationships

-  Notes
(0014986)
frisch (developer)
2015-12-03 00:35
edited on: 2015-12-03 11:38

Bumping priority, as this sounds quite serious.

The bug is probably in switch.ml. It gets called from matching.ml to create a switch on integers 3, 5, 6, 7 and it produces a switch on arg-3 with cases 0, 1, 2, 3, 4 (instead of 0, 2, 3, 4).

I'm not familiar with this piece of code, but my analysis is the following:

  - When the set of cases is "dense" enough, it is compiled to a "integer switch".

  - In switch.ml, function make_switch, the array "tbl" is initialized with 0; this value will not be modified for "holes" in the set. This results in implicit sharing with the first case.

One could perhaps fix that by detecting in Switch.make_switch the presence of holes, and add one more "dummy" action for them. I've attached a tentative fix, but it would be good if someone more aware of this piece of code (Luc?) could look at it...

(0015019)
maranget (manager)
2015-12-03 18:03

Thank you for reporting and for the analysis.

In the described situation: switch emitted, some holes (missing constructors),
and no failure, some action must be choosed for holes. The action used
is the first of switch. Hence this action has to be declared shared.

All this is rather complex and not that robust. At least the PR is fixed.


- Issue History
Date Modified Username Field Change
2015-03-08 17:04 chambart New Issue
2015-03-08 17:04 chambart File Added: example.ml
2015-03-08 17:06 chambart Description Updated View Revisions
2015-03-18 15:06 doligez Status new => acknowledged
2015-03-18 15:06 doligez Target Version => 4.03.0+dev / +beta1
2015-12-03 00:35 frisch Note Added: 0014986
2015-12-03 00:35 frisch Severity minor => major
2015-12-03 09:55 frisch Note Edited: 0014986 View Revisions
2015-12-03 11:28 frisch Note Edited: 0014986 View Revisions
2015-12-03 11:37 frisch File Added: 6805.diff
2015-12-03 11:38 frisch Note Edited: 0014986 View Revisions
2015-12-03 18:03 maranget Note Added: 0015019
2015-12-03 18:03 maranget Status acknowledged => closed
2015-12-03 18:03 maranget Resolution open => fixed
2015-12-03 18:03 maranget Fixed in Version => 4.03.0+dev / +beta1
2017-02-23 16:35 doligez Category OCaml backend (code generation) => Back end (clambda to assembly)
2017-02-23 16:44 doligez Category Back end (clambda to assembly) => back end (clambda to assembly)


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker