|
| 1 | +// Test without pch. |
| 2 | +// RUN: %clang_cc1 -fbounds-safety -include %s %s -ast-dump 2>&1 | FileCheck %s |
| 3 | + |
| 4 | +// Test with pch. |
| 5 | +// RUN: %clang_cc1 -fbounds-safety -emit-pch -o %t %s |
| 6 | +// RUN: %clang_cc1 -fbounds-safety -include-pch %t %s -ast-dump 2>&1 | FileCheck %s |
| 7 | + |
| 8 | +#ifndef HEADER |
| 9 | +#define HEADER |
| 10 | +#include <ptrcheck.h> |
| 11 | + |
| 12 | +struct Inner { |
| 13 | + int dummy; |
| 14 | + int len; |
| 15 | +}; |
| 16 | + |
| 17 | +struct Outer { |
| 18 | + struct Inner hdr; |
| 19 | + char fam[__counted_by(hdr.len)]; |
| 20 | +}; |
| 21 | + |
| 22 | +#else |
| 23 | + |
| 24 | +char access(struct Outer *bar, int index) { |
| 25 | + return bar->fam[index]; |
| 26 | +} |
| 27 | + |
| 28 | +// CHECK: -FunctionDecl [[func_access:0x[^ ]+]] {{.+}} access |
| 29 | +// CHECK: |-ParmVarDecl [[var_bar:0x[^ ]+]] |
| 30 | +// CHECK: |-ParmVarDecl [[var_index:0x[^ ]+]] |
| 31 | +// CHECK: `-CompoundStmt |
| 32 | +// CHECK: `-ReturnStmt |
| 33 | +// CHECK: `-ImplicitCastExpr {{.+}} 'char' <LValueToRValue> |
| 34 | +// CHECK: `-ArraySubscriptExpr |
| 35 | +// CHECK: |-MaterializeSequenceExpr {{.+}} <Unbind> |
| 36 | +// CHECK: | |-MaterializeSequenceExpr {{.+}} <Bind> |
| 37 | +// CHECK: | | |-BoundsSafetyPointerPromotionExpr {{.+}} 'char *__bidi_indexable' |
| 38 | +// CHECK: | | | |-ImplicitCastExpr {{.+}} 'char *' <ArrayToPointerDecay> |
| 39 | +// CHECK: | | | | `-MemberExpr {{.+}} ->fam |
| 40 | +// CHECK: | | | | `-OpaqueValueExpr [[ove:0x[^ ]+]] {{.*}} 'struct Outer *__single' |
| 41 | +// CHECK: | | | |-GetBoundExpr {{.+}} upper |
| 42 | +// CHECK: | | | | `-BoundsSafetyPointerPromotionExpr {{.+}} 'struct Outer *__bidi_indexable' |
| 43 | +// CHECK: | | | | |-OpaqueValueExpr [[ove]] {{.*}} 'struct Outer *__single' |
| 44 | +// CHECK: | | | | |-BinaryOperator {{.+}} 'char *' '+' |
| 45 | +// CHECK: | | | | | |-ImplicitCastExpr {{.+}} 'char *' <ArrayToPointerDecay> |
| 46 | +// CHECK: | | | | | | `-MemberExpr {{.+}} ->fam |
| 47 | +// CHECK: | | | | | | `-OpaqueValueExpr [[ove]] {{.*}} 'struct Outer *__single' |
| 48 | +// CHECK: | | | | | `-ImplicitCastExpr {{.+}} 'int' <LValueToRValue> |
| 49 | +// CHECK: | | | | | `-MemberExpr {{.+}} .len |
| 50 | +// CHECK: | | | | | `-MemberExpr {{.+}} ->hdr |
| 51 | +// CHECK: | | | | | `-OpaqueValueExpr [[ove]] {{.*}} 'struct Outer *__single' |
| 52 | +// CHECK: | | `-OpaqueValueExpr [[ove]] |
| 53 | +// CHECK: | | `-ImplicitCastExpr {{.+}} 'struct Outer *__single' <LValueToRValue> |
| 54 | +// CHECK: | | `-DeclRefExpr {{.+}} [[var_bar]] |
| 55 | +// CHECK: | `-OpaqueValueExpr [[ove]] {{.*}} 'struct Outer *__single' |
| 56 | +// CHECK: `-ImplicitCastExpr {{.+}} 'int' <LValueToRValue> |
| 57 | +// CHECK: `-DeclRefExpr {{.+}} [[var_index]] |
| 58 | + |
| 59 | +#endif |
0 commit comments