-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang] Fix and test triviality of __ptrauth types #137474
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
Address-discriminated __ptrauth types do not have unique object representations so they are not trivially comparable. Test all other trivialities too even though they are not incorrect. Fixes llvm#137473
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang Author: None (halbi2) ChangesAddress-discriminated __ptrauth types do not have unique object representations so they are not trivially comparable. Test all other trivialities too even though they are not incorrect. Fixes #137473 Full diff: https://github.com/llvm/llvm-project/pull/137474.diff 2 Files Affected:
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index b1ecd9d63702b..c95e733f30494 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2931,9 +2931,9 @@ bool ASTContext::hasUniqueObjectRepresentations(
return true;
}
- // All other pointers are unique.
+ // All other pointers (except __ptrauth pointers) are unique.
if (Ty->isPointerType())
- return true;
+ return !Ty.hasAddressDiscriminatedPointerAuth();
if (const auto *MPT = Ty->getAs<MemberPointerType>())
return !ABI->getMemberPointerInfo(MPT).HasPadding;
diff --git a/clang/test/SemaCXX/ptrauth-triviality.cpp b/clang/test/SemaCXX/ptrauth-triviality.cpp
new file mode 100644
index 0000000000000..baadadca9f64f
--- /dev/null
+++ b/clang/test/SemaCXX/ptrauth-triviality.cpp
@@ -0,0 +1,123 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios -std=c++20 -fptrauth-calls -fptrauth-intrinsics -verify -fsyntax-only %s
+// RUN: %clang_cc1 -triple aarch64-linux-gnu -std=c++20 -fptrauth-calls -fptrauth-intrinsics -verify -fsyntax-only %s
+// expected-no-diagnostics
+
+#define AQ __ptrauth(1,1,50)
+#define IQ __ptrauth(1,0,50)
+#define AA [[clang::ptrauth_vtable_pointer(process_independent,address_discrimination,no_extra_discrimination)]]
+#define IA [[clang::ptrauth_vtable_pointer(process_independent,no_address_discrimination,type_discrimination)]]
+#define PA [[clang::ptrauth_vtable_pointer(process_dependent,no_address_discrimination,no_extra_discrimination)]]
+
+template <class T>
+struct Holder {
+ T t_;
+ bool operator==(const Holder&) const = default;
+};
+
+struct S1 {
+ int * AQ p_;
+ void *payload_;
+ bool operator==(const S1&) const = default;
+};
+static_assert(__is_trivially_constructible(S1));
+static_assert(!__is_trivially_constructible(S1, const S1&));
+static_assert(!__is_trivially_assignable(S1, const S1&));
+static_assert(__is_trivially_destructible(S1));
+static_assert(!__is_trivially_copyable(S1));
+static_assert(!__is_trivially_relocatable(S1));
+static_assert(!__is_trivially_equality_comparable(S1));
+
+static_assert(__is_trivially_constructible(Holder<S1>));
+static_assert(!__is_trivially_constructible(Holder<S1>, const Holder<S1>&));
+static_assert(!__is_trivially_assignable(Holder<S1>, const Holder<S1>&));
+static_assert(__is_trivially_destructible(Holder<S1>));
+static_assert(!__is_trivially_copyable(Holder<S1>));
+static_assert(!__is_trivially_relocatable(Holder<S1>));
+static_assert(!__is_trivially_equality_comparable(Holder<S1>));
+
+struct S2 {
+ int * IQ p_;
+ void *payload_;
+ bool operator==(const S2&) const = default;
+};
+static_assert(__is_trivially_constructible(S2));
+static_assert(__is_trivially_constructible(S2, const S2&));
+static_assert(__is_trivially_assignable(S2, const S2&));
+static_assert(__is_trivially_destructible(S2));
+static_assert(__is_trivially_copyable(S2));
+static_assert(__is_trivially_relocatable(S2));
+static_assert(__is_trivially_equality_comparable(S2));
+
+static_assert(__is_trivially_constructible(Holder<S2>));
+static_assert(__is_trivially_constructible(Holder<S2>, const Holder<S2>&));
+static_assert(__is_trivially_assignable(Holder<S2>, const Holder<S2>&));
+static_assert(__is_trivially_destructible(Holder<S2>));
+static_assert(__is_trivially_copyable(Holder<S2>));
+static_assert(__is_trivially_relocatable(Holder<S2>));
+static_assert(__is_trivially_equality_comparable(Holder<S2>));
+
+struct AA S3 {
+ virtual void f();
+ void *payload_;
+ bool operator==(const S3&) const = default;
+};
+
+static_assert(!__is_trivially_constructible(S3));
+static_assert(!__is_trivially_constructible(S3, const S3&));
+static_assert(!__is_trivially_assignable(S3, const S3&));
+static_assert(__is_trivially_destructible(S3));
+static_assert(!__is_trivially_copyable(S3));
+static_assert(!__is_trivially_relocatable(S3));
+static_assert(!__is_trivially_equality_comparable(S3));
+
+static_assert(!__is_trivially_constructible(Holder<S3>));
+static_assert(!__is_trivially_constructible(Holder<S3>, const Holder<S3>&));
+static_assert(!__is_trivially_assignable(Holder<S3>, const Holder<S3>&));
+static_assert(__is_trivially_destructible(Holder<S3>));
+static_assert(!__is_trivially_copyable(Holder<S3>));
+static_assert(!__is_trivially_relocatable(Holder<S3>));
+static_assert(!__is_trivially_equality_comparable(Holder<S3>));
+
+struct IA S4 {
+ virtual void f();
+ void *payload_;
+ bool operator==(const S4&) const = default;
+};
+
+static_assert(!__is_trivially_constructible(S4));
+static_assert(!__is_trivially_constructible(S4, const S4&));
+static_assert(!__is_trivially_assignable(S4, const S4&));
+static_assert(__is_trivially_destructible(S4));
+static_assert(!__is_trivially_copyable(S4));
+static_assert(!__is_trivially_relocatable(S4));
+static_assert(!__is_trivially_equality_comparable(S4));
+
+static_assert(!__is_trivially_constructible(Holder<S4>));
+static_assert(!__is_trivially_constructible(Holder<S4>, const Holder<S4>&));
+static_assert(!__is_trivially_assignable(Holder<S4>, const Holder<S4>&));
+static_assert(__is_trivially_destructible(Holder<S4>));
+static_assert(!__is_trivially_copyable(Holder<S4>));
+static_assert(!__is_trivially_relocatable(Holder<S4>));
+static_assert(!__is_trivially_equality_comparable(Holder<S4>));
+
+struct PA S5 {
+ virtual void f();
+ void *payload_;
+ bool operator==(const S5&) const = default;
+};
+
+static_assert(!__is_trivially_constructible(S5));
+static_assert(!__is_trivially_constructible(S5, const S5&));
+static_assert(!__is_trivially_assignable(S5, const S5&));
+static_assert(__is_trivially_destructible(S5));
+static_assert(!__is_trivially_copyable(S5));
+static_assert(!__is_trivially_relocatable(S5));
+static_assert(!__is_trivially_equality_comparable(S5));
+
+static_assert(!__is_trivially_constructible(Holder<S5>));
+static_assert(!__is_trivially_constructible(Holder<S5>, const Holder<S5>&));
+static_assert(!__is_trivially_assignable(Holder<S5>, const Holder<S5>&));
+static_assert(__is_trivially_destructible(Holder<S5>));
+static_assert(!__is_trivially_copyable(Holder<S5>));
+static_assert(!__is_trivially_relocatable(Holder<S5>));
+static_assert(!__is_trivially_equality_comparable(Holder<S5>));
|
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.
Good catch, we'll need to add cases to the test when pushing __ptrauth_restricted_intptr
Thanks! |
@halbi2 Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/18/builds/15145 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/174/builds/16865 Here is the relevant piece of the build log for the reference
|
Address-discriminated __ptrauth types do not have unique object representations so they are not trivially comparable. Test all other trivialities too even though they are not incorrect. Fixes llvm#137473
Address-discriminated __ptrauth types do not have unique object representations so they are not trivially comparable. Test all other trivialities too even though they are not incorrect. Fixes llvm#137473
Address-discriminated __ptrauth types do not have unique object representations so they are not trivially comparable. Test all other trivialities too even though they are not incorrect. Fixes llvm#137473
Address-discriminated __ptrauth types do not have unique object representations so they are not trivially comparable. Test all other trivialities too even though they are not incorrect. Fixes llvm#137473
Address-discriminated __ptrauth types do not have unique object representations so they are not trivially comparable. Test all other trivialities too even though they are not incorrect. Fixes llvm#137473
Address-discriminated __ptrauth types do not have unique object representations so they are not trivially comparable. Test all other trivialities too even though they are not incorrect.
Fixes #137473