llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Loris Reiff (Liblor)

<details>
<summary>Changes</summary>

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
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}

``````````

</details>


https://github.com/llvm/llvm-project/pull/166142
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to