Skip to content

Commit 74d7f43

Browse files
authored
[Clang] Fix __{add,remove}_pointer in Objective-C++ (#123678)
This aligns the builtins with how implementations work which don't use the buitins.
1 parent 1224323 commit 74d7f43

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ Bug Fixes in This Version
122122
Bug Fixes to Compiler Builtins
123123
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
124124

125+
- The behvaiour of ``__add_pointer`` and ``__remove_pointer`` for Objective-C++'s ``id`` and interfaces has been fixed.
126+
125127
Bug Fixes to Attribute Support
126128
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
127129

clang/lib/Sema/SemaType.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,8 @@ QualType Sema::BuildPointerType(QualType T,
18261826
if (checkQualifiedFunction(*this, T, Loc, QFK_Pointer))
18271827
return QualType();
18281828

1829-
assert(!T->isObjCObjectType() && "Should build ObjCObjectPointerType");
1829+
if (T->isObjCObjectType())
1830+
return Context.getObjCObjectPointerType(T);
18301831

18311832
// In ARC, it is forbidden to build pointers to unqualified pointers.
18321833
if (getLangOpts().ObjCAutoRefCount)
@@ -9807,8 +9808,7 @@ QualType Sema::BuiltinAddPointer(QualType BaseType, SourceLocation Loc) {
98079808
}
98089809

98099810
QualType Sema::BuiltinRemovePointer(QualType BaseType, SourceLocation Loc) {
9810-
// We don't want block pointers or ObjectiveC's id type.
9811-
if (!BaseType->isAnyPointerType() || BaseType->isObjCIdType())
9811+
if (!BaseType->isAnyPointerType())
98129812
return BaseType;
98139813

98149814
return BaseType->getPointeeType();

clang/test/SemaCXX/remove_pointer.mm

Lines changed: 0 additions & 8 deletions
This file was deleted.

clang/test/SemaObjCXX/type-traits.mm

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c++17 %s
2+
3+
// expected-no-diagnostics
4+
5+
@interface I;
6+
@end
7+
8+
@class C;
9+
10+
static_assert(__is_same(__add_pointer(id), id*));
11+
static_assert(__is_same(__add_pointer(I), I*));
12+
13+
static_assert(__is_same(__remove_pointer(C*), C));
14+
static_assert(!__is_same(__remove_pointer(id), id));
15+
static_assert(__is_same(__remove_pointer(id*), id));
16+
static_assert(__is_same(__remove_pointer(__add_pointer(id)), id));
17+
static_assert(__is_same(__add_pointer(__remove_pointer(id)), id));

0 commit comments

Comments
 (0)