This is an archive of the discontinued LLVM Phabricator instance.

[clang][Interp] Check one-past-the-end pointers in GetPtrField
ClosedPublic

Authored by tbaeder on Apr 25 2023, 5:33 AM.

Details

Summary
Rename CheckBaseDerived to something more general and call it in
GetPtrField() as well, so we don't crash later in Pointer::toAPValue().

Diff Detail

Event Timeline

tbaeder created this revision.Apr 25 2023, 5:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2023, 5:33 AM
tbaeder requested review of this revision.Apr 25 2023, 5:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2023, 5:33 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aaron.ballman accepted this revision.May 2 2023, 1:42 PM

LGTM

clang/test/AST/Interp/records.cpp
533–557

Neat! For the tests in this namespace, Clang and ICC agree, GCC and MSVC agree, and users get to cry: https://godbolt.org/z/7EWWrY5z6

This revision is now accepted and ready to land.May 2 2023, 1:42 PM
shafik added inline comments.May 2 2023, 8:59 PM
clang/test/AST/Interp/records.cpp
533–557

Yeah, unfortunate but I am pretty sure clang is correct on both of those.

aaron.ballman added inline comments.May 3 2023, 5:14 AM
clang/test/AST/Interp/records.cpp
533–557

I think Clang is correct on one of those, but not both of them. I think Clang is correct to reject constexpr const int *pn = &(&b + 1)->n; as that involves dereferencing the one-past-the-end pointer, but I think Clang is wrong to reject constexpr A *a2 = &b + 1; as there's no dereference there.

shafik added a subscriber: rsmith.May 3 2023, 10:47 AM
shafik added inline comments.
clang/test/AST/Interp/records.cpp
533–557

@rsmith it looks like you added this diagnostic a while ago see ce1ec5e1f5620 did you mean it to apply to this case? The rules have changed a lot since then so perhaps this was invalid but now is good.

This revision was landed with ongoing or failed builds.Sep 5 2023, 2:02 AM
This revision was automatically updated to reflect the committed changes.