https://github.com/abhijeetsharma200 updated 
https://github.com/llvm/llvm-project/pull/182994

>From 992af0eab8af79b75fb75e7e77017ea8a75f3df5 Mon Sep 17 00:00:00 2001
From: Abhijeet Sharma <[email protected]>
Date: Tue, 24 Feb 2026 05:53:53 +0100
Subject: [PATCH] Add __has_feature(bounds_safety)

Teach the preprocessor to evaluate __has_feature(bounds_safety) based on
LangOpts.BoundsSafety. This is used by headers to conditionally enable
bounds-safety annotations/macros when -fbounds-safety is enabled.

Fixes #182948
---
 clang/include/clang/Basic/Features.def          |  1 +
 clang/test/Preprocessor/bounds-safety-feature.c | 10 ++++++++++
 2 files changed, 11 insertions(+)
 create mode 100644 clang/test/Preprocessor/bounds-safety-feature.c

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index ea5198a079254..18875db812075 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -324,6 +324,7 @@ FEATURE(shadow_call_stack,
 FEATURE(tls, PP.getTargetInfo().isTLSSupported())
 FEATURE(underlying_type, LangOpts.CPlusPlus)
 FEATURE(experimental_library, LangOpts.ExperimentalLibrary)
+FEATURE(bounds_safety, LangOpts.BoundsSafety)
 
 // C11 features supported by other languages as extensions.
 EXTENSION(c_alignas, true)
diff --git a/clang/test/Preprocessor/bounds-safety-feature.c 
b/clang/test/Preprocessor/bounds-safety-feature.c
new file mode 100644
index 0000000000000..f1c1be7922dc3
--- /dev/null
+++ b/clang/test/Preprocessor/bounds-safety-feature.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -E %s -fexperimental-bounds-safety | FileCheck %s 
--check-prefix=ENABLED
+// RUN: %clang_cc1 -E %s                              | FileCheck %s 
--check-prefix=DISABLED
+
+#if __has_feature(bounds_safety)
+// ENABLED: has_bounds_safety
+void has_bounds_safety() {}
+#else
+// DISABLED: no_bounds_safety
+void no_bounds_safety() {}
+#endif

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to