Skip to content

Commit 3386377

Browse files
change include test to only test our generated macro
1 parent f30fddd commit 3386377

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

libc/test/include/CMakeLists.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ add_libc_test(
2323
stdbit_test.cpp
2424
DEPENDS
2525
libc.include.llvm-libc-macros.stdbit_macros
26-
libc.src.__support.CPP.limits
27-
libc.src.stdbit.stdc_leading_zeros_uc
28-
libc.src.stdbit.stdc_leading_zeros_ui
29-
libc.src.stdbit.stdc_leading_zeros_ul
30-
libc.src.stdbit.stdc_leading_zeros_ull
31-
libc.src.stdbit.stdc_leading_zeros_us
26+
libc.include.stdbit
27+
# Intentionally do not depend on libc.src.stdbit.*. The include test is
28+
# simply testing the macros provided by stdbit.h, not the implementation of
29+
# the underlying functions which the type generic macros may dispatch to.
3230
COMPILE_OPTIONS
3331
# stdbit is full of type generic macros implemented via C11 _Generic.
3432
-Wno-c11-extensions

libc/test/include/stdbit_test.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,27 @@
88

99
#include "test/UnitTest/Test.h"
1010

11-
#include "llvm-libc-macros/stdbit-macros.h"
12-
#include "src/__support/CPP/limits.h" // UINT_WIDTH
13-
#include "src/stdbit/stdc_leading_zeros_uc.h"
14-
#include "src/stdbit/stdc_leading_zeros_ui.h"
15-
#include "src/stdbit/stdc_leading_zeros_ul.h"
16-
#include "src/stdbit/stdc_leading_zeros_ull.h"
17-
#include "src/stdbit/stdc_leading_zeros_us.h"
11+
#include <stdbit.h>
12+
13+
/*
14+
* The intent of this test is validate that:
15+
* 1. We provide the definition of the various type generic macros of stdbit.h.
16+
* 2. It dispatches to the correct underlying function.
17+
* Because unit tests build without public packaging, the object files produced
18+
* do not contain non-namespaced symbols.
19+
*/
20+
21+
unsigned char stdc_leading_zeros_uc(unsigned char) { return 0xAA; }
22+
unsigned short stdc_leading_zeros_us(unsigned short) { return 0xAB; }
23+
unsigned stdc_leading_zeros_ui(unsigned) { return 0xAC; }
24+
unsigned long stdc_leading_zeros_ul(unsigned long) { return 0xAD; }
25+
unsigned long long stdc_leading_zeros_ull(unsigned long long) { return 0xAF; }
1826

1927
TEST(LlvmLibcStdbitTest, TypeGenericMacro) {
20-
using namespace LIBC_NAMESPACE;
21-
EXPECT_EQ(stdc_leading_zeros(0U), static_cast<unsigned>(UINT_WIDTH));
28+
EXPECT_EQ(stdc_leading_zeros(static_cast<unsigned char>(0U)), static_cast<unsigned char>(0xAA));
29+
EXPECT_EQ(stdc_leading_zeros(static_cast<unsigned short>(0U)),
30+
static_cast<unsigned short>(0xAB));
31+
EXPECT_EQ(stdc_leading_zeros(0U), static_cast<unsigned>(0xAC));
32+
EXPECT_EQ(stdc_leading_zeros(0UL), static_cast<unsigned long>(0xAD));
33+
EXPECT_EQ(stdc_leading_zeros(0ULL), static_cast<unsigned long long>(0xAF));
2234
}

0 commit comments

Comments
 (0)