| 1 |
// RUN: %clang_cc1 -triple x86_64-linux-gnu -gkey-instructions -gno-column-info -x c++ %s -debug-info-kind=line-tables-only -emit-llvm -o - \ |
| 2 |
// RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-CXX |
| 3 |
|
| 4 |
// RUN: %clang_cc1 -triple x86_64-linux-gnu -gkey-instructions -gno-column-info -x c %s -debug-info-kind=line-tables-only -emit-llvm -o - \ |
| 5 |
// RUN: | FileCheck %s |
| 6 |
|
| 7 |
// Check the stores to `retval` allocas and branches to `return` block are in |
| 8 |
// the same atom group. They are both rank 1, which could in theory introduce |
| 9 |
// an extra step in some optimized code. This low risk currently feels an |
| 10 |
// acceptable for keeping the code a bit simpler (as opposed to adding |
| 11 |
// scaffolding to make the store rank 2). |
| 12 |
|
| 13 |
// Also check that in the case of a single return (no control flow) the |
| 14 |
// return instruction inherits the atom group of the branch to the return |
| 15 |
// block when the blocks get folded togather. |
| 16 |
|
| 17 |
#ifdef __cplusplus |
| 18 |
#define nomangle extern "C" |
| 19 |
#else |
| 20 |
#define nomangle |
| 21 |
#endif |
| 22 |
|
| 23 |
int g; |
| 24 |
nomangle float a() { |
| 25 |
// CHECK: float @a() |
| 26 |
if (g) |
| 27 |
// CHECK: if.then: |
| 28 |
// CHECK-NEXT: %1 = load i32, ptr @g{{.*}}, !dbg [[G2R3:!.*]] |
| 29 |
// CHECK-NEXT: %conv = sitofp i32 %1 to float{{.*}}, !dbg [[G2R2:!.*]] |
| 30 |
// CHECK-NEXT: store float %conv, ptr %retval{{.*}}, !dbg [[G2R1:!.*]] |
| 31 |
// CHECK-NEXT: br label %return{{.*}}, !dbg [[G2R1]] |
| 32 |
return g; |
| 33 |
// CHECK: if.end: |
| 34 |
// CHECK-NEXT: store float 1.000000e+00, ptr %retval{{.*}}, !dbg [[G3R1:!.*]] |
| 35 |
// CHECK-NEXT: br label %return, !dbg [[G3R1]] |
| 36 |
|
| 37 |
// CHECK: return: |
| 38 |
// CHECK-NEXT: %2 = load float, ptr %retval{{.*}}, !dbg [[G4R2:!.*]] |
| 39 |
// CHECK-NEXT: ret float %2{{.*}}, !dbg [[G4R1:!.*]] |
| 40 |
return 1; |
| 41 |
} |
| 42 |
|
| 43 |
// CHECK: void @b() |
| 44 |
// CHECK: ret void{{.*}}, !dbg [[B_G1R1:!.*]] |
| 45 |
nomangle void b() { return; } |
| 46 |
|
| 47 |
// CHECK: i32 @c() |
| 48 |
// CHECK: %add = add{{.*}}, !dbg [[C_G1R2:!.*]] |
| 49 |
// CHECK: ret i32 %add{{.*}}, !dbg [[C_G1R1:!.*]] |
| 50 |
nomangle int c() { return g + 1; } |
| 51 |
|
| 52 |
// NOTE: (return) (g = 1) are two separate atoms. |
| 53 |
// CHECK: i32 @d() |
| 54 |
// CHECK: store{{.*}}, !dbg [[D_G2R1:!.*]] |
| 55 |
// CHECK: ret i32 1{{.*}}, !dbg [[D_G1R1:!.*]] |
| 56 |
nomangle int d() { return g = 1; } |
| 57 |
|
| 58 |
// The implicit return here get the line number of the closing brace; make it |
| 59 |
// key to match existing behaviour. |
| 60 |
// CHECK: void @e() |
| 61 |
// CHECK: ret void, !dbg [[E_G1R1:!.*]] |
| 62 |
nomangle void e() {} |
| 63 |
|
| 64 |
#ifdef __cplusplus |
| 65 |
// CHECK-CXX: ptr @_Z1fRi |
| 66 |
int &f(int &r) { |
| 67 |
// Include ctrl-flow to stop ret value store being elided. |
| 68 |
if (r) |
| 69 |
// CHECK-CXX: if.then: |
| 70 |
// CHECK-CXX-NEXT: %2 = load ptr, ptr %r.addr{{.*}}, !dbg [[F_G2R2:!.*]], !nonnull |
| 71 |
// CHECK-CXX-NEXT: store ptr %2, ptr %retval{{.*}}, !dbg [[F_G2R1:!.*]] |
| 72 |
// CHECK-CXX-NEXT: br label %return, !dbg [[F_G2R1:!.*]] |
| 73 |
return r; |
| 74 |
|
| 75 |
// CHECK-CXX: if.end: |
| 76 |
// CHECK-CXX-NEXT: store ptr @g, ptr %retval{{.*}}, !dbg [[F_G3R1:!.*]] |
| 77 |
// CHECK-CXX-NEXT: br label %return, !dbg [[F_G3R1:!.*]] |
| 78 |
// CHECK-CXX: return: |
| 79 |
// CHECK-CXX-NEXT: %3 = load ptr, ptr %retval{{.*}}, !dbg [[F_G4R2:!.*]] |
| 80 |
// CHECK-CXX-NEXT: ret ptr %3, !dbg [[F_G4R1:!.*]] |
| 81 |
return g; |
| 82 |
} |
| 83 |
#endif |
| 84 |
|
| 85 |
// CHECK: [[G2R3]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 3) |
| 86 |
// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2) |
| 87 |
// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) |
| 88 |
// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) |
| 89 |
// CHECK: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2) |
| 90 |
// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) |
| 91 |
// CHECK: [[B_G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) |
| 92 |
// CHECK: [[C_G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) |
| 93 |
// CHECK: [[C_G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) |
| 94 |
// CHECK: [[D_G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) |
| 95 |
// CHECK: [[D_G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) |
| 96 |
// CHECK: [[E_G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) |
| 97 |
// CHECK-CXX: [[F_G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2) |
| 98 |
// CHECK-CXX: [[F_G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) |
| 99 |
// CHECK-CXX: [[F_G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) |
| 100 |
// CHECK-CXX: [[F_G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2) |
| 101 |
// CHECK-CXX: [[F_G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) |