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

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

Open
vtjnash opened this issue Feb 13, 2025 · 0 comments
Open

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

vtjnash opened this issue Feb 13, 2025 · 0 comments
Labels
compiler:llvm For issues that relate to LLVM correctness bug ⚠ Bugs that are likely to lead to incorrect results in user code without throwing

Comments

@vtjnash
Copy link
Member

vtjnash commented Feb 13, 2025

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
@vtjnash vtjnash added the correctness bug ⚠ Bugs that are likely to lead to incorrect results in user code without throwing label Feb 13, 2025
@oscardssmith oscardssmith added the compiler:llvm For issues that relate to LLVM label Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:llvm For issues that relate to LLVM correctness bug ⚠ Bugs that are likely to lead to incorrect results in user code without throwing
Projects
None yet
Development

No branches or pull requests

2 participants