Skip to content

Commit fb607c9

Browse files
authored
[MTE] add tests for stack tagging debug info (#93743)
These are equivalent to the tests in HWASan of the same name.
1 parent b12f81b commit fb607c9

File tree

4 files changed

+233
-0
lines changed

4 files changed

+233
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
; RUN: opt -aarch64-stack-tagging -stack-tagging-record-stack-history=instr -S -o - %s | FileCheck %s
2+
; RUN: opt --try-experimental-debuginfo-iterators -aarch64-stack-tagging -stack-tagging-record-stack-history=instr -S -o - %s | FileCheck %s
3+
4+
source_filename = "test.ll"
5+
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
6+
target triple = "aarch64--linux-android10000"
7+
8+
declare void @g(ptr, ptr, ptr, ptr, ptr, ptr)
9+
10+
; Function Attrs: sanitize_memtag
11+
define void @f() #0 !dbg !7 {
12+
entry:
13+
%nodebug0 = alloca ptr, align 8
14+
%nodebug1 = alloca ptr, align 8
15+
%nodebug2 = alloca ptr, align 8
16+
%nodebug3 = alloca ptr, align 8
17+
; CHECK: %a = alloca{{.*}} !DIAssignID ![[ID1:[0-9]+]]
18+
%a = alloca ptr, align 8, !DIAssignID !13
19+
; CHECK: @llvm.dbg.assign{{.*}} metadata ![[ID1]]{{.*}} !DIExpression(DW_OP_LLVM_tag_offset, 4)
20+
call void @llvm.dbg.assign(metadata i1 undef, metadata !14, metadata !DIExpression(), metadata !13, metadata ptr %a, metadata !DIExpression()), !dbg !15
21+
; CHECK: %b = alloca{{.*}} !DIAssignID ![[ID2:[0-9]+]]
22+
%b = alloca ptr, align 8, !DIAssignID !16
23+
; CHECK: @llvm.dbg.assign{{.*}} metadata ![[ID2]]{{.*}} !DIExpression(DW_OP_LLVM_tag_offset, 5)
24+
call void @llvm.dbg.assign(metadata i1 undef, metadata !17, metadata !DIExpression(), metadata !16, metadata ptr %b, metadata !DIExpression()), !dbg !15
25+
call void @g(ptr %nodebug0, ptr %nodebug1, ptr %nodebug2, ptr %nodebug3, ptr %a, ptr %b)
26+
ret void, !dbg !18
27+
}
28+
29+
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
30+
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
31+
32+
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
33+
declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #1
34+
35+
attributes #0 = { sanitize_memtag }
36+
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
37+
38+
!llvm.dbg.cu = !{!0}
39+
!llvm.module.flags = !{!3, !4, !5}
40+
!llvm.ident = !{!6}
41+
42+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
43+
!1 = !DIFile(filename: "x.c", directory: "/")
44+
!2 = !{}
45+
!3 = !{i32 2, !"Dwarf Version", i32 4}
46+
!4 = !{i32 2, !"Debug Info Version", i32 3}
47+
!5 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
48+
!6 = !{!"clang"}
49+
!7 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
50+
!8 = !DISubroutineType(types: !9)
51+
!9 = !{null, !10}
52+
!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
53+
!11 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !12)
54+
!12 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
55+
!13 = distinct !DIAssignID()
56+
!14 = !DILocalVariable(name: "a", scope: !7, file: !1, line: 1, type: !10)
57+
!15 = !DILocation(line: 0, scope: !7)
58+
!16 = distinct !DIAssignID()
59+
!17 = !DILocalVariable(name: "b", scope: !7, file: !1, line: 1, type: !10)
60+
!18 = !DILocation(line: 1, column: 37, scope: !7)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
; RUN: opt -aarch64-stack-tagging -stack-tagging-record-stack-history=instr -S -o - %s | FileCheck %s
2+
3+
;; Also test with RemoveDIs to verify that debug intrinsics immediately
4+
;; preceding an alloca (or other instruction of interest to stack tagging) will
5+
;; be correctly processed.
6+
; RUN: opt --try-experimental-debuginfo-iterators -aarch64-stack-tagging -stack-tagging-record-stack-history=instr -S -o - %s | FileCheck %s
7+
8+
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
9+
target triple = "aarch64--linux-android10000"
10+
11+
declare void @g(ptr, ptr, ptr, ptr, ptr, ptr)
12+
13+
define void @f() sanitize_memtag !dbg !6 {
14+
entry:
15+
%nodebug0 = alloca ptr
16+
%nodebug1 = alloca ptr
17+
%nodebug2 = alloca ptr
18+
%nodebug3 = alloca ptr
19+
%a = alloca ptr
20+
; CHECK: @llvm.dbg.declare{{.*}} !DIExpression(DW_OP_LLVM_tag_offset, 4)
21+
call void @llvm.dbg.declare(metadata ptr %a, metadata !12, metadata !DIExpression()), !dbg !14
22+
; CHECK: @llvm.dbg.declare{{.*}} !DIExpression(DW_OP_LLVM_tag_offset, 4)
23+
call void @llvm.dbg.declare(metadata ptr %a, metadata !12, metadata !DIExpression()), !dbg !14
24+
%b = alloca ptr
25+
; CHECK: @llvm.dbg.declare{{.*}} !DIExpression(DW_OP_LLVM_tag_offset, 5)
26+
call void @llvm.dbg.declare(metadata ptr %b, metadata !13, metadata !DIExpression()), !dbg !14
27+
; CHECK: @llvm.dbg.declare{{.*}} !DIExpression(DW_OP_LLVM_tag_offset, 5)
28+
call void @llvm.dbg.declare(metadata ptr %b, metadata !13, metadata !DIExpression()), !dbg !14
29+
call void @g(ptr %nodebug0, ptr %nodebug1, ptr %nodebug2, ptr %nodebug3, ptr %a, ptr %b)
30+
ret void, !dbg !15
31+
}
32+
33+
declare void @llvm.dbg.declare(metadata, metadata, metadata)
34+
35+
!llvm.dbg.cu = !{!0}
36+
!llvm.module.flags = !{!3, !4}
37+
!llvm.ident = !{!5}
38+
39+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
40+
!1 = !DIFile(filename: "x.c", directory: "/")
41+
!2 = !{}
42+
!3 = !{i32 2, !"Dwarf Version", i32 4}
43+
!4 = !{i32 2, !"Debug Info Version", i32 3}
44+
!5 = !{!"clang"}
45+
!6 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, scopeLine: 1, flags:
46+
DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
47+
!7 = !DISubroutineType(types: !8)
48+
!8 = !{null, !9}
49+
!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64)
50+
!10 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !11)
51+
!11 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
52+
!12 = !DILocalVariable(name: "a", scope: !6, file: !1, line: 1, type: !9)
53+
!13 = !DILocalVariable(name: "b", scope: !6, file: !1, line: 1, type: !9)
54+
!14 = !DILocation(line: 1, column: 29, scope: !6)
55+
!15 = !DILocation(line: 1, column: 37, scope: !6)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
; RUN: opt -aarch64-stack-tagging -stack-tagging-record-stack-history=instr -S -o - %s | FileCheck %s
2+
3+
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
4+
target triple = "aarch64-unknown-linux-android10000"
5+
6+
define dso_local void @f() sanitize_memtag !dbg !14 {
7+
%a1 = alloca i128, align 4
8+
%a2 = alloca i128, align 4
9+
; CHECK: call void @llvm.dbg.value(metadata i128 1, {{.*}}, metadata !DIExpression())
10+
call void @llvm.dbg.value(metadata i128 1, metadata !20, metadata !DIExpression()), !dbg !22
11+
store i128 1, ptr %a2, align 4, !dbg !23, !tbaa !24
12+
; CHECK: call void @llvm.dbg.value(metadata ptr %a1, {{.*}}, metadata !DIExpression(DW_OP_LLVM_tag_offset, 0, DW_OP_deref))
13+
call void @llvm.dbg.value(metadata ptr %a1, metadata !18, metadata !DIExpression(DW_OP_deref)), !dbg !22
14+
call void @use(ptr nonnull %a1), !dbg !28
15+
; CHECK: call void @llvm.dbg.value(metadata ptr %a2, {{.*}}, metadata !DIExpression(DW_OP_LLVM_tag_offset, 1, DW_OP_deref))
16+
call void @llvm.dbg.value(metadata ptr %a2, metadata !20, metadata !DIExpression(DW_OP_deref)), !dbg !22
17+
call void @use(ptr nonnull %a2), !dbg !29
18+
ret void, !dbg !30
19+
}
20+
21+
declare !dbg !5 void @use(ptr)
22+
23+
declare void @llvm.dbg.value(metadata, metadata, metadata)
24+
25+
!llvm.dbg.cu = !{!0}
26+
!llvm.module.flags = !{!8, !9, !10, !11, !12}
27+
!llvm.ident = !{!13}
28+
29+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 10.0.0 ([email protected]:llvm/llvm-project.git 5560dd08b99a0e8b0c55116376624e4f967caec5)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, nameTableKind: None)
30+
!1 = !DIFile(filename: "dbg.cc", directory: "/tmp")
31+
!2 = !{}
32+
!3 = !{!4, !5}
33+
!4 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
34+
!5 = !DISubprogram(name: "use", scope: !1, file: !1, line: 2, type: !6, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2)
35+
!6 = !DISubroutineType(types: !7)
36+
!7 = !{null, !4}
37+
!8 = !{i32 7, !"Dwarf Version", i32 4}
38+
!9 = !{i32 2, !"Debug Info Version", i32 3}
39+
!10 = !{i32 1, !"wchar_size", i32 4}
40+
!11 = !{i32 7, !"PIC Level", i32 2}
41+
!12 = !{i32 7, !"PIE Level", i32 2}
42+
!13 = !{!"clang version 10.0.0 ([email protected]:llvm/llvm-project.git 5560dd08b99a0e8b0c55116376624e4f967caec5)"}
43+
!14 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 4, type: !15, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !17)
44+
!15 = !DISubroutineType(types: !16)
45+
!16 = !{null}
46+
!17 = !{!18, !20}
47+
!18 = !DILocalVariable(name: "x", scope: !14, file: !1, line: 5, type: !19)
48+
!19 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
49+
!20 = !DILocalVariable(name: "y", scope: !14, file: !1, line: 5, type: !19)
50+
!21 = !DILocation(line: 5, column: 3, scope: !14)
51+
!22 = !DILocation(line: 0, scope: !14)
52+
!23 = !DILocation(line: 5, column: 10, scope: !14)
53+
!24 = !{!25, !25, i64 0}
54+
!25 = !{!"int", !26, i64 0}
55+
!26 = !{!"omnipotent char", !27, i64 0}
56+
!27 = !{!"Simple C++ TBAA"}
57+
!28 = !DILocation(line: 6, column: 3, scope: !14)
58+
!29 = !DILocation(line: 7, column: 3, scope: !14)
59+
!30 = !DILocation(line: 8, column: 1, scope: !14)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
; RUN: opt -aarch64-stack-tagging -stack-tagging-record-stack-history=instr -S -o - %s | FileCheck %s
2+
3+
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
4+
target triple = "aarch64-unknown-linux-android10000"
5+
6+
define dso_local void @f() sanitize_memtag !dbg !14 {
7+
%a1 = alloca i32, align 4
8+
%a2 = alloca i32, align 4
9+
; CHECK: call void @llvm.dbg.value(metadata i32 1, {{.*}}, metadata !DIExpression())
10+
call void @llvm.dbg.value(metadata i32 1, metadata !20, metadata !DIExpression()), !dbg !22
11+
store i32 1, ptr %a2, align 4, !dbg !23, !tbaa !24
12+
; CHECK: call void @llvm.dbg.value(metadata ptr %a1, {{.*}} metadata !DIExpression(DW_OP_LLVM_tag_offset, 0, DW_OP_deref))
13+
call void @llvm.dbg.value(metadata ptr %a1, metadata !18, metadata !DIExpression(DW_OP_deref)), !dbg !22
14+
call void @use(ptr nonnull %a1), !dbg !28
15+
; CHECK: call void @llvm.dbg.value(metadata ptr %a2, {{.*}} metadata !DIExpression(DW_OP_LLVM_tag_offset, 1, DW_OP_deref))
16+
call void @llvm.dbg.value(metadata ptr %a2, metadata !20, metadata !DIExpression(DW_OP_deref)), !dbg !22
17+
call void @use(ptr nonnull %a2), !dbg !29
18+
ret void, !dbg !30
19+
}
20+
21+
declare !dbg !5 void @use(ptr)
22+
23+
declare void @llvm.dbg.value(metadata, metadata, metadata)
24+
25+
!llvm.dbg.cu = !{!0}
26+
!llvm.module.flags = !{!8, !9, !10, !11, !12}
27+
!llvm.ident = !{!13}
28+
29+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 10.0.0 ([email protected]:llvm/llvm-project.git 5560dd08b99a0e8b0c55116376624e4f967caec5)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, nameTableKind: None)
30+
!1 = !DIFile(filename: "dbg.cc", directory: "/tmp")
31+
!2 = !{}
32+
!3 = !{!4, !5}
33+
!4 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
34+
!5 = !DISubprogram(name: "use", scope: !1, file: !1, line: 2, type: !6, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2)
35+
!6 = !DISubroutineType(types: !7)
36+
!7 = !{null, !4}
37+
!8 = !{i32 7, !"Dwarf Version", i32 4}
38+
!9 = !{i32 2, !"Debug Info Version", i32 3}
39+
!10 = !{i32 1, !"wchar_size", i32 4}
40+
!11 = !{i32 7, !"PIC Level", i32 2}
41+
!12 = !{i32 7, !"PIE Level", i32 2}
42+
!13 = !{!"clang version 10.0.0 ([email protected]:llvm/llvm-project.git 5560dd08b99a0e8b0c55116376624e4f967caec5)"}
43+
!14 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 4, type: !15, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !17)
44+
!15 = !DISubroutineType(types: !16)
45+
!16 = !{null}
46+
!17 = !{!18, !20}
47+
!18 = !DILocalVariable(name: "x", scope: !14, file: !1, line: 5, type: !19)
48+
!19 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
49+
!20 = !DILocalVariable(name: "y", scope: !14, file: !1, line: 5, type: !19)
50+
!21 = !DILocation(line: 5, column: 3, scope: !14)
51+
!22 = !DILocation(line: 0, scope: !14)
52+
!23 = !DILocation(line: 5, column: 10, scope: !14)
53+
!24 = !{!25, !25, i64 0}
54+
!25 = !{!"int", !26, i64 0}
55+
!26 = !{!"omnipotent char", !27, i64 0}
56+
!27 = !{!"Simple C++ TBAA"}
57+
!28 = !DILocation(line: 6, column: 3, scope: !14)
58+
!29 = !DILocation(line: 7, column: 3, scope: !14)
59+
!30 = !DILocation(line: 8, column: 1, scope: !14)

0 commit comments

Comments
 (0)