Previously, system globals were treated as immutable regions, unless it
was the errno which is known to be frequently modified.
D124244 wants to add a check for stores to immutable regions.
It would basically turn all stores to system globals into an error even
though we have no reason to believe that those mutable sys globals
should be treated as if they were immutable. And this leads to
false-positives if we apply D124244.
In this patch, I'm proposing to treat mutable sys globals actually
mutable, hence allocate them into the GlobalSystemSpaceRegion, UNLESS
they were declared as const (and a primitive arithmetic type), in
which case, we should use GlobalImmutableSpaceRegion.
In any other cases, I'm using the GlobalInternalSpaceRegion, which is
no different than the previous behavior.
In the tests I added, only the last expected-warning was different, compared to the baseline.
Which is this:
void test_my_mutable_system_global_constraint() { assert(my_mutable_system_global > 2); clang_analyzer_eval(my_mutable_system_global > 2); // expected-warning {{TRUE}} invalidate_globals(); clang_analyzer_eval(my_mutable_system_global > 2); // expected-warning {{UNKNOWN}} It was previously TRUE. } void test_my_mutable_system_global_assign(int x) { my_mutable_system_global = x; clang_analyzer_eval(my_mutable_system_global == x); // expected-warning {{TRUE}} invalidate_globals(); clang_analyzer_eval(my_mutable_system_global == x); // expected-warning {{UNKNOWN}} It was previously TRUE. }
Unfortunately, the taint checker and the taint propagation will be affected by this change.
Immutable regions were not invalidated, thus taint was preserved as an artifact of this.
Now, such memory regions do get invalidated, thus a new symbolic value will be bound to them; which won't be tainted anymore.
This caused a case in the test suite where the global stdin pointer got 'sanitized' by the default eval called fscanf() call.
In theory, the engine should propagate taint in default eval call. If that would be the case, we would still have this report.
The measurements are not yet complete, but the current results show minor report differences across the measured projects.
Almost all relate to this taint propagation regression, and the handful of others are probably an artifact of the missing sink nodes caused by those reports.
I'll come back with a more in-depth analysis if requested.
This code yields to a virtual function call. And we fortunately have that virtual function in the base class.
Use SymExpr::getOriginRegion() and dyn_cast_or_null to DeclRegion.