Skip to content

[IR] Avoid call to deprecated PointerType::get (NFC) #134609

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

junlarsen
Copy link
Member

Should keep MSVC quiet as noticed by @RKSimon in #134517.

Assertions have been copied over from PointerType::get in order to not silently change invariants with this call.

@llvmbot llvmbot added the llvm:ir label Apr 7, 2025
@junlarsen junlarsen changed the title [IR] Avoid call to deprecated PointerType::getUnqual (NFC)\ [IR] Avoid call to deprecated PointerType::getUnqual (NFC) Apr 7, 2025
Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@junlarsen junlarsen requested a review from RKSimon April 7, 2025 11:02
@llvmbot
Copy link
Member

llvmbot commented Apr 7, 2025

@llvm/pr-subscribers-llvm-ir

Author: Mats Jun Larsen (junlarsen)

Changes

Should keep MSVC quiet as noticed by @rksimon in #134517.

Assertions have been copied over from PointerType::get in order to not silently change invariants with this call.


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

1 Files Affected:

  • (modified) llvm/include/llvm/IR/DerivedTypes.h (+4-1)
diff --git a/llvm/include/llvm/IR/DerivedTypes.h b/llvm/include/llvm/IR/DerivedTypes.h
index ba5c41ff033f5..d0dffa9de616a 100644
--- a/llvm/include/llvm/IR/DerivedTypes.h
+++ b/llvm/include/llvm/IR/DerivedTypes.h
@@ -697,7 +697,10 @@ class PointerType : public Type {
   [[deprecated("PointerType::getUnqual with pointee type is pending removal. "
                "Use Context overload.")]]
   static PointerType *getUnqual(Type *ElementType) {
-    return PointerType::get(ElementType, 0);
+    assert(ElementType && "Can't get a pointer to <null> type!");
+    assert(isValidElementType(ElementType) &&
+           "Invalid type for pointer element!");
+    return PointerType::getUnqual(ElementType->getContext());
   }
 
   /// This constructs an opaque pointer to an object in the

@junlarsen junlarsen changed the title [IR] Avoid call to deprecated PointerType::getUnqual (NFC) [IR] Avoid call to deprecated PointerType::get (NFC) Apr 7, 2025
Copy link
Member

@svenvh svenvh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this fixes the warnings on e.g. gcc 9.4 too.

@junlarsen junlarsen merged commit 4d1e4ef into main Apr 7, 2025
13 checks passed
@junlarsen junlarsen deleted the users/junlarsen/_ir_avoid_call_to_deprecated_pointertype_getunqual_nfc_ branch April 7, 2025 12:09
@RKSimon
Copy link
Collaborator

RKSimon commented Apr 7, 2025

Thanks @junlarsen !

@junlarsen
Copy link
Member Author

Thanks @junlarsen !

Happy to help, thanks for spotting and notifying me of the msvc warnigns!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants