Skip to content

Commit 37a73d5

Browse files
[MemProf] Update metadata verification for a single string tag (#172543)
The memprof metadata verifier supported multiple string tags, but in reality, the other code (e.g. addCallStack) only supports a single such tag. Update the verifier to reflect that limitation, and the associated tests. Fixes #157217
1 parent 6c51c17 commit 37a73d5

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

llvm/lib/IR/Verifier.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5340,19 +5340,12 @@ void Verifier::visitMemProfMetadata(Instruction &I, MDNode *MD) {
53405340
MDNode *StackMD = dyn_cast<MDNode>(MIB->getOperand(0));
53415341
visitCallStackMetadata(StackMD);
53425342

5343-
// The next set of 1 or more operands should be MDString.
5344-
unsigned I = 1;
5345-
for (; I < MIB->getNumOperands(); ++I) {
5346-
if (!isa<MDString>(MIB->getOperand(I))) {
5347-
Check(I > 1,
5348-
"!memprof MemInfoBlock second operand should be an MDString",
5349-
MIB);
5350-
break;
5351-
}
5352-
}
5343+
// The second MIB operand should be MDString.
5344+
Check(isa<MDString>(MIB->getOperand(1)),
5345+
"!memprof MemInfoBlock second operand should be an MDString", MIB);
53535346

53545347
// Any remaining should be MDNode that are pairs of integers
5355-
for (; I < MIB->getNumOperands(); ++I) {
5348+
for (unsigned I = 2; I < MIB->getNumOperands(); ++I) {
53565349
MDNode *OpNode = dyn_cast<MDNode>(MIB->getOperand(I));
53575350
Check(OpNode, "Not all !memprof MemInfoBlock operands 2 to N are MDNode",
53585351
MIB);

llvm/test/Verifier/memprof-metadata-bad.ll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ entry:
88
%call3 = call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40), !memprof !3
99
%call4 = call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40), !memprof !5
1010
%call5 = call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40), !memprof !7, !callsite !9
11+
%call6 = call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40), !memprof !12
12+
%call7 = call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40), !memprof !15
1113
ret ptr %call5
1214
}
1315

@@ -45,10 +47,18 @@ declare dso_local noalias noundef ptr @malloc(i64 noundef)
4547
; CHECK: call stack metadata should have at least 1 operand
4648
; CHECK: Not all !memprof MemInfoBlock operands 2 to N are MDNode
4749
!8 = !{!0, !"default", i64 0, i64 5}
50+
!12 = !{!13}
51+
; CHECK: Not all !memprof MemInfoBlock operands 2 to N are MDNode
52+
!13 = !{!14, !"default", !"tag"}
53+
!15 = !{!16}
54+
; CHECK: Not all !memprof MemInfoBlock operands 2 to N are MDNode with 2 operands
55+
!16 = !{!14, !"default", !17}
56+
!17 = !{i64 789}
4857
!9 = !{i64 123}
4958
; CHECK: call stack metadata operand should be constant integer
5059
!10 = !{!"wrongtype"}
5160
!11 = !{i64 789, i64 678}
61+
!14 = !{i64 234}
5262

5363
; Errors from annotating incorrect instruction type in @wronginsttype.
5464
; CHECK: !memprof metadata should only exist on calls

llvm/test/Verifier/memprof-metadata-good.ll

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ entry:
2222
declare dso_local noalias noundef ptr @malloc(i64 noundef)
2323

2424
!0 = !{!1, !3}
25-
; !memprof metadata should be able to support an arbitrary list of string tags.
26-
!1 = !{!2, !"default", !"tag2"}
25+
; !memprof metadata can have a single string tag, followed by an arbitrary
26+
; list of MDNodes. The MDNodes should each be a pair
27+
!1 = !{!2, !"default", !8, !9}
2728
!2 = !{i64 123, i64 456}
28-
!3 = !{!4, !"cold", !"tag3", !"tag4"}
29+
!3 = !{!4, !"cold", !10}
2930
!4 = !{i64 123, i64 789, i64 678}
3031
!5 = !{i64 123}
3132
!6 = !{i64 456}
3233
; Inlined callsites will have more than one call stack id.
3334
!7 = !{i64 789, i64 678}
35+
!8 = !{i64 891, i64 100}
36+
!9 = !{i64 912, i64 200}
37+
!10 = !{i64 1234, i64 300}

0 commit comments

Comments
 (0)