[llvm] a433592 - [TableGen] Fix wrong bits output in GenericTable (#66867)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 25 04:33:03 PDT 2023


Author: Wang Pengcheng
Date: 2023-09-25T19:32:59+08:00
New Revision: a433592524f6d7a469023d55757caaf6bf175a26

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

LOG: [TableGen] Fix wrong bits output in GenericTable (#66867)

We used to return `int` in `getAsInt`, while `IntInit::getValue`
returns `int64_t` and `utohexstr` needs `uint64_t`. The casting
causes the wrong hex value when printing bits value.

Added: 
    

Modified: 
    llvm/test/TableGen/generic-tables.td
    llvm/utils/TableGen/SearchableTableEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/TableGen/generic-tables.td b/llvm/test/TableGen/generic-tables.td
index 2528448f732c67b..003b53209346017 100644
--- a/llvm/test/TableGen/generic-tables.td
+++ b/llvm/test/TableGen/generic-tables.td
@@ -25,10 +25,10 @@ include "llvm/TableGen/SearchableTable.td"
 // CHECK-LABEL: GET_ATable_IMPL
 // CHECK: constexpr AEntry ATable[] = {
 // CHECK-NOT:   { "aaa"
-// CHECK:       { "baz", 0x2, 0x6, 0x0 },
-// CHECK:       { "foo", 0x4, 0x4, 0x0 },
-// CHECK:       { "foobar", 0x4, 0x5, 0x0 },
-// CHECK:       { "bar", 0x5, 0x3, 0x0 },
+// CHECK:       { "baz", 0x2, 0x6, 0xFFFFFFFF00000000 },
+// CHECK:       { "foo", 0x4, 0x4, 0x100000000 },
+// CHECK:       { "foobar", 0x4, 0x5, 0x100000000 },
+// CHECK:       { "bar", 0x5, 0x3, 0x100000000 },
 // CHECK: };
 
 // CHECK: const AEntry *lookupATableByValues(uint8_t Val1, uint16_t Val2) {

diff  --git a/llvm/utils/TableGen/SearchableTableEmitter.cpp b/llvm/utils/TableGen/SearchableTableEmitter.cpp
index ee1af0ec70df08b..9987d1ec73d9f4a 100644
--- a/llvm/utils/TableGen/SearchableTableEmitter.cpp
+++ b/llvm/utils/TableGen/SearchableTableEmitter.cpp
@@ -31,12 +31,12 @@ using namespace llvm;
 
 namespace {
 
-int getAsInt(Init *B) {
+int64_t getAsInt(Init *B) {
   return cast<IntInit>(
              B->convertInitializerTo(IntRecTy::get(B->getRecordKeeper())))
       ->getValue();
 }
-int getInt(Record *R, StringRef Field) {
+int64_t getInt(Record *R, StringRef Field) {
   return getAsInt(R->getValueInit(Field));
 }
 


        


More information about the llvm-commits mailing list