aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
authorMatthias Springer <me@m-sp.org>2025-02-20 08:42:27 +0100
committerGitHub <noreply@github.com>2025-02-20 08:42:27 +0100
commit7d03c8e256a78b67a645b78e3ca93287bee0cd37 (patch)
tree3cc369bd9f63c2cdbf8196e7b2580c3ab514d7cd /flang/lib/Frontend/CompilerInvocation.cpp
parent77183a46a5fd4e0b92ea91096c6d58bea7a7f43b (diff)
downloadllvm-7d03c8e256a78b67a645b78e3ca93287bee0cd37.zip
llvm-7d03c8e256a78b67a645b78e3ca93287bee0cd37.tar.gz
llvm-7d03c8e256a78b67a645b78e3ca93287bee0cd37.tar.bz2
[mlir][Parser] Fix use-after-free when parsing invalid reference to nested definition (#127778)
This commit fixes a use-after-free crash when parsing the following invalid IR: ```mlir scf.for ... iter_args(%var = %foo) -> tensor<?xf32> { %foo = "test.inner"() : () -> (tensor<?xf32>) scf.yield %arg0 : tensor<?xf32> } ``` The `scf.for` parser was implemented as follows: 1. Resolve operands (including `%foo`). 2. Parse the region. During operand resolution, a forward reference (`unrealized_conversion_cast`) is added by the parser because `%foo` has not been defined yet. During region parsing, the definition of `%foo` is found and the forward reference is replaced with the actual definition. (And the forward reference is deleted.) However, the operand of the `scf.for` op is not updated because the `scf.for` op has not been created yet; all we have is an `OperationState` object. All parsers should be written in such a way that they first parse the region and then resolve the operands. That way, no forward reference is inserted in the first place. Before parsing the region, it may be necessary to set the argument types if they are defined as part of the assembly format of the op (as is the case with `scf.for`). Note: Ops in generic format are parsed in the same way. To make the parsing infrastructure more robust, this commit also delays the erase of forward references until the end of the lifetime of the parser. Instead of a use-after-free crash, users will then see more descriptive error messages such as: ``` error: operation's operand is unlinked ``` Note: The proper way to fix the parser is to first parse the region, then resolve the operands. The change to `Parser.cpp` is merely to help users finding the root cause of the problem.
Diffstat (limited to 'flang/lib/Frontend/CompilerInvocation.cpp')
0 files changed, 0 insertions, 0 deletions