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

Segfault in 'Simplify the CFG' pass with Pony 0.22.6 #2760

Closed
burjui opened this issue Jun 7, 2018 · 15 comments · Fixed by #2763
Closed

Segfault in 'Simplify the CFG' pass with Pony 0.22.6 #2760

burjui opened this issue Jun 7, 2018 · 15 comments · Fixed by #2763
Labels
triggers release Major issue that when fixed, results in an "emergency" release

Comments

@burjui
Copy link

burjui commented Jun 7, 2018

Got a segfault compiling my hobby project on Arch Linux x86_64:
https://bitbucket.org/bytefu/funky/src/simplify-cfg-fail/

$ ponyc
Building builtin -> /usr/lib/pony/0.22.6/packages/builtin
Building . -> /home/burjui/Devel/funky
Building libfunky -> /home/burjui/Devel/funky/libfunky
Building files -> /usr/lib/pony/0.22.6/packages/files
Building time -> /usr/lib/pony/0.22.6/packages/time
Building collections -> /usr/lib/pony/0.22.6/packages/collections
Building ponytest -> /usr/lib/pony/0.22.6/packages/ponytest
Building buffered -> /usr/lib/pony/0.22.6/packages/buffered
Building term -> /usr/lib/pony/0.22.6/packages/term
Building promises -> /usr/lib/pony/0.22.6/packages/promises
Building strings -> /usr/lib/pony/0.22.6/packages/strings
Building signals -> /usr/lib/pony/0.22.6/packages/signals
Building capsicum -> /usr/lib/pony/0.22.6/packages/capsicum
Building format -> /usr/lib/pony/0.22.6/packages/format
Building itertools -> /usr/lib/pony/0.22.6/packages/itertools
Building libfunky/ast -> /home/burjui/Devel/funky/libfunky/ast
Generating
 Reachability
 Selector painting
 Data prototypes
 Data types
 Function prototypes
 Functions
 Descriptors
Optimising
Stack dump:
0.      Running pass 'Simplify the CFG' on function '@Main_val_process_ooo'
[1]    9226 segmentation fault (core dumped)  ponyc

Though the segfault goes away after uncommenting the line 66 in main.pony:

token_count = token_count + 1

GDB shows the following stacktrace:

#0  0x00007ffff4f747c4 in llvm::removeUnreachableBlocks(llvm::Function&, llvm::LazyValueInfo*) () from /usr/lib/libLLVM-6.0.so
#1  0x00007ffff5376dab in ?? () from /usr/lib/libLLVM-6.0.so
#2  0x00007ffff47efdc1 in llvm::FPPassManager::runOnFunction(llvm::Function&) ()
   from /usr/lib/libLLVM-6.0.so
#3  0x00007ffff47efebd in llvm::legacy::FunctionPassManagerImpl::run(llvm::Function&)
    () from /usr/lib/libLLVM-6.0.so
#4  0x00007ffff47f0405 in llvm::legacy::FunctionPassManager::run(llvm::Function&) ()
   from /usr/lib/libLLVM-6.0.so
#5  0x00005555555fc8b4 in optimise(compile_t*, bool) ()
#6  0x00005555555fca40 in genopt ()
#7  0x000055555560b031 in genexe ()
#8  0x000055555559a96e in codegen ()
#9  0x0000555555579be7 in compile_package ()
#10 0x000055555557978d in main ()
@SeanTAllen
Copy link
Member

It would appear to be read code removing a giant chunk of the program and then getting angry.

What was the last version of Pony that you know this compiled with?

@SeanTAllen
Copy link
Member

@burjui could you try to create a more minimal example?

@SeanTAllen
Copy link
Member

This was introduced by 9222f08 and my fix for #2735 which was also caused by the same commit didn't fix this. A minimal example would go a long way to helping with this.

@SeanTAllen
Copy link
Member

Here's a minimal example that I think is the same.

actor Main
  new create(env: Env) => 
    var token = U8(1)
    repeat
      (token, let source) = (U8(1), U8(2))
    until token == 2 end

@SeanTAllen
Copy link
Member

So the problem here is in genreference.c

changing:

    if(value == GEN_NOVALUE)
    {

      ponyint_pool_free_size(buf_size, elements);
      return GEN_NOVALUE;
    }

to

    if(value == GEN_NOVALUE)
    {
      ponyint_pool_free_size(buf_size, elements);
      return GEN_NOTNEEDED;
    }

fixes the problem BUT...

that would reopen this issue: #2662

@SeanTAllen
Copy link
Member

@jemc @Praetonus I think this one is past my current compiler knowledge paygrade.

@SeanTAllen SeanTAllen added bug: 2 - under investigation triggers release Major issue that when fixed, results in an "emergency" release and removed bug: 1 - needs investigation labels Jun 8, 2018
@SeanTAllen
Copy link
Member

changing the return type at the end of gen_localdecl to GEN_NOTNEEDED fixes this bug.

AND... the tests all pass, so, i'm going to open a PR for review.

SeanTAllen added a commit that referenced this issue Jun 8, 2018
I don't know the compiler well and I went off what I knew and believe I
found the root cause for our tuple bugs that started with 9222f08. Which
was in turn fixing #2735.

However, a number of bugs came from that fix because, it didn't fix the
root issue. Which was `gen_localdecl` returning GEN_NOVALUE where
GEN_NOTNEEDED was needed. This is why, prior to 9222f08, `gen_tuple` was
returning GEN_NOTNEEDED when the value it has was GEN_NOVALUE.

Fixes #2760
@SeanTAllen
Copy link
Member

@burjui #2763 fixes your issue. I've tested both my minimal example and your full project.

@burjui
Copy link
Author

burjui commented Jun 8, 2018

I tested the fix and it works, thank you. I have never seen bugfixes coming that soon after reporting an issue, wonderful!

@burjui
Copy link
Author

burjui commented Jun 8, 2018

Found another case that causes a segfault even with the fix (tested on issue-2760 branch):

actor Main
  new create(env: Env) =>
    let x: (None | U8) = 1
    while true do
      let _: None = match x
        | let _: U8 => None
      end
    end
$ ponyc
...
0.      Running pass 'Simplify the CFG' on function '@Main_tag_create_oo'
[1]    18802 segmentation fault (core dumped)  ponyc

Same backtrace

@SeanTAllen
Copy link
Member

Interesting. Its looking like a different bug. But I need more time to triage. @burjui I might ask you to open a different issue.

@SeanTAllen
Copy link
Member

@burjui this is a different bug that appears in the same kind of way. can you open an issue for it?

@SeanTAllen
Copy link
Member

This existed at least as far back as 0.21.3

@SeanTAllen
Copy link
Member

This goes back to the introduction of the _ as valid syntax. Without that, this compiles now, so when opening a new issue, we should note that.

@burjui
Copy link
Author

burjui commented Jun 8, 2018

Created an issue: #2767

@burjui burjui closed this as completed Jun 8, 2018
SeanTAllen added a commit that referenced this issue Jun 9, 2018
I don't know the compiler well and I went off what I knew and believe I
found the root cause for our tuple bugs that started with 9222f08. Which
was in turn fixing #2735.

However, a number of bugs came from that fix because, it didn't fix the
root issue. Which was `gen_localdecl` returning GEN_NOVALUE where
GEN_NOTNEEDED was needed. This is why, prior to 9222f08, `gen_tuple` was
returning GEN_NOTNEEDED when the value it has was GEN_NOVALUE.

Fixes #2760
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triggers release Major issue that when fixed, results in an "emergency" release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants