Skip to content

Conversation

@xavierleroy
Copy link
Contributor

Consider two global variables x and y. Currently, the value analysis considers that any pointer based on x cannot be equal to any pointer based on y. This reflects the CompCert C semantics for pointer equality: if the two pointers are within bounds, they must differ; and if one pointer is outside bounds (including if it is "one past"), comparison is undefined.

However, a pointer "one past" x and a pointer to the beginning of y can be equal at the machine level, and comparing them for equality is not undefined behavior in ISO C, just an unpredictable result.

This PR makes sure CompCert's value analysis says "I don't know" for equality tests between pointers based on different global variables. It still says "false or undefined" for equality between a pointer based in the current stack block and a pointer based elsewhere, as such pointers can never be equal even if "one past".

A pointer "one past" a global "x" and a pointer to the beginning of a
global "y" can be equal.  This is undefined behavior in CompCert C,
but defined behavior in ISO C.

Thus, the value analysis should not infer that a pointer based at "x"
and a pointer based at "y" cannot be equal.

The only inference we keep is that a pointer based in the current
stack block and a pointer based in a global variable cannot be equal.
@xavierleroy xavierleroy force-pushed the value-analysis-pointer-comparison branch from b311744 to 918df5a Compare July 24, 2024 07:53
@xavierleroy xavierleroy merged commit 62251c7 into master Jul 26, 2024
@xavierleroy xavierleroy deleted the value-analysis-pointer-comparison branch August 16, 2024 06:35
@xavierleroy
Copy link
Contributor Author

Follow-up commit: fd48dc8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants