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

Wang Pengcheng via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 25 04:32:28 PDT 2023


https://github.com/wangpc-pp updated https://github.com/llvm/llvm-project/pull/66867

>From a09b156e5d3d8e08c08af99c60c90a4df0653065 Mon Sep 17 00:00:00 2001
From: wangpc <wangpengcheng.pp at bytedance.com>
Date: Wed, 20 Sep 2023 15:06:12 +0800
Subject: [PATCH] [TableGen] Fix wrong bits output in GenericTable

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.

I split this PR into two commits to show the difference.
---
 llvm/test/TableGen/generic-tables.td           | 8 ++++----
 llvm/utils/TableGen/SearchableTableEmitter.cpp | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

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