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 instead of throwing UndefVarError — includes rr trace #37265

Closed
jmert opened this issue Aug 28, 2020 · 3 comments · Fixed by #37285
Closed

Segfault instead of throwing UndefVarError — includes rr trace #37265

jmert opened this issue Aug 28, 2020 · 3 comments · Fixed by #37285

Comments

@jmert
Copy link
Contributor

jmert commented Aug 28, 2020

The test case from this discourse question leads to a segfault after the local function definitions are changed to either anonymous functions (which I tried locally) or local assignment of different functions (as shown in the third reply).

A later reply identified just changing @error to error() in the function definition avoids the segfault. The else branch doesn't define showcase(), so the later call should result in an UndefVarError being thrown. (The earlier observation that error() works is because that cases the function to throw an actual error and exit the function before the call following the if-else block is called.)

I've tried out Julia v1.5's new julia --bug-report=rr tool — the rr dump was uploaded to https://s3.amazonaws.com/julialang-dumps/reports/2020-08-28T15-12-54-jmert.tar.zst

Julia version:

julia> versioninfo()
Julia Version 1.5.0-beta1.0
Commit 6443f6c95a (2020-05-28 17:42 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)

(I had to switch to my Intel laptop since rr doesn't run on Ryzen, and I didn't realize I still had the beta installed on the laptop. I can reproduce with v1.5.1 if need be.)

Test script:

using Printf

function switchcase(i, str)
    case = str
    if uppercase(case) == "A"
        @info "set case A"
        showcase = i -> @printf("case A number %i", i)
    elseif uppercase(case) == "B"
        @info "set case B"
        showcase = i -> @printf("case B number %i and some more parameters %i", i, 8)
    else
        @error("no case $case")
    end
    showcase(i)
end

switchcase(2, "C")
@jmert jmert changed the title Segfault from particular invocation of @error — includes rr trace Segfault instead of throwing UndefVarError — includes rr trace Aug 28, 2020
@lmiq
Copy link
Contributor

lmiq commented Aug 28, 2020

Simpler test script:

f() = 1
g() = 2
function h(i)
  if i == 1
    s = f
  elseif i == 2
    s = g
  else
    @error("none")
  end
  s()
end
h(1)

@maleadt
Copy link
Member

maleadt commented Aug 28, 2020

Slightly simpler, and without the macro:

a() = 0
b() = 0
function c(d)
  if 0
    e = a
  elseif 0
    e = b
  else
    try
    catch 
    end
  end
  e
end
c(0)

@yuyichao
Copy link
Contributor

Making this line https://github.com/JuliaLang/julia/blob/master/src/codegen.cpp#L6840 conditional on VN should fix it without any other effect though I'm not 100% sure if this should happen.

yuyichao added a commit that referenced this issue Aug 30, 2020
Fixes a crash when one of the incoming value for a union value phi node is `Union{}`.
Incoming value of this type can be generated by try-catch.

Fix #37265
yuyichao added a commit that referenced this issue Aug 30, 2020
Fixes a crash when one of the incoming value for a union value phi node is of type `Union{}`.
Incoming value of this type can be generated by try-catch.

Fix #37265
yuyichao added a commit that referenced this issue Aug 30, 2020
Fixes a crash when one of the incoming value for a union value phi node is of type `Union{}`.
Incoming value of this type can be generated by try-catch.

Fix #37265
yuyichao added a commit that referenced this issue Sep 1, 2020
Fixes a crash when one of the incoming value for a union value phi node is of type `Union{}`.
Incoming value of this type can be generated by try-catch.

Fix #37265
yuyichao added a commit that referenced this issue Sep 2, 2020
Fixes a crash when one of the incoming value for a union value phi node is of type `Union{}`.
Incoming value of this type can be generated by try-catch.

Fix #37265
KristofferC pushed a commit that referenced this issue Sep 7, 2020
Fixes a crash when one of the incoming value for a union value phi node is of type `Union{}`.
Incoming value of this type can be generated by try-catch.

Fix #37265

(cherry picked from commit c3a63fc)
KristofferC pushed a commit that referenced this issue Sep 7, 2020
Fixes a crash when one of the incoming value for a union value phi node is of type `Union{}`.
Incoming value of this type can be generated by try-catch.

Fix #37265

(cherry picked from commit c3a63fc)
KristofferC pushed a commit that referenced this issue Sep 8, 2020
Fixes a crash when one of the incoming value for a union value phi node is of type `Union{}`.
Incoming value of this type can be generated by try-catch.

Fix #37265

(cherry picked from commit c3a63fc)
KristofferC pushed a commit that referenced this issue Sep 10, 2020
Fixes a crash when one of the incoming value for a union value phi node is of type `Union{}`.
Incoming value of this type can be generated by try-catch.

Fix #37265

(cherry picked from commit c3a63fc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants