This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] Loads with !dereferenceable metadata cannot be undef/poison
ClosedPublic

Authored by nikic on May 24 2022, 6:25 AM.

Details

Summary

A load with !dereferenceable or !dereferenceable_or_null metadata must return a well-defined (non-undef/poison) value. Effectively they imply !noundef. This is the same as we do for the dereferenceable(N) attribute.

This should fix https://github.com/llvm/llvm-project/issues/55672, or at least the specific case discussed there.

Diff Detail

Event Timeline

nikic created this revision.May 24 2022, 6:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2022, 6:25 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
nikic requested review of this revision.May 24 2022, 6:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2022, 6:25 AM
aqjune accepted this revision.May 24 2022, 8:13 AM

Per LangRef statements of the definition of dereferenceable(<n>) attribute:

The pointer should be well defined, otherwise it is undefined behavior. This means dereferenceable(<n>) implies noundef.

And the dereferenceable metadata says:

This is analogous to the ‘’dereferenceable’’ attribute on parameters and return values.

would like to interpret this wording as the metadata being equivalent to the attribute.

This revision is now accepted and ready to land.May 24 2022, 8:13 AM
This revision was landed with ongoing or failed builds.May 25 2022, 12:54 AM
This revision was automatically updated to reflect the committed changes.

I just implemented !dereferenceable in Alive2 and got this commit flagged.

I don't see why !dereferenceable should imply !noundef. They are separate concepts: one is about the object's properties (size) and the other is about the object's contents. If you want both, you should create loads with both.
We should strive to have metadata/attributes as disjoint as possible, otherwise some use cases get lost. For example, we have an internal use case, where we badly need to tag loads with !dereferenceable, but not with !noundef.

Can we revert this?

I just implemented !dereferenceable in Alive2 and got this commit flagged.

I don't see why !dereferenceable should imply !noundef. They are separate concepts: one is about the object's properties (size) and the other is about the object's contents. If you want both, you should create loads with both.
We should strive to have metadata/attributes as disjoint as possible, otherwise some use cases get lost. For example, we have an internal use case, where we badly need to tag loads with !dereferenceable, but not with !noundef.

Can we revert this?

Aaah, nervermind. !dereferenceable applies to the loaded value, not to the input ptr. My bad, sorry.