Open mushenoy opened 2 months ago
@llvm/issue-subscribers-clang-static-analyzer
Author: Mukund Shenoy (mushenoy)
This case could be reduced into this:
void escape_golbals();
void (*fn)() = (void*)0;
int main() {
escape_golbals();
fn();
}
We assume that from main
, even the mutable global variable initializers hold (in C).
Technically that assumption doesn't hold even for C, in the presence of __attribute__((destructor))
.
Personally I'd just drop special-casing main
for trusting mutable global inits.
Basically, we can't differentiate now if we don't have a binding because 1) We don't know anything about the variable, or 2) because we invalidated the it (globals in this case).
This leads RegionStoreManager::getBindingForVar
hitting the branch for If we're in main(), then global initializers have not become stale yet
.
To fix this we would need to either
main
.The first option could be done fairly easily, if we had invalidation artifacts. In that case, we could just check if e.g. the internal system memory space was ever invalidated.
My guess would be that this special casing for main
must be there for a reason - which I don't know ofc.
So, I'd prefer the first option for fixing this.
A False positive in clang-tidy for below sample program.
sample.c
Warnings:
Version clang-tidy --version LLVM (http://llvm.org/): LLVM version 19.0.0
Observations: