[libc-commits] [libc] 640ed21 - [libc][NFC] Add noreturn and constexpr qualifiers where appropriate

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Wed Jul 28 21:50:17 PDT 2021


Author: Alfonso Gregory
Date: 2021-07-29T04:50:05Z
New Revision: 640ed21cceb28ddb3a9779fdfa11a4c4d97e29df

URL: https://github.com/llvm/llvm-project/commit/640ed21cceb28ddb3a9779fdfa11a4c4d97e29df
DIFF: https://github.com/llvm/llvm-project/commit/640ed21cceb28ddb3a9779fdfa11a4c4d97e29df.diff

LOG: [libc][NFC] Add noreturn and constexpr qualifiers where appropriate

These functions make it clear to the compiler and user what the intended
behavior is so llvm can make them go as fast as possible.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106807

Added: 
    

Modified: 
    libc/src/__support/integer_operations.h
    libc/src/ctype/ctype_utils.h
    libc/utils/HdrGen/Command.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/integer_operations.h b/libc/src/__support/integer_operations.h
index 733fb7ed9ce91..4c13bb86e2d87 100644
--- a/libc/src/__support/integer_operations.h
+++ b/libc/src/__support/integer_operations.h
@@ -14,10 +14,9 @@
 namespace __llvm_libc {
 
 template <typename T>
-static inline cpp::EnableIfType<cpp::IsIntegral<T>::Value, T> integerAbs(T n) {
-  if (n < 0)
-    return -n;
-  return n;
+static constexpr cpp::EnableIfType<cpp::IsIntegral<T>::Value, T>
+integerAbs(T n) {
+  return (n < 0) ? -n : n;
 }
 
 } // namespace __llvm_libc

diff  --git a/libc/src/ctype/ctype_utils.h b/libc/src/ctype/ctype_utils.h
index 6238bd32d9f8c..b8457227aa832 100644
--- a/libc/src/ctype/ctype_utils.h
+++ b/libc/src/ctype/ctype_utils.h
@@ -18,17 +18,17 @@ namespace internal {
 // of a function call by inlining them.
 // ------------------------------------------------------
 
-static inline int isalpha(unsigned ch) { return (ch | 32) - 'a' < 26; }
+static constexpr int isalpha(unsigned ch) { return (ch | 32) - 'a' < 26; }
 
-static inline int isdigit(unsigned ch) { return (ch - '0') < 10; }
+static constexpr int isdigit(unsigned ch) { return (ch - '0') < 10; }
 
-static inline int isalnum(unsigned ch) { return isalpha(ch) || isdigit(ch); }
+static constexpr int isalnum(unsigned ch) { return isalpha(ch) || isdigit(ch); }
 
-static inline int isgraph(unsigned ch) { return 0x20 < ch && ch < 0x7f; }
+static constexpr int isgraph(unsigned ch) { return 0x20 < ch && ch < 0x7f; }
 
-static inline int islower(unsigned ch) { return (ch - 'a') < 26; }
+static constexpr int islower(unsigned ch) { return (ch - 'a') < 26; }
 
-static inline int isupper(unsigned ch) { return (ch - 'A') < 26; }
+static constexpr int isupper(unsigned ch) { return (ch - 'A') < 26; }
 
 } // namespace internal
 } // namespace __llvm_libc

diff  --git a/libc/utils/HdrGen/Command.h b/libc/utils/HdrGen/Command.h
index edc40298d97d9..895f472c3ad32 100644
--- a/libc/utils/HdrGen/Command.h
+++ b/libc/utils/HdrGen/Command.h
@@ -36,7 +36,7 @@ class Command {
   public:
     ErrorReporter(llvm::SMLoc L, llvm::SourceMgr &SM) : Loc(L), SrcMgr(SM) {}
 
-    void printFatalError(llvm::Twine Msg) const {
+    [[noreturn]] void printFatalError(llvm::Twine Msg) const {
       SrcMgr.PrintMessage(Loc, llvm::SourceMgr::DK_Error, Msg);
       std::exit(1);
     }


        


More information about the libc-commits mailing list