[llvm] d9e778d - [NFC] Use int underlying type for CodeGenOpt::Level

Scott Linder via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 23 15:32:21 PST 2023


Author: Scott Linder
Date: 2023-01-23T23:32:10Z
New Revision: d9e778dfa7df1d100865a0cfe198651aff3b839c

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

LOG: [NFC] Use int underlying type for CodeGenOpt::Level

In practice the change from an unspecified underlying type to uint8_t in
25c0ea2a5370813f46686918a84e0de27e107d08 means some builds break due to
ambiguity resolving operator<< on ostreams (I assume because they define
uint8_t differently).

There were also valid points raised on the review saying that we can
just use int here anyway. Pinning it to any type removes the potential
for UB when constructing it, and int is the de-facto default.

Added: 
    

Modified: 
    llvm/include/llvm/Support/CodeGen.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/CodeGen.h b/llvm/include/llvm/Support/CodeGen.h
index 9c557859d46f..7f95bcb9e9d7 100644
--- a/llvm/include/llvm/Support/CodeGen.h
+++ b/llvm/include/llvm/Support/CodeGen.h
@@ -52,7 +52,7 @@ namespace llvm {
 
   namespace CodeGenOpt {
   /// Type for the unique integer IDs of code generation optimization levels.
-  using IDType = uint8_t;
+  using IDType = int;
   /// Code generation optimization level.
   enum Level : IDType {
     None = 0,      ///< -O0
@@ -64,14 +64,10 @@ namespace llvm {
   ///
   /// Returns std::nullopt if \p ID is invalid.
   inline std::optional<Level> getLevel(IDType ID) {
-    if (ID > 3)
+    if (ID < 0 || ID > 3)
       return std::nullopt;
     return static_cast<Level>(ID);
   }
-  /// Get the integer \c ID of \p Level.
-  inline IDType getID(CodeGenOpt::Level Level) {
-    return static_cast<IDType>(Level);
-  }
   /// Parse \p C as a single digit integer ID and get matching \c Level.
   ///
   /// Returns std::nullopt if the input is not a valid digit or not a valid ID.


        


More information about the llvm-commits mailing list