Skip to content

[libc] remove stdc_leading_zeros for now #79915

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

Closed
wants to merge 1 commit into from

Conversation

nickdesaulniers
Copy link
Member

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.

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.
@llvmbot llvmbot added the libc label Jan 30, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 30, 2024

@llvm/pr-subscribers-libc

Author: Nick Desaulniers (nickdesaulniers)

Changes

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&lt;unsigned long long&gt;(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.


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

4 Files Affected:

  • (removed) libc/include/llvm-libc-macros/stdbit-macros.h (-20)
  • (modified) libc/include/stdbit.h.def (-1)
  • (modified) libc/test/include/CMakeLists.txt (-23)
  • (removed) libc/test/include/stdbit_test.cpp (-35)
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 febe95fe0a1e3c..00000000000000
--- 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 cb79ac1caf049f..10e1e8153a573f 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 ecc32380c596e0..183e7ecde719e5 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 d20005cc31afa0..00000000000000
--- 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));
-}

@nickdesaulniers
Copy link
Member Author

actually, I think I prefer #79917.

@nickdesaulniers nickdesaulniers deleted the remove_stdbit branch January 30, 2024 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants