This is an archive of the discontinued LLVM Phabricator instance.

Change DenseMap keys for APInt to avoid collision with valid APIint
ClosedPublic

Authored by rtrieu on Oct 11 2022, 8:44 PM.

Details

Summary

An APInt that can fit into a single word stores the bitwidth and the value. In the normal APInt constructor, bits outside the bitwidth are zeroed out. For a zero-width APInt, the only valid value is zero.

DenseMap requires the use of two special keys, an empty key and a tombstone key. APInt has specified that these keys APInt with bitwidth 0 and value either 0 or 1. For a value of 0, this collides with a valid zero-width APInt. Because of this, using a zero-width APInt with a DenseMap will not work.

This change updates the keys to use ~0 and ~1, which are non-valid for zero-width APInt.

Proposed fix for: https://github.com/llvm/llvm-project/issues/58013

Diff Detail

Event Timeline

rtrieu created this revision.Oct 11 2022, 8:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 11 2022, 8:44 PM
rtrieu requested review of this revision.Oct 11 2022, 8:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 11 2022, 8:44 PM
mizvekov accepted this revision.Oct 26 2022, 8:01 PM
This revision is now accepted and ready to land.Oct 26 2022, 8:01 PM
This revision was automatically updated to reflect the committed changes.