Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007563OCamlmiddle end (typedtree to clambda)public2017-06-23 01:442017-06-26 17:21
Reporterfahndrich 
Assigned Togasche 
PrioritynormalSeveritymajorReproducibilityalways
StatusresolvedResolutionfixed 
Platformx86OSLinuxOS VersionLinux-gnu Centos
Product Version4.03.0 
Target VersionFixed in Version4.06.0 +dev/beta1/beta2/rc1 
Summary0007563: value access to extensible variant tag binds module value instead (name clash)
DescriptionA reference from a module A to B picks up B.C (a module value) instead of B.C an extensible variant tag.

This results in a block with tag 0 containing the module values being passed around instead of an extensible variant value.

Repro is attached.
Steps To Reproduceocamlopt a_module.ml debug.ml variant.ml repro.ml -o repro
./repro

Prints:
Stored: a Clash
Direct: unknown: tag: 0, Size 3
  0: An int 0
  1: tag: 247, Size 2
    0: <unknown with tag 1001>
    1: An int 1
  2: tag: 247, Size 2
    0: <unknown with tag 1001>
    1: An int 1
Fatal error: exception Invalid_argument("compare: functional value")

The first print is getting the right variant value by accessing it via another name.
The second print is getting the wrong module value and I added some debug output to show the contents. As you can see the contents corresponds to the a_module contents (an int (empty list), and 2 closures).

The fatal error is trying to compare the ill-bound variant tag (which is really a module) and causing comparison of closures.
Additional InformationTested on 4.02.3, 4.03.0, 4.04.1, and 4.06.0+trunk and it fails in all cases.

(My category above is just a guess, middle end)
TagsNo tags attached.
Attached Filestgz file icon repro.tgz [^] (1,002 bytes) 2017-06-23 01:44

- Relationships

-  Notes
(0017947)
gasche (developer)
2017-06-23 06:18

Thanks for the report! The bug was introduced by module aliases in 4.02. Two ways to make the reproduction case simpler are:

- A_module does not need to be an external module, it can be declared above (but you need a definition of the form "module Alias = A_module", just "module Alias = struct .. end" would not work). On the other hand, the access to the conflict name needs to be from a different compilation unit.

- You can use "exception Clash" instead of the extensible datatype (anything that both uses transl_path in bytecomp/translcore.ml and has an uppercase last component would work), which allows to test the code under pre-4.02 version to check that the bug cannot be reproduced.

The following patch fixes the issue, but I am not sure that it is correct overall.

diff --git a/bytecomp/lambda.ml b/bytecomp/lambda.ml
index cca6315..b286772 100644
--- a/bytecomp/lambda.ml
+++ b/bytecomp/lambda.ml
@@ -535,7 +535,7 @@ let rec transl_normal_path = function
 (* Translation of value identifiers *)
 
 let transl_path ?(loc=Location.none) env path =
- transl_normal_path (Env.normalize_path (Some loc) env path)
+ transl_normal_path (Env.normalize_path_prefix (Some loc) env path)
 
 (* Compile a sequence of expressions *)
(0017948)
gasche (developer)
2017-06-23 06:32

Proposed fix (plus a regression testcase) sent at

  https://github.com/ocaml/ocaml/pull/1210 [^]
(0017949)
yallop (developer)
2017-06-23 09:33

For full dramatic effect, here's a way to turn the bug into a segmentation fault:

   $ ocaml
           OCaml version 4.04.0

   # module M = struct
       module X = List
       exception X
     end;;
   module M : sig module X = List exception X end
   # print_endline (Printexc.to_string M.X);;
   Segmentation fault
(0017956)
gasche (developer)
2017-06-23 13:12
edited on: 2017-06-23 17:45

Reporter: I am about to write a Changes entry, what is the name that should be used for crediting the report? Are you Manuel Fähndrich or Manuel Fahndrich? (Is it correct to assume that the first version is actually the correct one, despite the second one occurring more often on the internet?). If not, what name should be used to credit your work?

(0017969)
fahndrich (reporter)
2017-06-23 19:27

I'm the same person. Do I have 2 accounts? I dropped the umlaut a long time ago when I went to the US. I only use it in LaTeX papers :-)
(0017971)
gasche (developer)
2017-06-23 20:56

Well, googling for "site:caml.inria.fr/mantis fahndirch" only reported issues from way back, submitted also using your first name, so I preferred to ask than just assume. Thanks!
(0017995)
gasche (developer)
2017-06-26 17:21

GPR#1210 was merged after a round and review and some changes. It is only in the current trunk, so it will not be part of the next major release 4.05 that is frozen right now, but the following one (4.06).

Thanks for the report!

- Issue History
Date Modified Username Field Change
2017-06-23 01:44 fahndrich New Issue
2017-06-23 01:44 fahndrich File Added: repro.tgz
2017-06-23 06:18 gasche Note Added: 0017947
2017-06-23 06:32 gasche Note Added: 0017948
2017-06-23 09:33 yallop Note Added: 0017949
2017-06-23 13:12 gasche Note Added: 0017956
2017-06-23 17:45 gasche Note Edited: 0017956 View Revisions
2017-06-23 19:27 fahndrich Note Added: 0017969
2017-06-23 20:56 gasche Note Added: 0017971
2017-06-26 17:21 gasche Note Added: 0017995
2017-06-26 17:21 gasche Status new => resolved
2017-06-26 17:21 gasche Fixed in Version => 4.06.0 +dev/beta1/beta2/rc1
2017-06-26 17:21 gasche Resolution open => fixed
2017-06-26 17:21 gasche Assigned To => gasche


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker