[llvm] Fix parsing out-of-order ValueInfos (PR #73239)

via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 23 05:09:04 PST 2023


https://github.com/eleviant created https://github.com/llvm/llvm-project/pull/73239

C++ class type info has two entries in summary index: gv and typeidCompatibleVTable, both sharing the same GUID. This causes value numbers being non-sequential

>From f0947ef1647f2fe411932d1b551ee7d405e75178 Mon Sep 17 00:00:00 2001
From: Evgeny Leviant <eleviant at accesssoftek.com>
Date: Thu, 23 Nov 2023 16:04:26 +0300
Subject: [PATCH] Fix parsing out-of-order ValueInfos

C++ class type info has two entries in summary index: gv and
typeidCompatibleVTable, both sharing the same GUID. This causes
value numbers being non-sequential
---
 llvm/lib/AsmParser/LLParser.cpp      |  2 +-
 llvm/test/Assembler/thinlto-typid.ll | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Assembler/thinlto-typid.ll

diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 2d2c1bf65311c01..8fb2d27630f1615 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -9775,7 +9775,7 @@ bool LLParser::parseGVReference(ValueInfo &VI, unsigned &GVId) {
 
   GVId = Lex.getUIntVal();
   // Check if we already have a VI for this GV
-  if (GVId < NumberedValueInfos.size()) {
+  if (GVId < NumberedValueInfos.size() && NumberedValueInfos[GVId]) {
     assert(NumberedValueInfos[GVId].getRef() != FwdVIRef);
     VI = NumberedValueInfos[GVId];
   } else
diff --git a/llvm/test/Assembler/thinlto-typid.ll b/llvm/test/Assembler/thinlto-typid.ll
new file mode 100644
index 000000000000000..e1a3ea9ca75be72
--- /dev/null
+++ b/llvm/test/Assembler/thinlto-typid.ll
@@ -0,0 +1,22 @@
+; RUN: llvm-as %s -o - | llvm-dis -o - | FileCheck %s
+
+; CHECK: ^[[NUM:[0-9]+]] = gv: {{.*}} "_ZTSN3FooE"
+; CHECK: ^[[NUM]] = typeidCompatibleVTable: {{.*}} "_ZTSN3FooE"
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+$_ZTSN3FooE = comdat any
+
+ at _ZTSN3FooE = linkonce_odr constant [7 x i8] c"N3FooE\00", comdat, align 1
+@"_ZTVN3FooE" = internal unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr null, ptr @"_Z3barv"] }, align 8
+
+define internal i32 @"_Z3barv"() {
+  ret i32 0
+}
+
+^0 = module: (path: "thinlto-typeid.ll", hash: (0, 0, 0, 0, 0))
+^1 = gv: (name: "_ZTVN3FooE", summaries: (variable: (module: ^0, flags: (linkage: internal, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 1, canAutoHide: 0), varFlags: (readonly: 1, writeonly: 0, constant: 1, vcall_visibility: 0), vTableFuncs: ((virtFunc: ^3, offset: 16)))))
+^4 = gv: (name: "_ZTSN3FooE", summaries: (variable: (module: ^0, flags: (linkage: linkonce_odr, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0, constant: 1))))
+^3 = gv: (name: "_Z3barv", summaries: (function: (module: ^0, flags: (linkage: internal, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 1, canAutoHide: 0), insts: 1, funcFlags: (readNone: 1, readOnly: 0, noRecurse: 1, returnDoesNotAlias: 0, noInline: 0, alwaysInline: 0, noUnwind: 1, mayThrow: 0, hasUnknownCall: 0, mustBeUnreachable: 0))))
+^4 = typeidCompatibleVTable: (name: "_ZTSN3FooE", summary: ((offset: 16, ^1)))



More information about the llvm-commits mailing list