Skip to content

Commit

Permalink
[libc] Fix definition and use of LIBC_INLINE macro
Browse files Browse the repository at this point in the history
LIBC_INLINE was doubly defined in two headers.  Define it only in
one place. Also update a few uses to make sure it's always placed
where a function attribute is valid and is used consistently on
every declaration of the same function in case the attributes used
in its definition must match on declarations and definitions.

Reviewed By: abrachet

Differential Revision: https://reviews.llvm.org/D150731
  • Loading branch information
frobtech committed May 16, 2023
1 parent ede83e0 commit 2c874d2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions libc/src/__support/endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ namespace internal {
template <unsigned ORDER> struct Endian {
static constexpr const bool IS_LITTLE = ORDER == __ORDER_LITTLE_ENDIAN__;
static constexpr const bool IS_BIG = ORDER == __ORDER_BIG_ENDIAN__;
template <typename T> static T to_big_endian(T value);
template <typename T> static T to_little_endian(T value);
template <typename T> LIBC_INLINE static T to_big_endian(T value);
template <typename T> LIBC_INLINE static T to_little_endian(T value);
};

// Little Endian specializations
Expand Down
2 changes: 0 additions & 2 deletions libc/src/__support/macros/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#ifndef LLVM_LIBC_SUPPORT_MACROS_CONFIG_H
#define LLVM_LIBC_SUPPORT_MACROS_CONFIG_H

#define LIBC_INLINE inline

// LIBC_HAS_BUILTIN()
//
// Checks whether the compiler supports a Clang Feature Checking Macro, and if
Expand Down
3 changes: 2 additions & 1 deletion libc/src/__support/macros/optimization.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
#ifndef LLVM_LIBC_SRC_SUPPORT_MACROS_OPTIMIZATION_H
#define LLVM_LIBC_SRC_SUPPORT_MACROS_OPTIMIZATION_H

#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/__support/macros/config.h" // LIBC_HAS_BUILTIN
#include "src/__support/macros/properties/compiler.h" // LIBC_COMPILER_IS_CLANG

// We use a template to implement likely/unlikely to make sure that we don't
// accidentally pass an integer.
namespace __llvm_libc::details {
template <typename T>
constexpr LIBC_INLINE bool expects_bool_condition(T value, T expected) {
LIBC_INLINE constexpr bool expects_bool_condition(T value, T expected) {
return __builtin_expect(value, expected);
}
} // namespace __llvm_libc::details
Expand Down

0 comments on commit 2c874d2

Please sign in to comment.