Skip to content

Conversation

@Liblor
Copy link

@Liblor Liblor commented Nov 3, 2025

Similarly to uintptr_t we treat intptr_t as a pointer type.

Link: https://discourse.llvm.org/t/rfc-a-framework-for-allocator-partitioning-hints/87434

@github-actions
Copy link

github-actions bot commented Nov 3, 2025

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Nov 3, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 3, 2025

@llvm/pr-subscribers-clang

Author: Loris Reiff (Liblor)

Changes

Similarly to uintptr_t we treat intptr_t as a pointer type.

Link: https://discourse.llvm.org/t/rfc-a-framework-for-allocator-partitioning-hints/87434


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

2 Files Affected:

  • (modified) clang/lib/AST/InferAlloc.cpp (+4-4)
  • (modified) clang/test/CodeGenCXX/alloc-token-pointer.cpp (+9)
diff --git a/clang/lib/AST/InferAlloc.cpp b/clang/lib/AST/InferAlloc.cpp
index e439ed4dbb386..99f32a1a49708 100644
--- a/clang/lib/AST/InferAlloc.cpp
+++ b/clang/lib/AST/InferAlloc.cpp
@@ -34,10 +34,10 @@ typeContainsPointer(QualType T,
   for (QualType CurrentT = T; const auto *TT = CurrentT->getAs<TypedefType>();
        CurrentT = TT->getDecl()->getUnderlyingType()) {
     const IdentifierInfo *II = TT->getDecl()->getIdentifier();
-    // Special Case: Syntactically uintptr_t is not a pointer; semantically,
-    // however, very likely used as such. Therefore, classify uintptr_t as a
-    // pointer, too.
-    if (II && II->isStr("uintptr_t"))
+    // Special Case: Syntactically intptr and uintptr_t are not pointers;
+    // semantically, however, very likely used as such. Therefore, classify
+    // intptr_t and uintptr_t as pointers, too.
+    if (II && (II->isStr("intptr_t") || II->isStr("uintptr_t")))
       return true;
   }
 
diff --git a/clang/test/CodeGenCXX/alloc-token-pointer.cpp b/clang/test/CodeGenCXX/alloc-token-pointer.cpp
index f12ee7a40a6b8..545e354d1b2fc 100644
--- a/clang/test/CodeGenCXX/alloc-token-pointer.cpp
+++ b/clang/test/CodeGenCXX/alloc-token-pointer.cpp
@@ -2,6 +2,7 @@
 
 #include "../Analysis/Inputs/system-header-simulator-cxx.h"
 
+typedef __INTPTR_TYPE__ intptr_t;
 typedef __UINTPTR_TYPE__ uintptr_t;
 
 extern "C" {
@@ -187,6 +188,13 @@ uptr *test_uintptr_isptr2() {
   return new uptr;
 }
 
+using iptr = intptr_t;
+// CHECK-LABEL: define dso_local noundef ptr @_Z17test_intptr_isptrv(
+// CHECK: call noalias noundef nonnull ptr @_Znwm(i64 noundef 8){{.*}} !alloc_token [[META_INTPTRT:![0-9]+]]
+iptr *test_intptr_isptr() {
+  return new iptr;
+}
+
 // CHECK: [[META_INT]] = !{!"int", i1 false}
 // CHECK: [[META_INTPTR]] = !{!"int *", i1 true}
 // CHECK: [[META_ULONG]] = !{!"unsigned long", i1 false}
@@ -195,3 +203,4 @@ uptr *test_uintptr_isptr2() {
 // CHECK: [[META_VIRTUALTESTCLASS]] = !{!"VirtualTestClass", i1 true}
 // CHECK: [[META_MYSTRUCTUINTPTR]] = !{!"MyStructUintptr", i1 true}
 // CHECK: [[META_UINTPTR]] = !{!"unsigned long", i1 true}
+// CHECK: [[META_INTPTRT]] = !{!"long", i1 true}

@melver melver self-requested a review November 3, 2025 10:30
@melver
Copy link
Contributor

melver commented Nov 3, 2025

Let's hold off on this until we know that intptr_t usage actually warrants this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants