This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Don't check bounds for function pointer
ClosedPublic

Authored by ArcsinX on Mar 30 2022, 10:21 AM.

Details

Summary

Currently, clang crashes with i386 target on the following code:

void f() {
  f + 0xdead000000000000UL;
}

This problem is similar to the problem fixed in D104424, but that fix can't handle function pointer case, because getTypeSizeInCharsIfKnown() says that size is known and equal to 0 for function type.

This patch prevents bounds checking for function pointer, thus fixes the crash.

Fixes https://github.com/llvm/llvm-project/issues/50463

Diff Detail

Event Timeline

ArcsinX created this revision.Mar 30 2022, 10:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 30 2022, 10:21 AM
ArcsinX requested review of this revision.Mar 30 2022, 10:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 30 2022, 10:21 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

It seems like this entire section of code was added here: https://github.com/llvm/llvm-project/commit/ce44fe199bbfd4b5a44764b678c431fdc117116a

@chrish_ericsson_atx should probably take a look at this. That said, we might not want to early-exist here, I think we can just skip the IsUnboundedArray branch? This example worked correctly in the 12.0 branch, so I think it was fine before then.

ArcsinX updated this revision to Diff 419242.Mar 30 2022, 12:17 PM

Check for function type only if IsUnboundedArray is true

That said, we might not want to early-exist here, I think we can just skip the IsUnboundedArray branch?

It seems you are right, thanks, fixed.

I think I'm generally in favor, would still like to see the feedback from the original submitter here to see if there is more work to do in here that would be valuable.

clang/lib/Sema/SemaChecking.cpp
15498

Ah, I see... I originally made the comment thinking that we wanted to be able to get to ~15540 (which this 'return' would seem to undo), but I see this block ends in 'return' anyway. I'm happy with this change the way it is.

Friendly ping.

would still like to see the feedback from the original submitter here to see if there is more work to do in here that would be valuable.

Unsure, maybe we can process without him? It seems his last activity here was more than six months ago.

Friendly ping

erichkeane accepted this revision.Apr 13 2022, 6:37 AM

Friendly ping

Unfriendly LGTM.

This revision is now accepted and ready to land.Apr 13 2022, 6:37 AM
This revision was automatically updated to reflect the committed changes.