Skip to content

Conversation

@jhuber6
Copy link
Contributor

@jhuber6 jhuber6 commented Aug 18, 2025

Summary:
We added boolean vectors in clang 15 and wish to extend them further in
clang-22. However, there's no way to query for their support as they are
separate to the normal extended vector type. This adds a feature so we
can check for it as a feature directly.

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

llvmbot commented Aug 18, 2025

@llvm/pr-subscribers-clang

Author: Joseph Huber (jhuber6)

Changes

Summary:
We added boolean vectors in clang 15 and wish to extend them further in
clang-22. However, there's no way to query for their support as they are
separate to the normal extended vector type. This adds a feature so we
can check for it as a feature directly.


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

3 Files Affected:

  • (modified) clang/docs/LanguageExtensions.rst (+2-1)
  • (modified) clang/include/clang/Basic/Features.def (+1)
  • (modified) clang/test/SemaCXX/vector-bool.cpp (+4)
diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst
index 97413588fea15..953278aa62c6c 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -635,11 +635,12 @@ C and C++.  For example:
     return v;
   }
 
+
 Boolean vectors are a Clang extension of the ext vector type.  Boolean vectors
 are intended, though not guaranteed, to map to vector mask registers.  The size
 parameter of a boolean vector type is the number of bits in the vector.  The
 boolean vector is dense and each bit in the boolean vector is one vector
-element.
+element. Query for this feature with ``__has_feature(boolean_vectors)```.
 
 The semantics of boolean vectors borrows from C bit-fields with the following
 differences:
diff --git a/clang/include/clang/Basic/Features.def b/clang/include/clang/Basic/Features.def
index b9efc6a6a2e9d..d3c7642e53963 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -128,6 +128,7 @@ FEATURE(attribute_overloadable, true)
 FEATURE(attribute_unavailable_with_message, true)
 FEATURE(attribute_unused_on_fields, true)
 FEATURE(attribute_diagnose_if_objc, true)
+FEATURE(boolean_vectors, true)
 FEATURE(blocks, LangOpts.Blocks)
 FEATURE(c_thread_safety_attributes, true)
 FEATURE(cxx_exceptions, LangOpts.CXXExceptions)
diff --git a/clang/test/SemaCXX/vector-bool.cpp b/clang/test/SemaCXX/vector-bool.cpp
index cd638056f348b..b5160c4cee540 100644
--- a/clang/test/SemaCXX/vector-bool.cpp
+++ b/clang/test/SemaCXX/vector-bool.cpp
@@ -112,3 +112,7 @@ void Sizeof() {
   static_assert(sizeof(Bool195) == 32);
   static_assert(sizeof(Bool257) == 64);
 }
+
+#if !__has_feature(boolean_vectors)
+#error "FAIL"
+#endif

Copy link
Collaborator

@erichkeane erichkeane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I clicked accept, but not sure I'm super in favor of the name? Maybe see if folks will bikeshed it for you? I'm a bit concerned it is too close to other things (vector is ambiguous of course).

Maybe:

boolean_gnu_vector_type and boolean_ext_vector_type

WDYT?

@jhuber6
Copy link
Contributor Author

jhuber6 commented Aug 19, 2025

I clicked accept, but not sure I'm super in favor of the name? Maybe see if folks will bikeshed it for you? I'm a bit concerned it is too close to other things (vector is ambiguous of course).

Maybe:

boolean_gnu_vector_type and boolean_ext_vector_type

WDYT?

Yeah, I was wondering about that. I don't think we support the GNU vectors to be boolean yet so it can be a little confusing. Maybe just ext_vector_type_boolean?

@erichkeane
Copy link
Collaborator

I clicked accept, but not sure I'm super in favor of the name? Maybe see if folks will bikeshed it for you? I'm a bit concerned it is too close to other things (vector is ambiguous of course).
Maybe:
boolean_gnu_vector_type and boolean_ext_vector_type
WDYT?

Yeah, I was wondering about that. I don't think we support the GNU vectors to be boolean yet so it can be a little confusing. Maybe just ext_vector_type_boolean?

ah, sure. Then when/if we get gnu version we can do gnu_vector_type_boolean? Works for me and is 'specific' enough I'm no longer worried. Make it so :)

Summary:
We added boolean vectors in clang 15 and wish to extend them further in
clang-22. However, there's no way to query for their support as they are
separate to the normal extended vector type. This adds a feature so we
can check for it as a feature directly.
@jhuber6 jhuber6 changed the title [Clang] Add queryable feature 'boolean_vectors' for SIMD masks [Clang] Add queryable feature 'ext_vector_type_boolean' for SIMD masks Aug 19, 2025
@jhuber6 jhuber6 merged commit 2f6b747 into llvm:main Aug 20, 2025
10 checks passed
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

None yet

Development

Successfully merging this pull request may close these issues.

3 participants