-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
To keep ubsan happy, Use offsetof() rather than legacy equivalent #73657
Conversation
src/coreclr/pal/inc/rt/palrt.h
Outdated
// support for offsetof() on anything other than a standard-layout class | ||
// is conditionally supported. | ||
// This is more generous than the C++ standards when this code was originally written | ||
// | ||
// PAL_safe_offsetof is a version of offsetof that protects against an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can delete this comment and PAL_safe_offsetof
and replace all its occurences with just offsetof.
src/coreclr/pal/inc/rt/palrt.h
Outdated
// overridden operator& | ||
// overridden operator&. Note, however, C++-98 and newer | ||
// requires offsetof to work correctly even if operator& is overloaded. | ||
// | ||
|
||
#define FIELD_OFFSET(type, field) __builtin_offsetof(type, field) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for FIELD_OFFSET
. You can delete the definition and replace the few uses with offsetof
.
Using offsetof() will prevent various static analyzers and dynamic ubsan from complaining about indirecting through NULL.
The test failure is #73299 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
The existing code causes ubsan to generate a runtime error when using the &((Type *)0->field idiom.