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

Polymorphic function segfaults with optimization less than -O2 #216

Open
jrfondren opened this issue Sep 26, 2018 · 1 comment
Open

Polymorphic function segfaults with optimization less than -O2 #216

jrfondren opened this issue Sep 26, 2018 · 1 comment

Comments

@jrfondren
Copy link

Of a file named myvect.dats:

#include "share/atspre_staload.hats"

datatype MyVect(a:t@ype, int) =
    | Empty(a, 0)
    | {n:nat} Cons(a, n) of (a, MyVect(a, n-1))

extern prfun lemma_myvect_rest{a:t@ype}{n:int}(rest: MyVect(a, n)): [n >= 0] void

fun lengthMyVect{a:t@ype}{n:nat}(list: MyVect(a, n)): int(n) =
    case+ list of
    | Empty() => 0
    | Cons(_, rest) => 1 + lengthMyVect(rest) where {
            prval () = lemma_myvect_rest(rest)
    }

val+ 3 = lengthMyVect(Cons{..}{3}(1, Cons(2, Cons(3, Empty()))))

implement main0() = ()

I get these results:

$ patscc
ATS/Postiats version 0.3.12 with Copyright (c) 2011-2018 Hongwei Xi
$ patscc -DATS_MEMALLOC_LIBC -o myvect myvect.dats
$ ./myvect
Segmentation fault
$ patscc -O1 -DATS_MEMALLOC_LIBC -o myvect myvect.dats
$ ./myvect
Segmentation fault
$ patscc -O2 -DATS_MEMALLOC_LIBC -o myvect myvect.dats
$ ./myvect
$

This is also the case with -DATS_MEMALLOC_GCBDW and -lgc.

@githwxi
Copy link
Owner

githwxi commented Sep 26, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants