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

Separate out EH handler lowering into its own pass #21720

Merged
merged 1 commit into from
May 16, 2017
Merged

Conversation

Keno
Copy link
Member

@Keno Keno commented May 5, 2017

Currently it's being done as part of the GC root lowering pass. However, I'm working
on replacing that pass, so this functionality needed to be separated out anyway.
While I'm here:

  1. Simplify the algorithm to a simple DFS numbering
  2. Have it insert lifetime intrinisics to allow the optimizer to do stack slot coloring later
  3. Add a test for this pass

@Keno Keno requested review from vtjnash and yuyichao May 5, 2017 22:14
@Keno Keno force-pushed the kf/lowerhandlers branch from ca68f3f to 724fcce Compare May 5, 2017 22:26
@kshyatt kshyatt added error handling Handling of exceptions by Julia or the user compiler:lowering Syntax lowering (compiler front end, 2nd stage) labels May 5, 2017
@@ -0,0 +1,225 @@
// This file is a part of Julia. License is MIT: http://julialang.org/license
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the links are https now

@JeffBezanson JeffBezanson added compiler:codegen Generation of LLVM IR and native code and removed compiler:lowering Syntax lowering (compiler front end, 2nd stage) labels May 9, 2017
@tkelman
Copy link
Contributor

tkelman commented May 14, 2017

that segfault during bootstrap on win64 appveyor looks legit

@Keno
Copy link
Member Author

Keno commented May 15, 2017

Indeed. I'll take a look.

@vtjnash vtjnash requested review from yuyichao and removed request for vtjnash May 15, 2017 18:31
Currently it's being done as part of the GC root lowering pass. However, I'm working
on replacing that pass, so this functionality needed to be separated out anyway.
While I'm here:
1. Simplify the algorithm to a simple DFS numbering
2. Have it insert lifetime intrinisics to allow the optimizer to do stack slot coloring later
3. Add a test for this pass
@Keno Keno force-pushed the kf/lowerhandlers branch from f988f98 to bbe8e18 Compare May 15, 2017 19:04
@Keno
Copy link
Member Author

Keno commented May 15, 2017

Fixed, I think.

@Keno Keno merged commit 4cd4fae into master May 16, 2017
@yuyichao yuyichao deleted the kf/lowerhandlers branch May 16, 2017 16:09
@ararslan
Copy link
Member

This seems to be causing segfaults when compiling on FreeBSD.

@Keno
Copy link
Member Author

Keno commented May 16, 2017

Do you have a backtrace?

@ararslan
Copy link
Member

@Keno
Copy link
Member Author

Keno commented May 16, 2017

Can you attach a debugger? "make VERBOSE=1" will show you the exact command it was trying to run.

@yuyichao
Copy link
Contributor

@ararslan
Copy link
Member

Regarding the warning, I'm getting that on macOS as well. Perhaps the function should have a return true; at the end?

I can run make in gdb but I'm not sure how exactly to capture the relevant information.

@Keno
Copy link
Member Author

Keno commented May 16, 2017

Yes, it's missing a return true. Shouldn't be the cause of our problems though.

@yuyichao
Copy link
Contributor

The backtrace almost looks like the compiler assume the return will not be reachable and let the control flow fall into the next function, which might be a valid optimization according to C++ standard... Should llvm::FPPassManager::doInitialization(llvm::Module&) actually call runOnFunction?

@yuyichao
Copy link
Contributor

@ararslan can you add that return true and run again? If this still happens, maybe first justs run it in gdb and post the gdb bt when it crashes. Should be a slightly more reliable backtrace if anything....

@ararslan
Copy link
Member

Just adding the return was enough to fix both the warning and segfault. #21913

@yuyichao
Copy link
Contributor

It seems that that's actually the code clang produce for

int g1(bool);

bool f(bool a)
{
    if (a)
        return false;
    g1(a);
}

bool k()
{
    return true;
}
_Z1fb:                                  # @_Z1fb
        .cfi_startproc
# BB#0:
        pushq   %rax
.Lcfi0:
        .cfi_def_cfa_offset 16
        testb   %dil, %dil
        je      .LBB0_2
# BB#1:
        xorl    %eax, %eax
        popq    %rcx
        retq
.LBB0_2:
        xorl    %edi, %edi
        callq   _Z2g1b
.Lfunc_end0:
        .size   _Z1fb, .Lfunc_end0-_Z1fb
        .cfi_endproc

        .globl  _Z1kv
        .p2align        4, 0x90
        .type   _Z1kv,@function
_Z1kv:                                  # @_Z1kv
        .cfi_startproc
# BB#0:
        movb    $1, %al
        retq
.Lfunc_end1:
        .size   _Z1kv, .Lfunc_end1-_Z1kv
        .cfi_endproc

@yuyichao
Copy link
Contributor

Cool. A little surprised that this doesn't trigger a crash on macOS....

@Keno
Copy link
Member Author

Keno commented May 16, 2017

Huh, I was under the impression that it'd just do a ret undef rather than an unreachable.

@yuyichao
Copy link
Contributor

yuyichao commented May 16, 2017

That's what gcc does..... Apparently llvm (4.0 at least) doesn't....... not even a unreachable....

@yuyichao
Copy link
Contributor

Actually, it does emit a unreachable at IR level but the trap is not there at any optimization level (only in -O0)....

@andreasnoack
Copy link
Member

@Keno Bisection suggests that this is causing an assertion error with LLVM-svn. cc @ranjanan

docs/core.jl
inference.jl
julia: /home/andreasnoack/julia-dev/deps/srccache/llvm-svn/include/llvm/ADT/ArrayRef.h:233: const T&
llvm::ArrayRef<T>::operator[](size_t) const [with T = llvm::Type*; size_t = long unsigned int]: Asser
tion `Index < Length && "Invalid index!"' failed.

signal (6): Aborted
while loading inference.jl, in expression starting on line 5399
gsignal at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
abort at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x7f1c762fcbb6)
__assert_fail at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x7f1c73c010fa)
_ZN4llvm9Intrinsic7getTypeERNS_11LLVMContextENS0_2IDENS_8ArrayRefIPNS_4TypeEEE at /home/andreasnoack/julia-dev/usr/bin/../lib/libLLVM-5.0svn.so (unknown line)
_ZN4llvm9Intrinsic14getDeclarationEPNS_6ModuleENS0_2IDENS_8ArrayRefIPNS_4TypeEEE at /home/andreasnoack/julia-dev/usr/bin/../lib/libLLVM-5.0svn.so (unknown line)
doInitialization at /home/andreasnoack/julia-dev/src/llvm-lower-handlers.cpp:117
_ZN4llvm13FPPassManager16doInitializationERNS_6ModuleE at /home/andreasnoack/julia-dev/usr/bin/../lib/libLLVM-5.0svn.so (unknown line)
_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE at /home/andreasnoack/julia-dev/usr/bin/../lib/libLLVM-5.0svn.so (unknown line)
operator() at /home/andreasnoack/julia-dev/src/jitlayers.cpp:461 [inlined]
_M_invoke at /usr/include/c++/6/functional:1726
operator() at /usr/include/c++/6/functional:2136 [inlined]
addModuleSet<llvm::SmallVector<std::unique_ptr<llvm::Module>, 1u>, llvm::RTDyldMemoryManager*, std::u
nique_ptr<llvm::orc::LambdaResolver<JuliaOJIT::addModule(std::unique_ptr<llvm::Module>)::<lambda(cons
t string&)>, JuliaOJIT::addModule(std::unique_ptr<llvm::Module>)::<lambda(const string&)> >, std::def
ault_delete<llvm::orc::LambdaResolver<JuliaOJIT::addModule(std::unique_ptr<llvm::Module>)::<lambda(co
nst string&)>, JuliaOJIT::addModule(std::unique_ptr<llvm::Module>)::<lambda(const string&)> > > > > a
t /home/andreasnoack/julia-dev/usr/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h:72 [inlined]
addModule at /home/andreasnoack/julia-dev/src/jitlayers.cpp:589
jl_add_to_ee at /home/andreasnoack/julia-dev/src/jitlayers.cpp:812 [inlined]
jl_finalize_function at /home/andreasnoack/julia-dev/src/jitlayers.cpp:823
getAddressForFunction at /home/andreasnoack/julia-dev/src/codegen.cpp:1407
jl_generate_fptr at /home/andreasnoack/julia-dev/src/codegen.cpp:1504
jl_compile_method_internal at /home/andreasnoack/julia-dev/src/julia_internal.h:335 [inlined]
jl_call_method_internal at /home/andreasnoack/julia-dev/src/julia_internal.h:363 [inlined]
jl_apply_generic at /home/andreasnoack/julia-dev/src/gf.c:1923
unknown function (ip: 0x7f1c6cb24c85)
jl_call_fptr_internal at /home/andreasnoack/julia-dev/src/julia_internal.h:348 [inlined]
jl_call_method_internal at /home/andreasnoack/julia-dev/src/julia_internal.h:367 [inlined]
jl_apply_generic at /home/andreasnoack/julia-dev/src/gf.c:1923
unknown function (ip: 0x7f1c6cb23970)
jl_call_fptr_internal at /home/andreasnoack/julia-dev/src/julia_internal.h:348 [inlined]
jl_call_method_internal at /home/andreasnoack/julia-dev/src/julia_internal.h:367 [inlined]
jl_apply_generic at /home/andreasnoack/julia-dev/src/gf.c:1923
unknown function (ip: 0x7f1c6cb1afb2)
jl_call_fptr_internal at /home/andreasnoack/julia-dev/src/julia_internal.h:348 [inlined]
jl_call_method_internal at /home/andreasnoack/julia-dev/src/julia_internal.h:367 [inlined]
jl_toplevel_eval_flex at /home/andreasnoack/julia-dev/src/toplevel.c:587
jl_parse_eval_all at /home/andreasnoack/julia-dev/src/ast.c:873
jl_load at /home/andreasnoack/julia-dev/src/toplevel.c:614
unknown function (ip: 0x7f1c6caf2124)
jl_call_fptr_internal at /home/andreasnoack/julia-dev/src/julia_internal.h:348 [inlined]
jl_call_method_internal at /home/andreasnoack/julia-dev/src/julia_internal.h:367 [inlined]
jl_apply_generic at /home/andreasnoack/julia-dev/src/gf.c:1923
do_call at /home/andreasnoack/julia-dev/src/interpreter.c:75
eval at /home/andreasnoack/julia-dev/src/interpreter.c:242
jl_interpret_toplevel_expr at /home/andreasnoack/julia-dev/src/interpreter.c:34
jl_toplevel_eval_flex at /home/andreasnoack/julia-dev/src/toplevel.c:575
jl_eval_module_expr at /home/andreasnoack/julia-dev/src/toplevel.c:203
jl_toplevel_eval_flex at /home/andreasnoack/julia-dev/src/toplevel.c:478
jl_toplevel_eval_in at /home/andreasnoack/julia-dev/src/builtins.c:496
unknown function (ip: 0x7f1c6caf1928)
jl_call_fptr_internal at /home/andreasnoack/julia-dev/src/julia_internal.h:348 [inlined]
jl_call_method_internal at /home/andreasnoack/julia-dev/src/julia_internal.h:367 [inlined]
jl_apply_generic at /home/andreasnoack/julia-dev/src/gf.c:1923
do_call at /home/andreasnoack/julia-dev/src/interpreter.c:75
eval at /home/andreasnoack/julia-dev/src/interpreter.c:242
jl_interpret_toplevel_expr at /home/andreasnoack/julia-dev/src/interpreter.c:34
jl_toplevel_eval_flex at /home/andreasnoack/julia-dev/src/toplevel.c:575
jl_parse_eval_all at /home/andreasnoack/julia-dev/src/ast.c:873
jl_load at /home/andreasnoack/julia-dev/src/toplevel.c:614
exec_program at /home/andreasnoack/julia-dev/ui/repl.c:49
true_main at /home/andreasnoack/julia-dev/ui/repl.c:139
main at /home/andreasnoack/julia-dev/ui/repl.c:264
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x55b9a0b4b5e9)
Allocations: 368959 (Pool: 368924; Big: 35); GC: 0
Aborted
Makefile:214: recipe for target '/home/andreasnoack/julia-dev/usr/lib/julia/inference.ji' failed
make[1]: *** [/home/andreasnoack/julia-dev/usr/lib/julia/inference.ji] Error 134
Makefile:100: recipe for target 'julia-inference' failed

@Keno
Copy link
Member Author

Keno commented May 19, 2017

Yes, I had already given @ranjanan a patch for this.

@ranjanan
Copy link
Contributor

ranjanan commented May 20, 2017

Yes but after building I got another segfault at Base.precompile

/home/administrator/julia/base/precompile.jl
julia: /home/administrator/julia/deps/srccache/llvm-svn/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:1144: virtual void llvm::DwarfDebug::beginFunctionImpl(const llvm::MachineFunction*): Assertion `SP->getUnit()->getEmissionKind() == DICompileUnit::NoDebug && "DICompileUnit missing from llvm.dbg.cu?"' failed.

Perhaps it's something @yuyichao already mentioned in #21879

@yuyichao
Copy link
Contributor

Yes it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code error handling Handling of exceptions by Julia or the user
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants