Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More conservative value analysis of pointer equality #516

Merged
merged 2 commits into from
Jul 26, 2024

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
7 checks passed
@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.

1 participant