brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.4 KiB · 433f900 Raw
100 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-linux-gnu  -gkey-instructions %s -debug-info-kind=line-tables-only -emit-llvm -o - \2// RUN: | FileCheck %s3 4// Perennial question: should the inc be its own source atom or not5// (currently it is).6 7// FIXME: See do.c and while.c regarding cmp and cond br groups.8 9// The stores in the setup (stores to __RANGE1, __BEGIN1, __END1) are all10// marked as Key. Unclear whether that's desirable. Keep for now as that's11// least risky (at worst it introduces an unnecessary step while debugging,12// as opposed to potentially losing one we want).13 14// Check the conditional branch (and the condition) in FOR_COND and15// unconditional branch in FOR_BODY are Key Instructions.16 17struct Range {18    int *begin();19    int *end();20} r;21 22// CHECK-LABEL: define dso_local void @_Z1av(23// CHECK-SAME: ) #[[ATTR0:[0-9]+]] !dbg [[DBG10:![0-9]+]] {24// CHECK-NEXT:  [[ENTRY:.*:]]25// CHECK-NEXT:    [[__RANGE1:%.*]] = alloca ptr, align 826// CHECK-NEXT:    [[__BEGIN1:%.*]] = alloca ptr, align 827// CHECK-NEXT:    [[__END1:%.*]] = alloca ptr, align 828// CHECK-NEXT:    [[I:%.*]] = alloca i32, align 429// CHECK-NEXT:    store ptr @r, ptr [[__RANGE1]], align 8, !dbg [[DBG14:![0-9]+]]30// CHECK-NEXT:    [[CALL:%.*]] = call noundef ptr @_ZN5Range5beginEv(ptr noundef nonnull align 1 dereferenceable(1) @r), !dbg [[DBG15:![0-9]+]]31// CHECK-NEXT:    store ptr [[CALL]], ptr [[__BEGIN1]], align 8, !dbg [[DBG16:![0-9]+]]32// CHECK-NEXT:    [[CALL1:%.*]] = call noundef ptr @_ZN5Range3endEv(ptr noundef nonnull align 1 dereferenceable(1) @r), !dbg [[DBG17:![0-9]+]]33// CHECK-NEXT:    store ptr [[CALL1]], ptr [[__END1]], align 8, !dbg [[DBG18:![0-9]+]]34// CHECK-NEXT:    br label %[[FOR_COND:.*]], !dbg [[DBG19:![0-9]+]]35// CHECK:       [[FOR_COND]]:36// CHECK-NEXT:    [[TMP0:%.*]] = load ptr, ptr [[__BEGIN1]], align 8, !dbg [[DBG19]]37// CHECK-NEXT:    [[TMP1:%.*]] = load ptr, ptr [[__END1]], align 8, !dbg [[DBG19]]38// CHECK-NEXT:    [[CMP:%.*]] = icmp ne ptr [[TMP0]], [[TMP1]], !dbg [[DBG20:![0-9]+]]39// CHECK-NEXT:    br i1 [[CMP]], label %[[FOR_BODY:.*]], label %[[FOR_END:.*]], !dbg [[DBG21:![0-9]+]]40// CHECK:       [[FOR_BODY]]:41// CHECK-NEXT:    [[TMP2:%.*]] = load ptr, ptr [[__BEGIN1]], align 8, !dbg [[DBG19]]42// CHECK-NEXT:    [[TMP3:%.*]] = load i32, ptr [[TMP2]], align 4, !dbg [[DBG22:![0-9]+]]43// CHECK-NEXT:    store i32 [[TMP3]], ptr [[I]], align 4, !dbg [[DBG23:![0-9]+]]44// CHECK-NEXT:    br label %[[FOR_INC:.*]], !dbg [[DBG24:![0-9]+]]45// CHECK:       [[FOR_INC]]:46// CHECK-NEXT:    [[TMP4:%.*]] = load ptr, ptr [[__BEGIN1]], align 8, !dbg [[DBG19]]47// CHECK-NEXT:    [[INCDEC_PTR:%.*]] = getelementptr inbounds nuw i32, ptr [[TMP4]], i32 1, !dbg [[DBG25:![0-9]+]]48// CHECK-NEXT:    store ptr [[INCDEC_PTR]], ptr [[__BEGIN1]], align 8, !dbg [[DBG26:![0-9]+]]49// CHECK-NEXT:    br label %[[FOR_COND]], !dbg [[DBG19]], !llvm.loop50// CHECK:       [[FOR_END]]:51// CHECK-NEXT:    ret void, !dbg [[DBG30:![0-9]+]]52//53void a() {54  for (int i: r)55    ;56}57 58// - Check the branch out of the body gets an atom group (and gets it correct59// if there's ctrl-flow in the body).60void b() {61  for (int i: r) {62    if (i)63      ;64// CHECK: entry:65// CHECK: if.end:66// CHECK-NEXT: br label %for.inc, !dbg [[b_br:!.*]]67  }68}69 70// - Check an immediate loop exit (`break` in this case) gets an atom group and71// - doesn't cause a crash.72void c() {73  for (int i: r)74// CHECK: entry:75// CHECK: for.body:76// CHECK: br label %for.end, !dbg [[c_br:!.*]]77    break;78}79 80//.81// CHECK: [[DBG14]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)82// CHECK: [[DBG15]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)83// CHECK: [[DBG16]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)84// CHECK: [[DBG17]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2)85// CHECK: [[DBG18]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)86// CHECK: [[DBG19]] = !DILocation({{.*}})87// CHECK: [[DBG20]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)88// CHECK: [[DBG21]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 1)89// CHECK: [[DBG22]] = !DILocation({{.*}}, atomGroup: 6, atomRank: 2)90// CHECK: [[DBG23]] = !DILocation({{.*}}, atomGroup: 6, atomRank: 1)91// CHECK: [[DBG24]] = !DILocation({{.*}} atomGroup: 8, atomRank: 1)92// CHECK: [[DBG25]] = !DILocation({{.*}}, atomGroup: 7, atomRank: 2)93// CHECK: [[DBG26]] = !DILocation({{.*}}, atomGroup: 7, atomRank: 1)94// CHECK: [[DBG30]] = !DILocation({{.*}})95//96// CHECK: [[b_br]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]])97//98// CHECK: [[c_br]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]])99//.100