[clang] 74d7f43 - [Clang] Fix __{add, remove}_pointer in Objective-C++ (#123678)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 30 11:34:33 PST 2025
Author: Nikolas Klauser
Date: 2025-01-30T20:34:29+01:00
New Revision: 74d7f43b98910a110bc194752fca829eb19c265a
URL: https://github.com/llvm/llvm-project/commit/74d7f43b98910a110bc194752fca829eb19c265a
DIFF: https://github.com/llvm/llvm-project/commit/74d7f43b98910a110bc194752fca829eb19c265a.diff
LOG: [Clang] Fix __{add,remove}_pointer in Objective-C++ (#123678)
This aligns the builtins with how implementations work which don't use
the buitins.
Added:
clang/test/SemaObjCXX/type-traits.mm
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaType.cpp
Removed:
clang/test/SemaCXX/remove_pointer.mm
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8be1ea2fb01455..8c290437fe16fe 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -122,6 +122,8 @@ Bug Fixes in This Version
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+- The behvaiour of ``__add_pointer`` and ``__remove_pointer`` for Objective-C++'s ``id`` and interfaces has been fixed.
+
Bug Fixes to Attribute Support
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 33d5378944ddbf..2781651b5d8f7d 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)
@@ -9807,8 +9808,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/SemaCXX/remove_pointer.mm b/clang/test/SemaCXX/remove_pointer.mm
deleted file mode 100644
index d1cf1fa9f4efca..00000000000000
--- a/clang/test/SemaCXX/remove_pointer.mm
+++ /dev/null
@@ -1,8 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
-
-// expected-no-diagnostics
-
- at class X;
-
-static_assert(__is_same(__remove_pointer(X *), X), "");
-static_assert(__is_same(__remove_pointer(id), id), "");
diff --git a/clang/test/SemaObjCXX/type-traits.mm b/clang/test/SemaObjCXX/type-traits.mm
new file mode 100644
index 00000000000000..81b9573b521929
--- /dev/null
+++ b/clang/test/SemaObjCXX/type-traits.mm
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c++17 %s
+
+// expected-no-diagnostics
+
+ at interface I;
+ at end
+
+ at class C;
+
+static_assert(__is_same(__add_pointer(id), id*));
+static_assert(__is_same(__add_pointer(I), I*));
+
+static_assert(__is_same(__remove_pointer(C*), C));
+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