Skip to content

[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

Merged
merged 1 commit into from
Apr 28, 2025
Merged

Conversation

halbi2
Copy link
Contributor

@halbi2 halbi2 commented Apr 26, 2025

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

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
Copy link

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 @ followed by their GitHub username.

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.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Apr 26, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 26, 2025

@llvm/pr-subscribers-clang

Author: None (halbi2)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/137474.diff

2 Files Affected:

  • (modified) clang/lib/AST/ASTContext.cpp (+2-2)
  • (added) clang/test/SemaCXX/ptrauth-triviality.cpp (+123)
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>));

Copy link
Contributor

@ojhunt ojhunt left a 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

@ojhunt
Copy link
Contributor

ojhunt commented Apr 28, 2025

Thanks!

@ojhunt ojhunt merged commit c215318 into llvm:main Apr 28, 2025
14 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Pointer Authentication Tasks Apr 28, 2025
Copy link

@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-ci
Copy link
Collaborator

llvm-ci commented Apr 28, 2025

LLVM Buildbot has detected a new failure on builder lldb-arm-ubuntu running on linaro-lldb-arm-ubuntu while building clang at step 6 "test".

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
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: symbol_ondemand/breakpoint_source_regex/TestSourceTextRegexBreakpoint.py (1143 of 3001)
PASS: lldb-api :: python_api/watchpoint/watchlocation/TestSetWatchlocation.py (1144 of 3001)
PASS: lldb-api :: source-manager/TestSourceManager.py (1145 of 3001)
PASS: lldb-api :: symbol_ondemand/shared_library/TestSharedLibOnDemand.py (1146 of 3001)
PASS: lldb-api :: terminal/TestSTTYBeforeAndAfter.py (1147 of 3001)
PASS: lldb-api :: test_utils/TestDecorators.py (1148 of 3001)
PASS: lldb-api :: test_utils/TestInlineTest.py (1149 of 3001)
PASS: lldb-api :: test_utils/TestPExpectTest.py (1150 of 3001)
PASS: lldb-api :: test_utils/base/TestBaseTest.py (1151 of 3001)
PASS: lldb-api :: python_api/watchpoint/watchlocation/TestTargetWatchAddress.py (1152 of 3001)
FAIL: lldb-api :: tools/lldb-dap/attach/TestDAP_attachByPortNum.py (1153 of 3001)
******************** TEST 'lldb-api :: tools/lldb-dap/attach/TestDAP_attachByPortNum.py' FAILED ********************
Script:
--
/usr/bin/python3.10 /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib --env LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/include --env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --arch armv8l --build-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex --lldb-module-cache-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/lldb --compiler /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/clang --dsymutil /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/dsymutil --make /usr/bin/gmake --llvm-tools-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --lldb-obj-root /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lldb --lldb-libs-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/tools/lldb-dap/attach -p TestDAP_attachByPortNum.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision c21531895a5d5e6ffc349d6e229d71dd1463860a)
  clang revision c21531895a5d5e6ffc349d6e229d71dd1463860a
  llvm revision c21531895a5d5e6ffc349d6e229d71dd1463860a
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 'debugserver', 'objc']

--
Command Output (stderr):
--
Usage:
  /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/lldb-server v[ersion]
  /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/lldb-server g[dbserver] [options]
  /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/lldb-server p[latform] [options]
Invoke subcommand for additional help
PASS: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_by_illegal_port (TestDAP_attachByPortNum.TestDAP_attachByPortNum)
========= DEBUG ADAPTER PROTOCOL LOGS =========
1745810504.017233849 --> (stdin/stdout) {"command":"initialize","type":"request","arguments":{"adapterID":"lldb-native","clientID":"vscode","columnsStartAt1":true,"linesStartAt1":true,"locale":"en-us","pathFormat":"path","supportsRunInTerminalRequest":true,"supportsVariablePaging":true,"supportsVariableType":true,"supportsStartDebuggingRequest":true,"supportsProgressReporting":true,"$__lldb_sourceInitFile":true},"seq":1}
1745810504.021262169 <-- (stdin/stdout) {"body":{"$__lldb_version":"lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision c21531895a5d5e6ffc349d6e229d71dd1463860a)\n  clang revision c21531895a5d5e6ffc349d6e229d71dd1463860a\n  llvm revision c21531895a5d5e6ffc349d6e229d71dd1463860a","completionTriggerCharacters":["."," ","\t"],"exceptionBreakpointFilters":[{"default":false,"filter":"cpp_catch","label":"C++ Catch"},{"default":false,"filter":"cpp_throw","label":"C++ Throw"},{"default":false,"filter":"objc_catch","label":"Objective-C Catch"},{"default":false,"filter":"objc_throw","label":"Objective-C Throw"}],"supportTerminateDebuggee":true,"supportsBreakpointLocationsRequest":true,"supportsCancelRequest":true,"supportsCompletionsRequest":true,"supportsConditionalBreakpoints":true,"supportsConfigurationDoneRequest":true,"supportsDataBreakpoints":true,"supportsDelayedStackTraceLoading":true,"supportsDisassembleRequest":true,"supportsEvaluateForHovers":true,"supportsExceptionInfoRequest":true,"supportsExceptionOptions":true,"supportsFunctionBreakpoints":true,"supportsHitConditionalBreakpoints":true,"supportsInstructionBreakpoints":true,"supportsLogPoints":true,"supportsModulesRequest":true,"supportsReadMemoryRequest":true,"supportsRestartRequest":true,"supportsSetVariable":true,"supportsStepInTargetsRequest":true,"supportsSteppingGranularity":true,"supportsValueFormattingOptions":true},"command":"initialize","request_seq":1,"seq":0,"success":true,"type":"response"}
1745810504.021747351 --> (stdin/stdout) {"command":"attach","type":"request","arguments":{"program":"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/tools/lldb-dap/attach/TestDAP_attachByPortNum.test_by_illegal_port/a.out","initCommands":["settings clear -all","settings set symbols.enable-external-lookup false","settings set target.inherit-tcc true","settings set target.disable-aslr false","settings set target.detach-on-error false","settings set target.auto-apply-fixits false","settings set plugin.process.gdb-remote.packet-timeout 60","settings set symbols.clang-modules-cache-path \"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api\"","settings set use-color false","settings set show-statusline false"],"gdb-remote-port":65536},"seq":2}
1745810504.022583246 <-- (stdin/stdout) {"body":{"category":"console","output":"Running initCommands:\n"},"event":"output","seq":0,"type":"event"}
1745810504.022663832 <-- (stdin/stdout) {"body":{"category":"console","output":"(lldb) settings clear -all\n"},"event":"output","seq":0,"type":"event"}
1745810504.022678375 <-- (stdin/stdout) {"body":{"category":"console","output":"(lldb) settings set symbols.enable-external-lookup false\n"},"event":"output","seq":0,"type":"event"}
1745810504.022692919 <-- (stdin/stdout) {"body":{"category":"console","output":"(lldb) settings set target.inherit-tcc true\n"},"event":"output","seq":0,"type":"event"}
1745810504.022705078 <-- (stdin/stdout) {"body":{"category":"console","output":"(lldb) settings set target.disable-aslr false\n"},"event":"output","seq":0,"type":"event"}
1745810504.022717237 <-- (stdin/stdout) {"body":{"category":"console","output":"(lldb) settings set target.detach-on-error false\n"},"event":"output","seq":0,"type":"event"}
1745810504.022729158 <-- (stdin/stdout) {"body":{"category":"console","output":"(lldb) settings set target.auto-apply-fixits false\n"},"event":"output","seq":0,"type":"event"}
1745810504.022741318 <-- (stdin/stdout) {"body":{"category":"console","output":"(lldb) settings set plugin.process.gdb-remote.packet-timeout 60\n"},"event":"output","seq":0,"type":"event"}
1745810504.022806883 <-- (stdin/stdout) {"body":{"category":"console","output":"(lldb) settings set symbols.clang-modules-cache-path \"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api\"\n"},"event":"output","seq":0,"type":"event"}
1745810504.022819519 <-- (stdin/stdout) {"body":{"category":"console","output":"(lldb) settings set use-color false\n"},"event":"output","seq":0,"type":"event"}
1745810504.022831440 <-- (stdin/stdout) {"body":{"category":"console","output":"(lldb) settings set show-statusline false\n"},"event":"output","seq":0,"type":"event"}

@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 28, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-gcc-ubuntu running on sie-linux-worker3 while building clang at step 6 "test-build-unified-tree-check-all".

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
Step 6 (test-build-unified-tree-check-all) failure: 1200 seconds without output running [b'ninja', b'check-all'], attempting to kill
...
PASS: lit :: shtest-not.py (90433 of 90443)
PASS: lit :: allow-retries.py (90434 of 90443)
PASS: lit :: discovery.py (90435 of 90443)
PASS: lit :: shtest-external-shell-kill.py (90436 of 90443)
PASS: lit :: googletest-timeout.py (90437 of 90443)
PASS: lit :: selecting.py (90438 of 90443)
PASS: lit :: shtest-timeout.py (90439 of 90443)
PASS: lit :: max-time.py (90440 of 90443)
PASS: lit :: shtest-shell.py (90441 of 90443)
PASS: lit :: shtest-define.py (90442 of 90443)
command timed out: 1200 seconds without output running [b'ninja', b'check-all'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=1850.625370

jyli0116 pushed a commit to jyli0116/llvm-project that referenced this pull request Apr 28, 2025
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
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
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
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
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
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
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
Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request May 9, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

New __ptrauth types are wrongly reported as __is_trivially_equality_comparable
4 participants