[clang] [Clang] Fix __{add, remove}_pointer in Objective-C++ (PR #123678)
Nikolas Klauser via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 20 17:24:14 PST 2025
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/123678
This aligns the builtins with how implementations work which don't use the buitins.
>From 233d8d797a7a915d4100d7ca4259bb28611c7d90 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Tue, 21 Jan 2025 02:16:02 +0100
Subject: [PATCH] [Clang] Fix __{add,remove}_pointer in Objective-C++
---
clang/lib/Sema/SemaType.cpp | 6 +++---
clang/test/SemaObjCXX/type-traits.mm | 14 ++++++++++++++
2 files changed, 17 insertions(+), 3 deletions(-)
create mode 100644 clang/test/SemaObjCXX/type-traits.mm
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 2ccf5a8e1d6f31..10be75c53af08f 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1826,7 +1826,8 @@ QualType Sema::BuildPointerType(QualType T,
if (checkQualifiedFunction(*this, T, Loc, QFK_Pointer))
return QualType();
- assert(!T->isObjCObjectType() && "Should build ObjCObjectPointerType");
+ if (T->isObjCObjectType())
+ return Context.getObjCObjectPointerType(T);
// In ARC, it is forbidden to build pointers to unqualified pointers.
if (getLangOpts().ObjCAutoRefCount)
@@ -9806,8 +9807,7 @@ QualType Sema::BuiltinAddPointer(QualType BaseType, SourceLocation Loc) {
}
QualType Sema::BuiltinRemovePointer(QualType BaseType, SourceLocation Loc) {
- // We don't want block pointers or ObjectiveC's id type.
- if (!BaseType->isAnyPointerType() || BaseType->isObjCIdType())
+ if (!BaseType->isAnyPointerType())
return BaseType;
return BaseType->getPointeeType();
diff --git a/clang/test/SemaObjCXX/type-traits.mm b/clang/test/SemaObjCXX/type-traits.mm
new file mode 100644
index 00000000000000..20cb980e8880bf
--- /dev/null
+++ b/clang/test/SemaObjCXX/type-traits.mm
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c++17 %s
+
+// expected-no-diagnostics
+
+ at interface I;
+ at end
+
+static_assert(__is_same(__add_pointer(id), id*));
+static_assert(__is_same(__add_pointer(I), I*));
+
+static_assert(!__is_same(__remove_pointer(id), id));
+static_assert(__is_same(__remove_pointer(id*), id));
+static_assert(__is_same(__remove_pointer(__add_pointer(id)), id));
+static_assert(__is_same(__add_pointer(__remove_pointer(id)), id));
More information about the cfe-commits
mailing list