| 1 |
// RUN: %clang_cc1 -ast-dump -verify -x c %s | FileCheck -check-prefix=CHECK-C %s |
| 2 |
// RUN: %clang_cc1 -ast-dump -x c++ -std=c++11 %s | FileCheck %s --check-prefixes CHECK-C,CHECK-CPP |
| 3 |
|
| 4 |
// expected-no-diagnostics |
| 5 |
|
| 6 |
void bar(int); |
| 7 |
// CHECK-C: FunctionDecl{{.*}}code_align 'void ()' |
| 8 |
void code_align() { |
| 9 |
int a1[10], a2[10]; |
| 10 |
// CHECK-C: AttributedStmt |
| 11 |
// CHECK-C-NEXT: CodeAlignAttr |
| 12 |
// CHECK-C-NEXT: ConstantExpr{{.*}}'int' |
| 13 |
// CHECK-C-NEXT: value: Int 16 |
| 14 |
// CHECK-C-NEXT: IntegerLiteral{{.*}}16{{$}} |
| 15 |
[[clang::code_align(16)]] for (int p = 0; p < 128; ++p) { |
| 16 |
a1[p] = a2[p] = 0; |
| 17 |
} |
| 18 |
|
| 19 |
// CHECK-C: AttributedStmt |
| 20 |
// CHECK-C-NEXT: CodeAlignAttr |
| 21 |
// CHECK-C-NEXT: ConstantExpr{{.*}}'int' |
| 22 |
// CHECK-C-NEXT: value: Int 4 |
| 23 |
// CHECK-C-NEXT: IntegerLiteral{{.*}}4{{$}} |
| 24 |
int i = 0; |
| 25 |
[[clang::code_align(4)]] while (i < 30) { |
| 26 |
a1[i] += 3; |
| 27 |
} |
| 28 |
|
| 29 |
// CHECK-C: AttributedStmt |
| 30 |
// CHECK-C-NEXT: CodeAlignAttr |
| 31 |
// CHECK-C-NEXT: ConstantExpr{{.*}}'int' |
| 32 |
// CHECK-C-NEXT: value: Int 32 |
| 33 |
// CHECK-C-NEXT: IntegerLiteral{{.*}}32{{$}} |
| 34 |
for (int i = 0; i < 128; ++i) { |
| 35 |
[[clang::code_align(32)]] for (int j = 0; j < 128; ++j) { |
| 36 |
a1[i] += a1[j]; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
// CHECK-C: AttributedStmt |
| 41 |
// CHECK-C-NEXT: CodeAlignAttr |
| 42 |
// CHECK-C-NEXT: ConstantExpr{{.*}}'int' |
| 43 |
// CHECK-C-NEXT: value: Int 64 |
| 44 |
// CHECK-C-NEXT: IntegerLiteral{{.*}}64{{$}} |
| 45 |
[[clang::code_align(64)]] |
| 46 |
for(int I=0; I<128; ++I) { bar(I); } |
| 47 |
|
| 48 |
// CHECK-C: AttributedStmt |
| 49 |
// CHECK-C-NEXT: CodeAlignAttr |
| 50 |
// CHECK-C-NEXT: ConstantExpr{{.*}}'int' |
| 51 |
// CHECK-C-NEXT: value: Int 4 |
| 52 |
// CHECK-C-NEXT: IntegerLiteral{{.*}}4{{$}} |
| 53 |
int b = 10; |
| 54 |
[[clang::code_align(4)]] do { |
| 55 |
b = b + 1; |
| 56 |
} while (b < 20); |
| 57 |
} |
| 58 |
|
| 59 |
#if __cplusplus >= 201103L |
| 60 |
//CHECK-CPP: FunctionDecl{{.*}}used code_align_cpp 'void ()' implicit_instantiation |
| 61 |
template <int A, int B> |
| 62 |
void code_align_cpp() { |
| 63 |
int a[10]; |
| 64 |
// CHECK-CPP: AttributedStmt |
| 65 |
// CHECK-CPP-NEXT: CodeAlignAttr |
| 66 |
// CHECK-CPP-NEXT: ConstantExpr{{.*}}'int' |
| 67 |
// CHECK-CPP-NEXT: value: Int 32 |
| 68 |
// CHECK-CPP-NEXT: SubstNonTypeTemplateParmExpr{{.*}}'int' |
| 69 |
// CHECK-CPP-NEXT: NonTypeTemplateParmDecl{{.*}}referenced 'int' depth 0 index 0 A |
| 70 |
// CHECK-CPP-NEXT: IntegerLiteral{{.*}}32{{$}} |
| 71 |
[[clang::code_align(A)]] for (int i = 0; i != 10; ++i) |
| 72 |
a[i] = 0; |
| 73 |
|
| 74 |
// CHECK-CPP: AttributedStmt |
| 75 |
// CHECK-CPP-NEXT: CodeAlignAttr |
| 76 |
// CHECK-CPP-NEXT: ConstantExpr{{.*}}'int' |
| 77 |
// CHECK-CPP-NEXT: value: Int 4 |
| 78 |
// CHECK-CPP-NEXT: SubstNonTypeTemplateParmExpr{{.*}}'int' |
| 79 |
// CHECK-CPP-NEXT: NonTypeTemplateParmDecl{{.*}}referenced 'int' depth 0 index 1 B |
| 80 |
// CHECK-CPP-NEXT: IntegerLiteral{{.*}}4{{$}} |
| 81 |
int c[] = {0, 1, 2, 3, 4, 5}; |
| 82 |
[[clang::code_align(B)]] for (int n : c) { n *= 2; } |
| 83 |
} |
| 84 |
|
| 85 |
int main() { |
| 86 |
code_align_cpp<32, 4>(); |
| 87 |
return 0; |
| 88 |
} |
| 89 |
#endif |