Skip to content

[clang][ptrauth] Make ptrauth feature detection tests more robust #136204

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

ojhunt
Copy link
Contributor

@ojhunt ojhunt commented Apr 17, 2025

The existing test behavior checked for a warning being emitted under an #if, but if the feature detection fails the #if fails and the warning is not expected in the output.

I've made the test more explicit, and added comments to ensure no one simply adds/moves any expected output around.

The existing test behavior checked for a warning being emitted under
an #if, but if the feature detection fails the #if fails and the
warning is not expected in the output.

I've made the test more explicit, and added comments to ensure no
one simply adds/moves any expected output around.
@ojhunt ojhunt requested a review from ahatanak April 17, 2025 21:21
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Apr 17, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 17, 2025

@llvm/pr-subscribers-clang

Author: Oliver Hunt (ojhunt)

Changes

The existing test behavior checked for a warning being emitted under an #if, but if the feature detection fails the #if fails and the warning is not expected in the output.

I've made the test more explicit, and added comments to ensure no one simply adds/moves any expected output around.


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

3 Files Affected:

  • (modified) clang/test/Sema/ptrauth-qualifier.c (+5-3)
  • (modified) clang/test/Sema/ptrauth.c (+5-3)
  • (modified) clang/test/SemaObjC/ptrauth-qualifier.m (+5-3)
diff --git a/clang/test/Sema/ptrauth-qualifier.c b/clang/test/Sema/ptrauth-qualifier.c
index 99d16b062ca6f..ab12acd8975f4 100644
--- a/clang/test/Sema/ptrauth-qualifier.c
+++ b/clang/test/Sema/ptrauth-qualifier.c
@@ -1,9 +1,11 @@
 // RUN: %clang_cc1 -triple arm64-apple-ios -std=c23 -fsyntax-only -verify -fptrauth-intrinsics %s
 // RUN: %clang_cc1 -triple aarch64-linux-gnu -std=c23 -fsyntax-only -verify -fptrauth-intrinsics %s
 
-#if __has_feature(ptrauth_qualifier)
-#warning __ptrauth qualifier enabled!
-// expected-warning@-1 {{__ptrauth qualifier enabled!}}
+#if !__has_extension(ptrauth_qualifier)
+// This error means that the __ptrauth qualifier availability test says  that it
+// is not available. This error is not expected in the output, if it is seen
+// there is a feature detection regression.
+#error __ptrauth qualifier not enabled
 #endif
 
 #if __aarch64__
diff --git a/clang/test/Sema/ptrauth.c b/clang/test/Sema/ptrauth.c
index fc1ae954fa36b..e3932615c2962 100644
--- a/clang/test/Sema/ptrauth.c
+++ b/clang/test/Sema/ptrauth.c
@@ -1,8 +1,10 @@
 // RUN: %clang_cc1 -triple arm64-apple-ios -fsyntax-only -verify -fptrauth-intrinsics %s -fexperimental-new-constant-interpreter
 
-#if __has_feature(ptrauth_intrinsics)
-#warning Pointer authentication enabled!
-// expected-warning@-1 {{Pointer authentication enabled!}}
+#if !__has_feature(ptrauth_intrinsics)
+// This error means that the __ptrauth intrinsics availability test says that
+// they are not available. This error is not expected in the output of this
+// test, if it is seen there is a feature detection regression.
+#error __ptrauth intrinsics not enabled
 #endif
 
 #if __aarch64__
diff --git a/clang/test/SemaObjC/ptrauth-qualifier.m b/clang/test/SemaObjC/ptrauth-qualifier.m
index 4836a653dd02f..98d0248f169be 100644
--- a/clang/test/SemaObjC/ptrauth-qualifier.m
+++ b/clang/test/SemaObjC/ptrauth-qualifier.m
@@ -1,9 +1,11 @@
 // RUN: %clang_cc1 -triple arm64-apple-ios -fsyntax-only -verify -fptrauth-intrinsics %s
 // RUN: %clang_cc1 -triple aarch64-linux-gnu -fsyntax-only -verify -fptrauth-intrinsics %s
 
-#if __has_feature(ptrauth_qualifier)
-#warning __ptrauth qualifier enabled!
-// expected-warning@-1 {{__ptrauth qualifier enabled!}}
+#if !__has_extension(ptrauth_qualifier)
+// This error means that the __ptrauth qualifier availability test says  that it
+// is not available. This error is not expected in the output, if it is seen
+// there is a feature detection regression.
+#error __ptrauth qualifier not enabled
 #endif
 
 @interface Foo

@ojhunt ojhunt merged commit 1dbc8ef into llvm:main Apr 18, 2025
13 checks passed
@ojhunt ojhunt deleted the users/ojhunt/robustify-ptrauth-feature-detection-test branch April 18, 2025 00:53
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…vm#136204)

The existing test behavior checked for a warning being emitted under an
#if, but if the feature detection fails the #if fails and the warning is
not expected in the output.

I've made the test more explicit, and added comments to ensure no one
simply adds/moves any expected output around.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…vm#136204)

The existing test behavior checked for a warning being emitted under an
#if, but if the feature detection fails the #if fails and the warning is
not expected in the output.

I've made the test more explicit, and added comments to ensure no one
simply adds/moves any expected output around.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants