[clang] [clang][analyzer] Add notes to PointerSubChecker (PR #95899)
DonĂ¡t Nagy via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 18 02:48:01 PDT 2024
================
@@ -144,9 +144,24 @@ void PointerSubChecker::checkPreStmt(const BinaryOperator *B,
// Allow arithmetic on different symbolic regions.
if (isa<SymbolicRegion>(SuperLR) || isa<SymbolicRegion>(SuperRR))
return;
+ if (const auto *SuperDLR = dyn_cast<DeclRegion>(SuperLR))
+ DiffDeclL = SuperDLR->getDecl();
+ if (const auto *SuperDRR = dyn_cast<DeclRegion>(SuperRR))
+ DiffDeclR = SuperDRR->getDecl();
----------------
NagyDonat wrote:
Note that `FieldRegion`s are `DeclRegion`s, so these declarations may be data member declarations within a `struct` or `class`. This is usually not a problem, but there is a corner case where `SuperLR != SuperRR`, but the corresponding declarations are identical:
```
struct {
int array[5];
} a, b;
int func(void) {
return &a.array[3] - &b.array[2];
}
```
In this case the current code would place both notes onto the declaration of `field`, which would be confusing for the user.
Consider adding some code that handles this situation explicitly. (Either simply skip note creation when `DiffDeclL == DiffDeclR`, or create a specialized note for this case.)
https://github.com/llvm/llvm-project/pull/95899
More information about the cfe-commits
mailing list