Skip to content
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

Merged
merged 3 commits into from
Feb 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions libc/test/include/stdbit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,38 @@

#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.
* 1. We provide the definition of the various type generic macros of stdbit.h
* (the macros are transitively included from stdbit-macros.h by stdbit.h).
* 2. It dispatches to the correct underlying function.
* Because unit tests build without public packaging, the object files produced
* 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-macros.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 "include/llvm-libc-macros/stdbit-macros.h"

TEST(LlvmLibcStdbitTest, TypeGenericMacroLeadingZeros) {
EXPECT_EQ(stdc_leading_zeros(static_cast<unsigned char>(0U)),
Expand Down
Loading