[clang] [clang][dataflow] Allow `DataflowAnalysisContext` to use a non-owned `Solver`. (PR #91316)

via cfe-commits cfe-commits at lists.llvm.org
Tue May 7 05:56:48 PDT 2024


martinboehme wrote:

@ymand PTAL -- I noticed that my initial version had a use-after-move on this line:

```cxx
  DataflowAnalysisContext(std::unique_ptr<Solver> S,
                          Options Opts = Options{
                              /*ContextSensitiveOpts=*/std::nullopt,
                              /*Logger=*/nullptr})
      : DataflowAnalysisContext(*S, std::move(S), Opts) {}
```

This was because the private constructor to which this constructor delegates originally took the `std::unique_ptr<Solver>` by value, and the order in which the arguments are evaluated is indeterminate.

I've now changed the parameter of the private constructor to be an rvalue reference (`std::unique_ptr<Solver> &&`), which resolves this issue as the move only happens inside the constructor.

https://github.com/llvm/llvm-project/pull/91316


More information about the cfe-commits mailing list