haoNoQ wrote:
Ok I kinda forgot about the elephant in the room.
With path sensitivity you'll be able to handle more kinds of variables. Not
just global variables but also stuff in heap memory. As well as someone else's
stack variables passed by reference down the stack. Or it could be, like, just
*some* pointer or reference passed to us from god knows where. We don't have to
know where and by whom exactly the memory it points to has been allocated. We
just need to know whether it's the same memory address at two different points
of the program.
The static analyzer will model such aliasing for you and give you that
information for free, so that at any point of time you know which pointer
points to which storage, even if you can't (or don't want to) describe that
storage. It'd magically work correctly even if that information depends on the
exact execution path up to that point.
This could make your check significantly more powerful. And that's very hard
without path sensitivity.
----
FWIW one case you can probably handle without path sensitivity is: member
variables inside a method. Eg., in
```c++
class MyClass {
int memberVar;
public:
int foo() {
memberVar++;
return memberVar;
}
void bar() {
memberVar + foo(); // should warn
}
};
```
you don't really need to know what `this` points to, as long as you confirm
that it points to the same thing inside `foo()` and `bar()`. Which is trivial
because the `foo()` invocation inside `bar()` is invoked directly on `this`.
This is so easy because the `this` pointer cannot be overwritten at runtime, so
you don't have to worry about code like `this = &other`.
You can probably handle references similarly, since they also cannot be
reassigned at runtime. It doesn't matter that you don't know what the reference
refers to:
```c++
int foo(int &refVar) {
refVar++;
return refVar;
}
void bar(int &refVar) {
refVar + foo(refVar); // should warn
}
```
But when it comes to pointers and heap storage, you'll probably have a very
hard time with path sensitivity.
https://github.com/llvm/llvm-project/pull/130421
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits