This is an archive of the discontinued LLVM Phabricator instance.

[builtins] Fix signed integer overflows in divmodsi4.c, divmoddi4.c and divmodti4.c
ClosedPublic

Authored by Ka-Ka on Aug 25 2023, 12:41 AM.

Details

Summary

When compiling the builtins with the undefined behavior sanitizer and running testcases you end up with the following warning:

UBSan: divmodsi4.c:22:17: signed integer overflow: 2147483647 - -1 cannot be represented in type 'si_int' (aka 'long')

This can be avoided by doing the subtract in a matching unsigned variant of the type.

The same kind of pattern is found in divmoddi4.c and divmodti4.c

This was found in an out of tree target.

Diff Detail

Event Timeline

Ka-Ka created this revision.Aug 25 2023, 12:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 25 2023, 12:41 AM
Herald added a subscriber: Enna1. · View Herald Transcript
Ka-Ka requested review of this revision.Aug 25 2023, 12:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 25 2023, 12:41 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
MaskRay accepted this revision.Aug 25 2023, 10:31 AM
This revision is now accepted and ready to land.Aug 25 2023, 10:31 AM