-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
[libc] fix stdbit include test when not all entrypoints are available #80323
[libc] fix stdbit include test when not all entrypoints are available #80323
Conversation
The intent of the test is to check that: 1. The type generic macros are defined. 2. Those macros dispatch to the correct underlying function. The issue is that when new functionality is added to our stdbit.h without rolling out the new entrypoint to all targets, this test breaks because our generated stdbit.h will not contain declarations for the underlying function. In that case, we should just declare the underlying functions first before including our generated stdbit.h which just contains declarations. A definition is a declaration, but redeclarations must match, hence the additions of noexcept and extern "C".
@llvm/pr-subscribers-libc Author: Nick Desaulniers (nickdesaulniers) ChangesThe intent of the test is to check that:
The issue is that when new functionality is added to our stdbit.h without Full diff: https://github.com/llvm/llvm-project/pull/80323.diff 1 Files Affected:
diff --git a/libc/test/include/stdbit_test.cpp b/libc/test/include/stdbit_test.cpp
index 61e241c8f68a9..4e8498621b683 100644
--- a/libc/test/include/stdbit_test.cpp
+++ b/libc/test/include/stdbit_test.cpp
@@ -8,8 +8,6 @@
#include "test/UnitTest/Test.h"
-#include <stdbit.h>
-
/*
* The intent of this test is validate that:
* 1. We provide the definition of the various type generic macros of stdbit.h.
@@ -18,16 +16,24 @@
* do not contain non-namespaced symbols.
*/
-unsigned char stdc_leading_zeros_uc(unsigned char) { return 0xAA; }
-unsigned short stdc_leading_zeros_us(unsigned short) { return 0xAB; }
-unsigned stdc_leading_zeros_ui(unsigned) { return 0xAC; }
-unsigned long stdc_leading_zeros_ul(unsigned long) { return 0xAD; }
-unsigned long long stdc_leading_zeros_ull(unsigned long long) { return 0xAF; }
-unsigned char stdc_leading_ones_uc(unsigned char) { return 0xBA; }
-unsigned short stdc_leading_ones_us(unsigned short) { return 0xBB; }
-unsigned stdc_leading_ones_ui(unsigned) { return 0xBC; }
-unsigned long stdc_leading_ones_ul(unsigned long) { return 0xBD; }
-unsigned long long stdc_leading_ones_ull(unsigned long long) { return 0xBF; }
+/*
+ * Declare these BEFORE including stdbit.h so that this test may still be run
+ * even if a given target doesn't yet have these individual entrypoints enabled.
+ */
+extern "C" {
+unsigned char stdc_leading_zeros_uc(unsigned char) noexcept { return 0xAA; }
+unsigned short stdc_leading_zeros_us(unsigned short) noexcept { return 0xAB; }
+unsigned stdc_leading_zeros_ui(unsigned) noexcept { return 0xAC; }
+unsigned long stdc_leading_zeros_ul(unsigned long) noexcept { return 0xAD; }
+unsigned long long stdc_leading_zeros_ull(unsigned long long) noexcept { return 0xAF; }
+unsigned char stdc_leading_ones_uc(unsigned char) noexcept { return 0xBA; }
+unsigned short stdc_leading_ones_us(unsigned short) noexcept { return 0xBB; }
+unsigned stdc_leading_ones_ui(unsigned) noexcept { return 0xBC; }
+unsigned long stdc_leading_ones_ul(unsigned long) noexcept { return 0xBD; }
+unsigned long long stdc_leading_ones_ull(unsigned long long) noexcept { return 0xBF; }
+}
+
+#include <stdbit.h>
TEST(LlvmLibcStdbitTest, TypeGenericMacroLeadingZeros) {
EXPECT_EQ(stdc_leading_zeros(static_cast<unsigned char>(0U)),
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
* llvm/main: (500 commits) [docs] Add beginner-focused office hours (llvm#80308) [mlir][sparse] external entry method wrapper for sparse tensors (llvm#80326) [StackSlotColoring] Ignore non-spill objects in RemoveDeadStores. (llvm#80242) [libc][stdbit] fix return types (llvm#80337) Revert "[RISCV] Refine cost on Min/Max reduction" (llvm#80340) [TTI]Add support for strided loads/stores. [analyzer][HTMLRewriter] Cache partial rewrite results. (llvm#80220) [flang][openacc][openmp] Use #0 from hlfir.declare value when generating bound ops (llvm#80317) [AArch64][PAC] Expand blend(reg, imm) operation in aarch64-pauth pass (llvm#74729) [SHT_LLVM_BB_ADDR_MAP][llvm-readobj] Implements llvm-readobj handling for PGOAnalysisMap. (llvm#79520) [libc] add bazel support for most of unistd (llvm#80078) [clang-tidy] Remove enforcement of rule C.48 from cppcoreguidelines-prefer-member-init (llvm#80330) [OpenMP] Fix typo (NFC) (llvm#80332) [BOLT] Enable re-writing of Linux kernel binary (llvm#80228) [BOLT] Adjust section sizes based on file offsets (llvm#80226) [libc] fix stdbit include test when not all entrypoints are available (llvm#80323) [RISCV][GISel] RegBank select and instruction select for vector G_ADD, G_SUB (llvm#74114) [RISCV] Add srmcfg CSR from Ssqosid extension. (llvm#79914) [mlir][sparse] add sparsification options to pretty print and debug s… (llvm#80205) [RISCV][MC] MC layer support for the experimental zalasr extension (llvm#79911) ...
…llvm#80323) The intent of the test is to check that: 1. The type generic macros are defined. 2. Those macros dispatch to the correct underlying function. The issue is that when new functionality is added to our stdbit.h without rolling out the new entrypoint to all targets, this test breaks because our generated stdbit.h will not contain declarations for the underlying function. In that case, we should just declare the underlying functions first before including our generated stdbit.h which just contains declarations. A definition is a declaration, but redeclarations must match, hence the additions of noexcept and extern "C".
The intent of the test is to check that:
The issue is that when new functionality is added to our stdbit.h without
rolling out the new entrypoint to all targets, this test breaks because our
generated stdbit.h will not contain declarations for the underlying function.
In that case, we should just declare the underlying functions first before
including our generated stdbit.h which just contains declarations. A definition
is a declaration, but redeclarations must match, hence the additions of
noexcept and extern "C".