[libc-commits] [libc] [libc] remove stdc_leading_zeros for now (PR #79915)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Mon Jan 29 16:14:26 PST 2024


https://github.com/nickdesaulniers created https://github.com/llvm/llvm-project/pull/79915

The type generic macro had numerous issues.

The include test is broken for GCC.

    libc/test/include/stdbit_test.cpp:34:13: error: ‘_Generic’ was not declared in this scope
       34 |   EXPECT_EQ(stdc_leading_zeros(0ULL), static_cast<unsigned long long>(0xAF));
          |             ^~~~~~~~~~~~~~~~~~

Also, -Wc11-extensions (and thus -Wno-c11-extensions) are clang-only.

    cc1plus: note: unrecognized command-line option ‘-Wno-c11-extensions’ may
    have been intended to silence earlier diagnostics

And the hermetic test seems to be getting our generated stdbit.h, but the unit
tests does not.

I'll investigate this more later, but let's get the build bots back to green.


>From eb6fd92473410217ee94477405a8f8d508e54aae Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Mon, 29 Jan 2024 16:11:38 -0800
Subject: [PATCH] [libc] remove stdc_leading_zeros for now
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The type generic macro had numerous issues.

The include test is broken for GCC.

    libc/test/include/stdbit_test.cpp:34:13: error: ‘_Generic’ was not declared in this scope
       34 |   EXPECT_EQ(stdc_leading_zeros(0ULL), static_cast<unsigned long long>(0xAF));
          |             ^~~~~~~~~~~~~~~~~~

Also, -Wc11-extensions (and thus -Wno-c11-extensions) are clang-only.

    cc1plus: note: unrecognized command-line option ‘-Wno-c11-extensions’ may
    have been intended to silence earlier diagnostics

And the hermetic test seems to be getting our generated stdbit.h, but the unit
tests does not.

I'll investigate this more later, but let's get the build bots back to green.
---
 libc/include/llvm-libc-macros/stdbit-macros.h | 20 -----------
 libc/include/stdbit.h.def                     |  1 -
 libc/test/include/CMakeLists.txt              | 23 ------------
 libc/test/include/stdbit_test.cpp             | 35 -------------------
 4 files changed, 79 deletions(-)
 delete mode 100644 libc/include/llvm-libc-macros/stdbit-macros.h
 delete mode 100644 libc/test/include/stdbit_test.cpp

diff --git a/libc/include/llvm-libc-macros/stdbit-macros.h b/libc/include/llvm-libc-macros/stdbit-macros.h
deleted file mode 100644
index febe95fe0a1e3c1..000000000000000
--- a/libc/include/llvm-libc-macros/stdbit-macros.h
+++ /dev/null
@@ -1,20 +0,0 @@
-//===-- Definition of macros to be used with stdbit functions ----------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef __LLVM_LIBC_MACROS_STDBIT_MACROS_H
-#define __LLVM_LIBC_MACROS_STDBIT_MACROS_H
-
-#define stdc_leading_zeros(x)                                                  \
-  _Generic((x),                                                                \
-      unsigned char: stdc_leading_zeros_uc,                                    \
-      unsigned short: stdc_leading_zeros_us,                                   \
-      unsigned: stdc_leading_zeros_ui,                                         \
-      unsigned long: stdc_leading_zeros_ul,                                    \
-      unsigned long long: stdc_leading_zeros_ull)(x)
-
-#endif // __LLVM_LIBC_MACROS_STDBIT_MACROS_H
diff --git a/libc/include/stdbit.h.def b/libc/include/stdbit.h.def
index cb79ac1caf049fd..10e1e8153a573fc 100644
--- a/libc/include/stdbit.h.def
+++ b/libc/include/stdbit.h.def
@@ -10,7 +10,6 @@
 #define LLVM_LIBC_STDBIT_H
 
 #include <__llvm-libc-common.h>
-#include <llvm-libc-macros/stdbit-macros.h>
 
 %%public_api()
 
diff --git a/libc/test/include/CMakeLists.txt b/libc/test/include/CMakeLists.txt
index ecc32380c596e06..183e7ecde719e55 100644
--- a/libc/test/include/CMakeLists.txt
+++ b/libc/test/include/CMakeLists.txt
@@ -14,26 +14,3 @@ add_libc_test(
     # This is needed because the __containerof macro uses statement expression.
     -Wno-gnu-statement-expression-from-macro-expansion
 )
-
-# stdbit_test only tests our generated stdbit.h, which is not generated in
-# overlay mode.
-if (LLVM_LIBC_FULL_BUILD)
-  add_libc_test(
-    stdbit_test
-    SUITE
-      libc_include_tests
-    SRCS
-      stdbit_test.cpp
-    DEPENDS
-      libc.include.llvm-libc-macros.stdbit_macros
-      libc.include.stdbit
-      # Intentionally do not depend on libc.src.stdbit.*. The include test is
-      # simply testing the macros provided by stdbit.h, not the implementation
-      # of the underlying functions which the type generic macros may dispatch
-      # to.
-    COMPILE_OPTIONS
-      # stdbit.h is full of type generic macros implemented via C11 _Generic.
-      # Clang will produce -Wno-c11-extensions when using _Generic in C++ mode.
-      -Wno-c11-extensions
-  )
-endif()
diff --git a/libc/test/include/stdbit_test.cpp b/libc/test/include/stdbit_test.cpp
deleted file mode 100644
index d20005cc31afa00..000000000000000
--- a/libc/test/include/stdbit_test.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-//===-- Unittests for stdbit ----------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDSList-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#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.
- * 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; }
-
-TEST(LlvmLibcStdbitTest, TypeGenericMacro) {
-  EXPECT_EQ(stdc_leading_zeros(static_cast<unsigned char>(0U)),
-            static_cast<unsigned char>(0xAA));
-  EXPECT_EQ(stdc_leading_zeros(static_cast<unsigned short>(0U)),
-            static_cast<unsigned short>(0xAB));
-  EXPECT_EQ(stdc_leading_zeros(0U), static_cast<unsigned>(0xAC));
-  EXPECT_EQ(stdc_leading_zeros(0UL), static_cast<unsigned long>(0xAD));
-  EXPECT_EQ(stdc_leading_zeros(0ULL), static_cast<unsigned long long>(0xAF));
-}



More information about the libc-commits mailing list