Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGen / assignment-tracking / memcpy-fragment.cpp
blob126bc8f54eb437d2a1414176a963daaac2d97e09
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
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.
13 // Test write a complete struct field only.
14 void fragmentWhole()
16 struct Record {
17 int num;
18 char ch;
21 Record dest;
22 char src = '\0';
23 __builtin_memcpy(&dest.ch, &src, sizeof(char));
25 // CHECK: call void @llvm.memcpy{{.+}}, !DIAssignID ![[memberID:[0-9]+]]
26 // CHECK-NEXT: call void @llvm.dbg.assign(metadata{{.*}}undef, metadata !{{[0-9]+}}, metadata !DIExpression(DW_OP_LLVM_fragment, 32, 8), metadata ![[memberID]], metadata ptr %ch, metadata !DIExpression())
28 // Write starting at a field and overlapping part of another.
29 void fragmentWholeToPartial()
31 struct Record {
32 int num1;
33 int num2;
36 Record dest;
37 char src[5]="\0\0\0\0";
38 __builtin_memcpy(&dest.num1, &src, 5);
40 // CHECK: call void @llvm.memcpy{{.+}}, !DIAssignID ![[exceed:[0-9]+]]
41 // CHECK-NEXT: call void @llvm.dbg.assign(metadata{{.*}}undef, metadata !{{[0-9]+}}, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 40), metadata ![[exceed]], metadata ptr %num1, metadata !DIExpression())
43 // Write starting between fields.
44 void fragmentPartialToWhole()
46 struct record {
47 int num1;
48 int num2;
49 int num3;
52 record dest;
53 char src[5]="\0\0\0\0";
54 __builtin_memcpy((char*)&(dest.num2) + 3, &src, 5);
56 // CHECK: call void @llvm.memcpy{{.+}}, !DIAssignID ![[addendID:[0-9]+]]
57 // CHECK-NEXT: call void @llvm.dbg.assign(metadata{{.*}}undef, metadata !{{.*}}, metadata !DIExpression(DW_OP_LLVM_fragment, 56, 40), metadata ![[addendID]], metadata ptr %add.ptr, metadata !DIExpression())