Skip to content

Commit 3cd66f8

Browse files
Add test for iterating over MDNode operands when they are empty
With e851278 the for loop that iterates over MDNode operands was changed to a range-based for loop. This change surfaces a bug where if the result of MD->operands() is an ArrayRef that has a size of 0, then iterating over that ArrayRef leads to a segmentation fault, due to accessing invalid addresses. This was reverted with 6ce03ff but this test should be added to test that codepath in the future.
1 parent 6ce03ff commit 3cd66f8

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; RUN: llvm-as -disable-output %s
2+
%"class.llvm::StringRef" = type { ptr, i64 }
3+
define internal void @_ZL30tokenizeWindowsCommandLineImplN4llvm9StringRefERNS_11StringSaverENS_12function_refIFvS0_EEEbNS3_IFvvEEEb() !dbg !12 {
4+
%7 = alloca %"class.llvm::StringRef", align 8
5+
%21 = call noundef i64 @_ZNK4llvm9StringRef4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %7)
6+
br label %22
7+
br label %22, !llvm.loop !284 ; This instruction has loop metadata but no operands and should not result in a segmentation fault in the verifier.
8+
}
9+
define linkonce_odr noundef i64 @_ZNK4llvm9StringRef4sizeEv() align 2 !dbg !340 {
10+
%2 = alloca ptr, align 8
11+
%3 = load ptr, ptr %2, align 8
12+
%4 = getelementptr inbounds %"class.llvm::StringRef", ptr %3
13+
%5 = load i64, ptr %4
14+
ret i64 %5
15+
}
16+
!llvm.module.flags = !{!2, !6}
17+
!llvm.dbg.cu = !{!7}
18+
!2 = !{i32 2, !"Debug Info Version", i32 3}
19+
!6 = !{i32 7, !"frame-pointer", i32 1}
20+
!7 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !8, sdk: "MacOSX14.0.sdk")
21+
!8 = !DIFile(filename: "file.cpp", directory: "/Users/Dev", checksumkind: CSK_MD5, checksum: "ed7ae158f20f7914bc5fb843291e80da")
22+
!12 = distinct !DISubprogram(unit: !7, retainedNodes: !36)
23+
!36 = !{}
24+
!284 = distinct !{}
25+
!340 = distinct !DISubprogram(unit: !7, retainedNodes: !36)

0 commit comments

Comments
 (0)