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

crashing ocamlopt (Alpha) #2396

Closed
vicuna opened this issue Mar 15, 2000 · 5 comments
Closed

crashing ocamlopt (Alpha) #2396

vicuna opened this issue Mar 15, 2000 · 5 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Mar 15, 2000

Original bug ID: 58
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Hello,

when I tried out my additions to the standard library with your latest
CVS-version (OCaml 2.99+10, date 15.03.2000), I found a bug which is
obviously in the native code generator.

Platform: Digital Unix 4.0e / Alpha

I have attached a simplified version of an offending module at the end of
this report. Other programs may also cause this, as I noticed.

The output of the compiler varies when one changes offending files:
sometimes it core dumps, sometimes it raises an exception, etc. With this
specific file, the following output occurs on my machine:

spilled-i/116 spilled-x/117 spilled-env/118 spilled-res/119
@`ï``b`````/119

Fatal error: Liveness.fundecl
Uncaught exception: Misc.Fatal_error

I know that the CVS-version is alpha-software, but I wanted to test
compilation of the system with my new stdlib-functions (which work well, as
I have verified).

Best regards and good bug hunting,
Markus Mottl

--
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl

file: pres_impl.ml
compile with: ocamlopt.opt -c pres_impl.ml

module type Implementation = sig
type 'a t
val name : string
val length : 'a t -> int
val make : int -> 'a -> 'a t
val unsafe_get : 'a t -> int -> 'a
val unsafe_set : 'a t -> int -> 'a -> unit
end

module Make (S : Strat.T) (Impl : Implementation) = struct
module Strategy = S

type strategy = Strategy.t

type 'a t = {mutable ar : 'a Impl.t;
mutable vlix : int;
mutable strategy : strategy}

let name = Impl.name

let invalid_arg str = invalid_arg (name ^ "." ^ str)

let length ra = succ ra.vlix

let real_length ra = Impl.length ra.ar
let real_lix ra = pred (real_length ra)

let unsafe_get ra = Impl.unsafe_get ra.ar
let unsafe_set ra = Impl.unsafe_set ra.ar

let dummy_loc = 0
let no_obj () = Obj.magic dummy_loc

let creator n = let nothing = no_obj () in Impl.make n nothing

let screate_fresh strategy n =
let res = {ar = no_obj (); vlix = pred n; strategy = strategy} in
Strategy.grow strategy (fun rlen -> res.ar <- creator rlen) n; res

let create_fresh n = screate_fresh Strategy.default n

let create_from ra =
{ar = creator (length ra); vlix = ra.vlix; strategy = ra.strategy}

let sempty strategy =
let res = {ar = no_obj (); vlix = -1; strategy = strategy} in
Strategy.grow strategy (fun rlen -> res.ar <- creator rlen) 0; res

let screate strategy n x =
let res = screate_fresh strategy n in
for i = 0 to pred n do unsafe_set res i x done; res

let sinit strategy n f =
let res = screate_fresh strategy n in
for i = 0 to pred n do unsafe_set res i (f i) done; res

let resizer some_lix ra len =
let ar = creator len in
for i = 0 to some_lix do Impl.unsafe_set ar i (unsafe_get ra i) done;
ra.ar <- ar

let enforce_strategy ra =
let real_len = real_length ra and len = length ra in
Strategy.shrink ra.strategy (resizer ra.vlix ra) real_len len
end

@vicuna
Copy link
Author

vicuna commented Mar 16, 2000

Comment author: administrator

Hi,

module Make (S : Strat.T) (Impl : Implementation) = struct

I'm trying to reproduce your bug, but I'm afraid we'll need the file
strat.ml for that...

-- Damien

@vicuna
Copy link
Author

vicuna commented Mar 16, 2000

Comment author: administrator

Hello,

module Make (S : Strat.T) (Impl : Implementation) = struct

I'm trying to reproduce your bug, but I'm afraid we'll need the file
strat.ml for that...

I am awefully sorry! Trying to reduce the size of the file as much as
possible, I completely overlooked this dependency... (see missing file
below).

There is a funny aspect about the problem:

Compiling "strat.ml" and "pres_impl.ml" as follows:

ocamlopt -c strat.ml pres_impl.ml

works without problems!

But:

ocamlopt -c strat.ml
ocamlopt -c pres_impl.ml

This messes up the terminal, but using "copy&paste" with the mouse shows
you this:

spilled-i/116 spilled-x/117 spilled-env/118 spilled-res/119
ðí@`ï``b`````/119

Fatal error: Liveness.fundecl
Uncaught exception: Misc.Fatal_error

In the terminal window, only the first line (spilled...) is readable,
everything else looks rather strange. But ok, such things can happen if a
program goes wild... ;-)

I received many other strange messages while reducing the file more and
more so don't trust the output above as indication to the problem...

Best regards,
Markus Mottl

File: strat.ml

module type T = sig
type t

val default : t

val grow : t -> (int -> unit) -> int -> unit
val shrink : t -> (int -> unit) -> int -> int -> unit
end

--
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl

@vicuna
Copy link
Author

vicuna commented Mar 16, 2000

Comment author: administrator

Having read your notes in the bugtracking list:

Yes, sorry: I also forgot to mention that I normally move "ocamlopt.opt" to
"ocamlopt" when I install things - a probably very bad habit (especially
when one forgets to mention this in bug reports). It, of course, makes a
difference whether a byte code program crashes or a native code one...

Regards,
Markus Mottl

--
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl

@vicuna
Copy link
Author

vicuna commented Mar 17, 2000

Comment author: administrator

Thanks for the missing file. Damien and I were able to find the bug.
It's a case of a memory root (in the stack) not being mentioned to the GC.
The bug is a consequence of a simplification of the C-- intermediate language
that I did one week ago, but turns out to be incorrect. The sources now
in the CVS repository compiles your example correctly.

Thanks for the well-delineated bug report,

  • Xavier Leroy

@vicuna
Copy link
Author

vicuna commented Mar 17, 2000

Comment author: administrator

Crashes "ocamlopt.opt" but not "ocamlopt" on my machine. -- Damien
Bug introduced 2000/03/12, fixed 2000/03/17 by Xavier.

@vicuna vicuna closed this as completed Mar 17, 2000
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant