Skip to content

[Serialization] Migrate away from PointerUnion::get (NFC) #120844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kazutakahirata
Copy link
Contributor

Note that PointerUnion::get has been soft deprecated in
PointerUnion.h:

// FIXME: Replace the uses of is(), get() and dyn_cast() with
// isa, cast and the llvm::dyn_cast

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.

Note that PointerUnion::get has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.
@kazutakahirata kazutakahirata requested a review from nikic December 21, 2024 17:05
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:modules C++20 modules and Clang Header Modules labels Dec 21, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 21, 2024

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)

Changes

Note that PointerUnion::get has been soft deprecated in
PointerUnion.h:

// FIXME: Replace the uses of is(), get() and dyn_cast() with
// isa<T>, cast<T> and the llvm::dyn_cast<T>

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.


Full diff: https://github.com/llvm/llvm-project/pull/120844.diff

1 Files Affected:

  • (modified) clang/lib/Serialization/MultiOnDiskHashTable.h (+2-2)
diff --git a/clang/lib/Serialization/MultiOnDiskHashTable.h b/clang/lib/Serialization/MultiOnDiskHashTable.h
index a0d75ec3a9e76e..6464220f13aeff 100644
--- a/clang/lib/Serialization/MultiOnDiskHashTable.h
+++ b/clang/lib/Serialization/MultiOnDiskHashTable.h
@@ -93,7 +93,7 @@ template<typename Info> class MultiOnDiskHashTable {
     using result_type = OnDiskTable *;
 
     result_type operator()(void *P) const {
-      return Table::getFromOpaqueValue(P).template get<OnDiskTable *>();
+      return llvm::cast<OnDiskTable *>(Table::getFromOpaqueValue(P));
     }
   };
 
@@ -130,7 +130,7 @@ template<typename Info> class MultiOnDiskHashTable {
     Files.insert(PendingOverrides.begin(), PendingOverrides.end());
     // Explicitly capture Files to work around an MSVC 2015 rejects-valid bug.
     auto ShouldRemove = [&Files](void *T) -> bool {
-      auto *ODT = Table::getFromOpaqueValue(T).template get<OnDiskTable *>();
+      auto *ODT = llvm::cast<OnDiskTable *>(Table::getFromOpaqueValue(T));
       bool Remove = Files.count(ODT->File);
       if (Remove)
         delete ODT;

@llvmbot
Copy link
Member

llvmbot commented Dec 21, 2024

@llvm/pr-subscribers-clang-modules

Author: Kazu Hirata (kazutakahirata)

Changes

Note that PointerUnion::get has been soft deprecated in
PointerUnion.h:

// FIXME: Replace the uses of is(), get() and dyn_cast() with
// isa<T>, cast<T> and the llvm::dyn_cast<T>

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.


Full diff: https://github.com/llvm/llvm-project/pull/120844.diff

1 Files Affected:

  • (modified) clang/lib/Serialization/MultiOnDiskHashTable.h (+2-2)
diff --git a/clang/lib/Serialization/MultiOnDiskHashTable.h b/clang/lib/Serialization/MultiOnDiskHashTable.h
index a0d75ec3a9e76e..6464220f13aeff 100644
--- a/clang/lib/Serialization/MultiOnDiskHashTable.h
+++ b/clang/lib/Serialization/MultiOnDiskHashTable.h
@@ -93,7 +93,7 @@ template<typename Info> class MultiOnDiskHashTable {
     using result_type = OnDiskTable *;
 
     result_type operator()(void *P) const {
-      return Table::getFromOpaqueValue(P).template get<OnDiskTable *>();
+      return llvm::cast<OnDiskTable *>(Table::getFromOpaqueValue(P));
     }
   };
 
@@ -130,7 +130,7 @@ template<typename Info> class MultiOnDiskHashTable {
     Files.insert(PendingOverrides.begin(), PendingOverrides.end());
     // Explicitly capture Files to work around an MSVC 2015 rejects-valid bug.
     auto ShouldRemove = [&Files](void *T) -> bool {
-      auto *ODT = Table::getFromOpaqueValue(T).template get<OnDiskTable *>();
+      auto *ODT = llvm::cast<OnDiskTable *>(Table::getFromOpaqueValue(T));
       bool Remove = Files.count(ODT->File);
       if (Remove)
         delete ODT;

@kazutakahirata kazutakahirata merged commit c9df8da into llvm:main Dec 22, 2024
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_PointerUnion_clang_MultiOnDiskHashTable branch December 22, 2024 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants