[llvm] [Statepoint][NFC] Use uint16_t and add an assert (PR #78717)

Danila Malyutin via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 19 06:49:07 PST 2024


https://github.com/danilaml created https://github.com/llvm/llvm-project/pull/78717

Use a fixed width integer type and assert that DwarRegNum fits the 16 bits.

This is a follow up to review comments on #78600.

>From 4a7dbafeef5e1ddded8bd0af737d4a176f79daad Mon Sep 17 00:00:00 2001
From: Danila Malyutin <dmalyutin at azul.com>
Date: Fri, 19 Jan 2024 17:39:48 +0400
Subject: [PATCH] [Statepoint][NFC] Use uint16_t and add an assert

Use a fixed width integer type and assert that DwarRegNum fits the 16 bits.
---
 llvm/include/llvm/CodeGen/StackMaps.h | 18 ++++++++----------
 llvm/lib/CodeGen/StackMaps.cpp        |  2 +-
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/llvm/include/llvm/CodeGen/StackMaps.h b/llvm/include/llvm/CodeGen/StackMaps.h
index ca5dfa5666003c..578020ca5501a0 100644
--- a/llvm/include/llvm/CodeGen/StackMaps.h
+++ b/llvm/include/llvm/CodeGen/StackMaps.h
@@ -259,7 +259,7 @@ class StatepointOpers {
 class StackMaps {
 public:
   struct Location {
-    enum LocationType : unsigned short {
+    enum LocationType : uint16_t {
       Unprocessed,
       Register,
       Direct,
@@ -268,24 +268,22 @@ class StackMaps {
       ConstantIndex
     };
     LocationType Type = Unprocessed;
-    unsigned short Size = 0;
-    unsigned short Reg = 0;
+    uint16_t Size = 0;
+    uint16_t Reg = 0;
     int32_t Offset = 0;
 
     Location() = default;
-    Location(LocationType Type, unsigned short Size, unsigned short Reg,
-             int32_t Offset)
+    Location(LocationType Type, uint16_t Size, uint16_t Reg, int32_t Offset)
         : Type(Type), Size(Size), Reg(Reg), Offset(Offset) {}
   };
 
   struct LiveOutReg {
-    unsigned short Reg = 0;
-    unsigned short DwarfRegNum = 0;
-    unsigned short Size = 0;
+    uint16_t Reg = 0;
+    uint16_t DwarfRegNum = 0;
+    uint16_t Size = 0;
 
     LiveOutReg() = default;
-    LiveOutReg(unsigned short Reg, unsigned short DwarfRegNum,
-               unsigned short Size)
+    LiveOutReg(uint16_t Reg, uint16_t DwarfRegNum, uint16_t Size)
         : Reg(Reg), DwarfRegNum(DwarfRegNum), Size(Size) {}
   };
 
diff --git a/llvm/lib/CodeGen/StackMaps.cpp b/llvm/lib/CodeGen/StackMaps.cpp
index f45bcaf16ab707..90aa93e442cf36 100644
--- a/llvm/lib/CodeGen/StackMaps.cpp
+++ b/llvm/lib/CodeGen/StackMaps.cpp
@@ -200,7 +200,7 @@ static unsigned getDwarfRegNum(unsigned Reg, const TargetRegisterInfo *TRI) {
       break;
   }
 
-  assert(RegNum >= 0 && "Invalid Dwarf register number.");
+  assert(RegNum >= 0 && isUInt<16>(RegNum) && "Invalid Dwarf register number.");
   return (unsigned)RegNum;
 }
 



More information about the llvm-commits mailing list