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

Don't set subobject bounds on hand-rolled offsetof idioms #608

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

jrtc27
Copy link
Member

@jrtc27 jrtc27 commented Feb 9, 2022

No description provided.

…seExpr

It's possible we could do without the QualType out param, but I'm not
sure if edge cases where references are involved would be otherwise
ambiguous.
Technically this is UB, but it exists in real-world code and it's
unnecessarily hostile to break such idioms.
Copy link
Contributor

@bsdjhb bsdjhb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know the LLVM code well enough to review, but the test cases look sensible to me.

Copy link
Member

@arichardson arichardson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I do wonder why the clang-format check no longer works 😢

E->getDereferencedBaseExpr(getContext())->IgnoreParenCasts();
if (BaseDeref->isNullPointerConstant(getContext(),
Expr::NPC_ValueDependentIsNotNull))
return cannotSetBounds(*this, E, Ty, Kind,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should be emit a warning and suggest replacing it with (__builtin_)offsetof?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thought did occur to me but then forgot about it; probably should

@jrtc27
Copy link
Member Author

jrtc27 commented Feb 9, 2022

LGTM, but I do wonder why the clang-format check no longer works 😢

Yeah, really odd failure mode

@arichardson
Copy link
Member

ping? Should we merge this as-is or are you planning to add the fixit?

@jrtc27
Copy link
Member Author

jrtc27 commented Aug 15, 2022

From memory I found a bunch of problems in testing this where it didn’t work for anything non-trivial

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.

None yet

3 participants