[clang] [clang][analyzer]Add C++ polymorphic ptr arithmetic checker (PR #82977)

via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 27 08:42:14 PST 2024


https://github.com/NagyDonat commented:

I finished reading your commit and added one more suggestion about note tag creation.

Moreover I also suggest adding a testcase that looks like
```cpp
struct Node {
  int value;
};
struct BranchingNode: public Node {
  Node nodes[8];
};
void delete_base_member() {
  BranchingNode *p = new BranchingNode;
  delete &p->nodes[3];
}
```
Based on the source code I'd guess that in this case the checker would produce a false positive report (which highlights a real bug, but with incorrect message -- the checker wouldn't notice that the deleted region is not the base class subregion of the BranchingNode, but another subregion).

It isn't a problem if the checker cannot handle this artificial example, but we should include a testcase for it (with a fixme if the checker behavior is incorrect).

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


More information about the cfe-commits mailing list