1 // RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone -O0 \
2 // RUN: -emit-llvm -fexperimental-assignment-tracking=forced %s -o - \
3 // RUN: -disable-O0-optnone \
4 // RUN: | FileCheck %s
5
6 // Check that the (debug) codegen looks right with assignment tracking
7 // enabled. Each fragment that is written to should have a dbg.assign that has
8 // the DIAssignID of the write as an argument. The fragment offset and size
9 // should match the offset into the base storage and size of the store. Each of
10 // the scenarios below results in slightly different arguments generated for
11 // the memcpy.
12
13 // Test write a complete struct field only.
fragmentWhole()14 void fragmentWhole()
15 {
16 struct Record {
17 int num;
18 char ch;
19 };
20
21 Record dest;
22 char src = '\0';
23 __builtin_memcpy(&dest.ch, &src, sizeof(char));
24 }
25 // CHECK: call void @llvm.memcpy{{.+}}, !DIAssignID ![[memberID:[0-9]+]]
26 // CHECK-NEXT: #dbg_assign({{.*}}undef, !{{[0-9]+}}, !DIExpression(DW_OP_LLVM_fragment, 32, 8), ![[memberID]], ptr %ch, !DIExpression(),
27
28 // Write starting at a field and overlapping part of another.
fragmentWholeToPartial()29 void fragmentWholeToPartial()
30 {
31 struct Record {
32 int num1;
33 int num2;
34 };
35
36 Record dest;
37 char src[5]="\0\0\0\0";
38 __builtin_memcpy(&dest.num1, &src, 5);
39 }
40 // CHECK: call void @llvm.memcpy{{.+}}, !DIAssignID ![[exceed:[0-9]+]]
41 // CHECK-NEXT: #dbg_assign({{.*}}undef, !{{[0-9]+}}, !DIExpression(DW_OP_LLVM_fragment, 0, 40), ![[exceed]], ptr %num1, !DIExpression(),
42
43 // Write starting between fields.
fragmentPartialToWhole()44 void fragmentPartialToWhole()
45 {
46 struct record {
47 int num1;
48 int num2;
49 int num3;
50 };
51
52 record dest;
53 char src[5]="\0\0\0\0";
54 __builtin_memcpy((char*)&(dest.num2) + 3, &src, 5);
55 }
56 // CHECK: call void @llvm.memcpy{{.+}}, !DIAssignID ![[addendID:[0-9]+]]
57 // CHECK-NEXT: #dbg_assign({{.*}}undef, !{{.*}}, !DIExpression(DW_OP_LLVM_fragment, 56, 40), ![[addendID]], ptr %add.ptr, !DIExpression(),
58