Skip to content

Commit 48e0a6f

Browse files
committed
[DXILBitcodeWriter] Don't create a new abbrev per MDString
We were running out of abbrevs and crashing if there were more than 20 something strings in metadata, which turned out to be a bug where we created an abbrev every time we emitted a string rather than just one for the string table. Differential Revision: https://reviews.llvm.org/D158440
1 parent 77596e6 commit 48e0a6f

File tree

2 files changed

+80
-2
lines changed

2 files changed

+80
-2
lines changed

llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -1766,14 +1766,18 @@ unsigned DXILBitcodeWriter::createMetadataStringsAbbrev() {
17661766

17671767
void DXILBitcodeWriter::writeMetadataStrings(
17681768
ArrayRef<const Metadata *> Strings, SmallVectorImpl<uint64_t> &Record) {
1769+
if (Strings.empty())
1770+
return;
1771+
1772+
unsigned MDSAbbrev = createMetadataStringsAbbrev();
1773+
17691774
for (const Metadata *MD : Strings) {
17701775
const MDString *MDS = cast<MDString>(MD);
17711776
// Code: [strchar x N]
17721777
Record.append(MDS->bytes_begin(), MDS->bytes_end());
17731778

17741779
// Emit the finished record.
1775-
Stream.EmitRecord(bitc::METADATA_STRING_OLD, Record,
1776-
createMetadataStringsAbbrev());
1780+
Stream.EmitRecord(bitc::METADATA_STRING_OLD, Record, MDSAbbrev);
17771781
Record.clear();
17781782
}
17791783
}
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
; RUN: llc --filetype=obj %s -o - | dxil-dis | FileCheck %s
2+
; Make sure that DXILBitcodeWriter can handle more than 20 or so strings
3+
; without crashing.
4+
5+
target triple = "dxil-unknown-shadermodel6.7-library"
6+
7+
!llvm.too_many_strings = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27, !28, !29, !30, !31}
8+
9+
!0 = !{!"String 0"}
10+
!1 = !{!"String 1"}
11+
!2 = !{!"String 2"}
12+
!3 = !{!"String 3"}
13+
!4 = !{!"String 4"}
14+
!5 = !{!"String 5"}
15+
!6 = !{!"String 6"}
16+
!7 = !{!"String 7"}
17+
!8 = !{!"String 8"}
18+
!9 = !{!"String 9"}
19+
!10 = !{!"String 10"}
20+
!11 = !{!"String 11"}
21+
!12 = !{!"String 12"}
22+
!13 = !{!"String 13"}
23+
!14 = !{!"String 14"}
24+
!15 = !{!"String 15"}
25+
!16 = !{!"String 16"}
26+
!17 = !{!"String 17"}
27+
!18 = !{!"String 18"}
28+
!19 = !{!"String 19"}
29+
!20 = !{!"String 20"}
30+
!21 = !{!"String 21"}
31+
!22 = !{!"String 22"}
32+
!23 = !{!"String 23"}
33+
!24 = !{!"String 24"}
34+
!25 = !{!"String 25"}
35+
!26 = !{!"String 26"}
36+
!27 = !{!"String 27"}
37+
!28 = !{!"String 28"}
38+
!29 = !{!"String 29"}
39+
!30 = !{!"String 30"}
40+
!31 = !{!"String 31"}
41+
42+
; CHECK: !llvm.too_many_strings = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27, !28, !29, !30, !31}
43+
; CHECK: !0 = !{!"String 0"}
44+
; CHECK: !1 = !{!"String 1"}
45+
; CHECK: !2 = !{!"String 2"}
46+
; CHECK: !3 = !{!"String 3"}
47+
; CHECK: !4 = !{!"String 4"}
48+
; CHECK: !5 = !{!"String 5"}
49+
; CHECK: !6 = !{!"String 6"}
50+
; CHECK: !7 = !{!"String 7"}
51+
; CHECK: !8 = !{!"String 8"}
52+
; CHECK: !9 = !{!"String 9"}
53+
; CHECK: !10 = !{!"String 10"}
54+
; CHECK: !11 = !{!"String 11"}
55+
; CHECK: !12 = !{!"String 12"}
56+
; CHECK: !13 = !{!"String 13"}
57+
; CHECK: !14 = !{!"String 14"}
58+
; CHECK: !15 = !{!"String 15"}
59+
; CHECK: !16 = !{!"String 16"}
60+
; CHECK: !17 = !{!"String 17"}
61+
; CHECK: !18 = !{!"String 18"}
62+
; CHECK: !19 = !{!"String 19"}
63+
; CHECK: !20 = !{!"String 20"}
64+
; CHECK: !21 = !{!"String 21"}
65+
; CHECK: !22 = !{!"String 22"}
66+
; CHECK: !23 = !{!"String 23"}
67+
; CHECK: !24 = !{!"String 24"}
68+
; CHECK: !25 = !{!"String 25"}
69+
; CHECK: !26 = !{!"String 26"}
70+
; CHECK: !27 = !{!"String 27"}
71+
; CHECK: !28 = !{!"String 28"}
72+
; CHECK: !29 = !{!"String 29"}
73+
; CHECK: !30 = !{!"String 30"}
74+
; CHECK: !31 = !{!"String 31"}

0 commit comments

Comments
 (0)