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

Miscompilation of invalid conditionals when both branches yield the same value #29306

Closed
getzze opened this issue Sep 21, 2018 · 4 comments
Closed
Assignees
Labels
compiler:optimizer Optimization passes (mostly in base/compiler/ssair/)

Comments

@getzze
Copy link
Contributor

getzze commented Sep 21, 2018

julia> VERSION
v"1.0.0"

julia> a = [1,2,3,4,missing,6,7]
7-element Array{Union{Missing, Int64},1}:
 1       
 2       
 3       
 4       
  missing
 6       
 7       

julia> y = 6; b = [ (x>y ? missing : x)  for x in a]
ERROR: TypeError: non-boolean (Missing) used in boolean context

julia> c = [ (x>6 ? -1 : x)  for x in a]
ERROR: TypeError: non-boolean (Missing) used in boolean context

julia> d = [ (x>6 ? missing : -1)  for x in a]
ERROR: TypeError: non-boolean (Missing) used in boolean context

julia> e = [ (x>6 ? missing : x)  for x in a]
7-element Array{Union{Missing, Int64},1}:
 1       
 2       
 3       
 4       
  missing
 6       
  missing

The definition of e should give the same error as for c and d, or at least b!

@c42f
Copy link
Member

c42f commented Sep 22, 2018

Here's a reduced example which shows this is a weird transformation of the conditional (not related to generators per se):

julia> function foo(x)
           if x > 0
               x
           else
               missing
           end
       end
foo (generic function with 1 method)

julia> foo(missing) # Should produce an error
missing

julia> @code_typed foo(missing)
CodeInfo(
2 1 ─     goto #3 if not $(QuoteNode(missing))                                             │
3 2return x                                                                         │
5 3return Main.missing                                                              │
) => Missing

I'm really not sure what that QuoteNode is doing there!

@c42f
Copy link
Member

c42f commented Sep 22, 2018

A further reduced example, showing that this is also independent of missing:

julia> function foo()
           if "Move right along, nothing to see here"
               10
           else
               10
           end
       end
foo (generic function with 2 methods)

julia> foo()
10

julia> @code_typed foo()
CodeInfo(
2 1 ─     goto #3 if not "Move right along, nothing to see here"                           │
3 2return 105 3return 10                                                                        │
) => Int64

@c42f c42f changed the title Bug with generator and missing values Miscompilation of invalid conditionals when both branches yield the same value Sep 22, 2018
@c42f
Copy link
Member

c42f commented Sep 22, 2018

Ok, this is an error somewhere in codegen - running julia with --compile=no results in the expected error from the function foo() above.

@c42f
Copy link
Member

c42f commented Sep 22, 2018

More weirdness - reasonable looking code is shown by @code_llvm, but then apparently clobbered after native codegen:

julia> function foo()
           if "asdf"
               10
           else
               10
           end
       end
foo (generic function with 1 method)

julia> @code_llvm foo()

; Function foo
; Location: REPL[1]:2
; Function Attrs: sspstrong
define i64 @julia_foo_789307557() #0 {
top:
  call void @jl_type_error_rt(i8* inttoptr (i64 94190438521104 to i8*), i8* inttoptr (i64 94190439063072 to i8*), %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140252862974832 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(12)* addrspacecast (%jl_value_t* inttoptr (i64 140252904070960 to %jl_value_t*) to %jl_value_t addrspace(12)*))
  unreachable
}

julia> foo()
10

julia> @code_llvm foo()

; Function foo
; Location: REPL[1]:2
; Function Attrs: sspstrong
define i64 @julia_foo_789307561() #0 {
top:
  ret i64 10
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:optimizer Optimization passes (mostly in base/compiler/ssair/)
Projects
None yet
Development

No branches or pull requests

3 participants