-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[Clang] Fix __{add,remove}_pointer in Objective-C++ #123678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-clang Author: Nikolas Klauser (philnik777) ChangesThis aligns the builtins with how implementations work which don't use the buitins. Full diff: https://github.com/llvm/llvm-project/pull/123678.diff 2 Files Affected:
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
+
+@interface I;
+@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));
|
cor3ntin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a changelog entry?
233d8d7 to
98395fd
Compare
AaronBallman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oof, I'd like to hear from @rjmccall -- Objective-C pointer types are not C pointer types.
|
It's probably right that these should match the behavior of adding or removing a |
|
@AaronBallman is there anything blocking this? I'd really like to have this in the release branch as early as possible. |
AaronBallman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
98395fd to
2fe753b
Compare
2fe753b to
3c1c9bf
Compare
|
/cherry-pick 74d7f43 |
Error: Command failed due to missing milestone. |
|
/cherry-pick 74d7f43 |
|
Failed to cherry-pick: 74d7f43 https://github.com/llvm/llvm-project/actions/runs/13060196391 Please manually backport the fix and push it to your github fork. Once this is done, please create a pull request |
This aligns the builtins with how implementations work which don't use the buitins.
This aligns the builtins with how implementations work which don't use the buitins.
|
@philnik777 Were you able to manually create the backport pull request? |
This aligns the builtins with how implementations work which don't use the buitins.