This is an archive of the discontinued LLVM Phabricator instance.

[Libomptarget] Fix bucket selection in MemoryManager.h
AcceptedPublic

Authored by protze.joachim on Jun 30 2022, 1:57 AM.

Details

Summary

Fixes an integer overflow in floorToPowerOfTwo for 0x8000 0000 (32bit arch) / 0x8000 0000 0000 0000 (64bit arch) and higher.

Fixes the binary search in findBucket to return the intended bucket (e.g., 35 and 120 or 259 and 1020 went to the same bucket).

Diff Detail

Event Timeline

protze.joachim created this revision.Jun 30 2022, 1:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2022, 1:57 AM
protze.joachim requested review of this revision.Jun 30 2022, 1:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2022, 1:57 AM

I don't understand. Here we all do >> operation. How could it cause overflow?

protze.joachim edited the summary of this revision. (Show Details)Jul 1 2022, 12:18 AM

I don't understand. Here we all do >> operation. How could it cause overflow?

The function also has | (soft addition) and one +, which overflows, when you pass 0x8000 0000 to the function. The first few lines propagate the 1 all the way to the right, so that you get 0xFFFF FFFF, adding 1 gives you 0x0.

tianshilei1992 accepted this revision.Jul 1 2022, 1:17 PM

I don't understand. Here we all do >> operation. How could it cause overflow?

The function also has | (soft addition) and one +, which overflows, when you pass 0x8000 0000 to the function. The first few lines propagate the 1 all the way to the right, so that you get 0xFFFF FFFF, adding 1 gives you 0x0.

I see. Yeah, that should be the case.

This revision is now accepted and ready to land.Jul 1 2022, 1:17 PM