This is an archive of the discontinued LLVM Phabricator instance.

[APInt] Fix isAllOnes and extractBits for zero width values.
ClosedPublic

Authored by lattner on Oct 6 2021, 9:53 AM.

Details

Summary

isAllOnes() should return true for zero bit values because
there are no zeros in it.

Thanks to Jay Foad for pointing this out.

Diff Detail

Event Timeline

lattner created this revision.Oct 6 2021, 9:53 AM
lattner requested review of this revision.Oct 6 2021, 9:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 6 2021, 9:53 AM
foad accepted this revision.Oct 6 2021, 11:56 AM

This makes me happy!

llvm/unittests/ADT/APIntTest.cpp
2994

'true' would be better than '1U', but isn't there an EXPECT_TRUE for this?

This revision is now accepted and ready to land.Oct 6 2021, 11:56 AM
lattner updated this revision to Diff 377642.Oct 6 2021, 12:37 PM

use EXPECT_TRUE as Jay points out

This revision was landed with ongoing or failed builds.Oct 6 2021, 12:38 PM
This revision was automatically updated to reflect the committed changes.

Jay happiness++

joerg added a subscriber: joerg.Oct 12 2021, 6:59 AM

Did this get an audit for existing users? It can be argued in both ways. E.g. "".isdigit() in Python is False, because there is no digit contained and that's pretty much the same use case.

foad added a comment.Oct 12 2021, 7:32 AM

Did this get an audit for existing users? It can be argued in both ways. E.g. "".isdigit() in Python is False, because there is no digit contained and that's pretty much the same use case.

AFAIK there are no in-tree users to audit: zero-width APInts were only introduced very recently, and I don't think they're used in-tree except for unit tests.

Right, they are only being used in the CIRCT incubator project afaik, and it is fine.