-
Notifications
You must be signed in to change notification settings - Fork 750
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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: llvm/llvm-project#121847
- Loading branch information
1 parent
799e988
commit 7b05367
Showing
4 changed files
with
13 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters