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

Eliminate null checks if the OS is known to trap failures safely #1185

Open
secure-sw-dev-bot opened this issue Jan 17, 2022 · 0 comments
Open

Comments

@secure-sw-dev-bot
Copy link

This issue was copied from checkedc/checkedc-clang#1189


The compiler could skip inserting null checks on pointer dereferences if it knows that use of a null pointer would be trapped safely by the OS rather than causing undefined behavior. This is probably true for a dereference at a sufficiently small constant offset from a pointer (e.g., accessing a struct field), but a dereference at an offset not known to be small or any pointer arithmetic operation that could be repeated to build up a large offset may still require a null check. This feature could be controlled by its own Checked-C-specific flag, or it might make sense to tie it into target-specific information already available in LLVM/Clang, such as -fdelete-null-pointer-checks; this may be related to #168.

Potential benefits:

  1. Avoid the performance impact of the null checks.
  2. If a user turns on warnings for runtime check insertion (Local variable bounds dependent on global variable can be invalidated by function call (unsound) #1188) in order to get a guarantee of spatial memory safety on a plain C compiler, getting a large number of warnings about null checks and having to add them explicitly to the source code would be extremely annoying. Having the compiler eliminate most of the null checks would make this use scenario more feasible. An alternative way to address the problem would be to add a nullability analysis to Checked C, but I imagine that might be a lot of work and might become a distraction from the main goal of spatial memory safety.
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

No branches or pull requests

1 participant