[all-commits] [llvm/llvm-project] 7b0536: [ADT] Fix specialization of ValueIsPresent for Poi...

Sergei Barannikov via All-commits all-commits at lists.llvm.org
Fri Jan 10 05:43:41 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 7b0536794349734c8862fc140808e4e5a2ab8f8d
      https://github.com/llvm/llvm-project/commit/7b0536794349734c8862fc140808e4e5a2ab8f8d
  Author: Sergei Barannikov <barannikov88 at gmail.com>
  Date:   2025-01-10 (Fri, 10 Jan 2025)

  Changed paths:
    M llvm/include/llvm/Support/Casting.h
    M llvm/lib/CodeGen/RegisterBankInfo.cpp
    M llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp
    M llvm/unittests/ADT/PointerUnionTest.cpp

  Log Message:
  -----------
  [ADT] Fix specialization of ValueIsPresent for PointerUnion (#121847)

Two instances of `PointerUnion` with different active members and null
value compare unequal. Currently, this results in counterintuitive
behavior when using functions from `Casting.h`, e.g.:

```C++
  PointerUnion<int *, float *> U;
  // U = (int *)nullptr;
  dyn_cast<int *>(U); // Aborts
  dyn_cast<float *>(U); // Aborts
  U = (float *)nullptr;
  dyn_cast<int *>(U); // OK
  dyn_cast<float *>(U); // OK
```

`dyn_cast` should abort in all cases because the argument is null.
Currently, it aborts only if the first member is active. This happens
because the partial template specialization of `ValueIsPresent` for
nullable types compares the union with a union constructed from nullptr,
and the two unions compare equal only if their active members are the
same.

This patch changed the specialization of `ValueIsPresent` for nullable
types to make `isPresent()` return false for all possible null values of
a PointerUnion, and fixes two places where the old behavior was
exploited.

Pull Request: https://github.com/llvm/llvm-project/pull/121847



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list