[clang] [analyzer] Switch to PostStmt callbacks in ArrayBoundV2 (PR #72107)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 23 16:29:10 PST 2023


Xazax-hun wrote:

Note that &array[idx] is perfectly valid code when `idx == number of elements`. And it is relatively common to do that when one is using STL algorithms on arrays:
```
auto it = std::find(&array[0], &array[size], foo);
```

Of course, one could use the `begin/end` free functions, but those are only available since C++11. 

Could you elaborate on alternative approaches you considered fixing the problem and why you chose this one? E.g., would trying to look at the parent regions for expressions like `foo[idx].bar` work? Or is the source of the problem that you'd also need the exact expression for the subscript instead of the `MemberExpr`?

Alternatively, would it be possible to suppress warnings on the common pattern `&array[idx]` by checking the parent of the subscript expression in the AST (but still emitting a warning when the pointer is dereferenced)?


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


More information about the cfe-commits mailing list