Skip to content

lowering / codegen is unsound for try/catch variables #57393

@vtjnash

Description

@vtjnash

The LLVM optimizer can be tricked into not observing memory effects on will-throw branches, since it does not know they will resume at the catch branch. We can turn that into a miscompile using SSAValue (as otherwise slot2ssa would normally put a phic node here on any attempted direct use of x which would inhibit llvm from doing any analysis of it)

julia> function foo()
       x = Ref(0)
       for i in ((0,x), (1,x))
       i[1] == 1 && return i[2][]
       try; i[2][] = 1; throw("intentional"); catch; end
       end
       throw("unreachable")
       end
foo (generic function with 1 methods)

julia> foo() # this should return 1
0

Metadata

Metadata

Assignees

No one assigned

    Labels

    compiler:llvmFor issues that relate to LLVMcorrectness bug ⚠Bugs that are likely to lead to incorrect results in user code without throwingerror handlingHandling of exceptions by Julia or the user

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions