This is an archive of the discontinued LLVM Phabricator instance.

[PATCH] Fix UBSAN in __ubsan::Value::getSIntValue
ClosedPublic

Authored by marxin on Feb 23 2021, 1:13 AM.

Details

Summary

As reported here:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99190

it fixes:

// gcc -fsanitize=shift -w
// ldd a.out produces
// libubsan.so.1 => /home/vitti/local/gcc-150221-undefined/lib64/libubsan.so.1
// ./a.out produces
// ../../../../gcc-150221/libsanitizer/ubsan/ubsan_value.cpp:77:25: runtime error: left shift of 0x0000000000000000fffffffffffffffb by 96 places cannot be represented in type '__int128'
// ubsan_value.cpp:77 -> "return SIntMax(Val) << ExtraBits >> ExtraBits;"
int main (void)
{

  1 << -5;

  return 0;
}

Diff Detail

Event Timeline

marxin requested review of this revision.Feb 23 2021, 1:13 AM
marxin created this revision.
vitalybuka accepted this revision.Feb 23 2021, 2:02 AM
This revision is now accepted and ready to land.Feb 23 2021, 2:02 AM

Can you try to add a test?

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 23 2021, 2:10 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript

Can you try to add a test?

I don't an easy way how to do that. Anyway, I've just pushed the revision.
Thanks for the review.