|
| 1 | +// RUN: %clang_cc1 -triple x86_64-apple-mac -ast-dump -fbounds-safety %s | FileCheck %s |
| 2 | +// RUN: %clang_cc1 -triple x86_64-apple-mac -ast-dump -fbounds-safety -x objective-c -fbounds-attributes-objc-experimental %s | FileCheck %s |
| 3 | +#include <ptrcheck.h> |
| 4 | + |
| 5 | +int *__counted_by(len) frob(int len); |
| 6 | + |
| 7 | +int *__sized_by(len) byte_frob(int len); |
| 8 | +void *alloc_bytes(int byte_count) __attribute__((alloc_size(1))); |
| 9 | +// <rdar://problem/70626464> |
| 10 | +// void *alloc_items(int byte_count, int size) __attribute__((alloc_size(1, 2))); |
| 11 | + |
| 12 | +typedef int (__array_decay_discards_count_in_parameters int_array_t)[10]; |
| 13 | +void count_attr_in_bracket(int buf[__counted_by(len)], int len); |
| 14 | +void count_ignored_from_array(int (__array_decay_discards_count_in_parameters buf)[10]); |
| 15 | +void count_ignored_and_attr(int_array_t __counted_by(count) buf, int count); |
| 16 | + |
| 17 | +struct s { |
| 18 | + int *__counted_by(l) bp; |
| 19 | + int *bp2 __counted_by(l+1); |
| 20 | + unsigned char *bp3 __sized_by(l); |
| 21 | + unsigned char *bp4 __sized_by(l+1); |
| 22 | + int l; |
| 23 | +}; |
| 24 | + |
| 25 | +void test(void) { |
| 26 | + int n = 0; |
| 27 | + int *__counted_by(n) buf1; |
| 28 | + int n2 = 0; |
| 29 | + int *buf2 __counted_by(n2); |
| 30 | + int n3 = sizeof(int) * n; |
| 31 | + unsigned char *__sized_by(n3) byte_buf1; |
| 32 | + int n4 = sizeof(int) * n2; |
| 33 | + unsigned char *byte_buf2 __sized_by(n4); |
| 34 | +} |
| 35 | + |
| 36 | +int *__counted_by(len) frob_body(int len) { return 0; } |
| 37 | +int *__sized_by(len) byte_frob_body(int len) { return 0; } |
| 38 | +// CHECK:TranslationUnitDecl {{.*}} |
| 39 | +// CHECK:|-FunctionDecl {{.*}} frob 'int *__single __counted_by(len)(int)' |
| 40 | +// CHECK-NEXT:| `-ParmVarDecl {{.*}} used len 'int' |
| 41 | +// CHECK-NEXT:|-FunctionDecl {{.*}} byte_frob 'int *__single __sized_by(len)(int)' |
| 42 | +// CHECK-NEXT:| `-ParmVarDecl {{.*}} used len 'int' |
| 43 | +// CHECK-NEXT:|-FunctionDecl {{.*}} alloc_bytes 'void *__single(int)' |
| 44 | +// CHECK-NEXT:| |-ParmVarDecl {{.*}} byte_count 'int' |
| 45 | +// CHECK-NEXT:| `-AllocSizeAttr {{.*}} 1 |
| 46 | +// CHECK-NEXT:|-TypedefDecl {{.*}} referenced int_array_t '__array_decay_discards_count_in_parameters int[10]':'int[10]' |
| 47 | +// CHECK-NEXT:| `-MacroQualifiedType {{.*}} '__array_decay_discards_count_in_parameters int[10]' sugar |
| 48 | +// CHECK-NEXT:| `-AttributedType {{.*}} 'int[10] __attribute__((decay_discards_count_in_parameters))' sugar |
| 49 | +// CHECK-NEXT:| `-ParenType {{.*}} 'int[10]' sugar |
| 50 | +// CHECK-NEXT:| `-ConstantArrayType {{.*}} 'int[10]' 10 |
| 51 | +// CHECK-NEXT:| `-BuiltinType {{.*}} 'int' |
| 52 | +// CHECK-NEXT:|-FunctionDecl {{.*}} count_attr_in_bracket 'void (int *__single __counted_by(len), int)' |
| 53 | +// CHECK-NEXT:| |-ParmVarDecl {{.*}} buf 'int *__single __counted_by(len)':'int *__single' |
| 54 | +// CHECK-NEXT:| `-ParmVarDecl {{.*}} used len 'int' |
| 55 | +// CHECK-NEXT:| `-DependerDeclsAttr {{.*}} Implicit {{.*}} 0 |
| 56 | +// CHECK-NEXT:|-FunctionDecl {{.*}} count_ignored_from_array 'void (int *__single)' |
| 57 | +// CHECK-NEXT:| `-ParmVarDecl {{.*}} buf 'int *__single' |
| 58 | +// CHECK-NEXT:|-FunctionDecl {{.*}} count_ignored_and_attr 'void (int *__single __counted_by(count), int)' |
| 59 | +// CHECK-NEXT:| |-ParmVarDecl {{.*}} buf 'int *__single __counted_by(count)':'int *__single' |
| 60 | +// CHECK-NEXT:| `-ParmVarDecl {{.*}} used count 'int' |
| 61 | +// CHECK-NEXT:| `-DependerDeclsAttr {{.*}} Implicit {{.*}} 0 |
| 62 | +// CHECK-NEXT:|-RecordDecl {{.*}} struct s definition |
| 63 | +// CHECK-NEXT:| |-FieldDecl {{.*}} bp 'int *__single __counted_by(l)':'int *__single' |
| 64 | +// CHECK-NEXT:| |-FieldDecl {{.*}} bp2 'int *__single __counted_by(l + 1)':'int *__single' |
| 65 | +// CHECK-NEXT:| |-FieldDecl {{.*}} bp3 'unsigned char *__single __sized_by(l)':'unsigned char *__single' |
| 66 | +// CHECK-NEXT:| |-FieldDecl {{.*}} bp4 'unsigned char *__single __sized_by(l + 1)':'unsigned char *__single' |
| 67 | +// CHECK-NEXT:| `-FieldDecl {{.*}} referenced l 'int' |
| 68 | +// CHECK-NEXT:| `-DependerDeclsAttr {{.*}} Implicit {{.*}} {{.*}} {{.*}} {{.*}} 0 0 0 0 |
| 69 | +// CHECK-NEXT:|-FunctionDecl {{.*}} test 'void (void)' |
| 70 | +// CHECK-NEXT:| `-CompoundStmt {{.*}} |
| 71 | +// CHECK-NEXT:| |-DeclStmt {{.*}} |
| 72 | +// CHECK-NEXT:| | `-VarDecl {{.*}} used n 'int' cinit |
| 73 | +// CHECK-NEXT:| | |-IntegerLiteral {{.*}} 'int' 0 |
| 74 | +// CHECK-NEXT:| | `-DependerDeclsAttr {{.*}} Implicit {{.*}} 0 |
| 75 | +// CHECK-NEXT:| |-DeclStmt {{.*}} |
| 76 | +// CHECK-NEXT:| | `-VarDecl {{.*}} buf1 'int *__single __counted_by(n)':'int *__single' |
| 77 | +// CHECK-NEXT:| |-DeclStmt {{.*}} |
| 78 | +// CHECK-NEXT:| | `-VarDecl {{.*}} used n2 'int' cinit |
| 79 | +// CHECK-NEXT:| | |-IntegerLiteral {{.*}} 'int' 0 |
| 80 | +// CHECK-NEXT:| | `-DependerDeclsAttr {{.*}} Implicit {{.*}} 0 |
| 81 | +// CHECK-NEXT:| |-DeclStmt {{.*}} |
| 82 | +// CHECK-NEXT:| | `-VarDecl {{.*}} buf2 'int *__single __counted_by(n2)':'int *__single' |
| 83 | +// CHECK-NEXT:| |-DeclStmt {{.*}} |
| 84 | +// CHECK-NEXT:| | `-VarDecl {{.*}} used n3 'int' cinit |
| 85 | +// CHECK-NEXT:| | |-ImplicitCastExpr {{.*}} 'int' <IntegralCast> |
| 86 | +// CHECK-NEXT:| | | `-BinaryOperator {{.*}} 'unsigned long' '*' |
| 87 | +// CHECK-NEXT:| | | |-UnaryExprOrTypeTraitExpr {{.*}} 'unsigned long' sizeof 'int' |
| 88 | +// CHECK-NEXT:| | | `-ImplicitCastExpr {{.*}} 'unsigned long' <IntegralCast> |
| 89 | +// CHECK-NEXT:| | | `-ImplicitCastExpr {{.*}} 'int' <LValueToRValue> |
| 90 | +// CHECK-NEXT:| | | `-DeclRefExpr {{.*}} 'int' lvalue Var {{.*}} 'n' 'int' |
| 91 | +// CHECK-NEXT:| | `-DependerDeclsAttr {{.*}} Implicit {{.*}} 0 |
| 92 | +// CHECK-NEXT:| |-DeclStmt {{.*}} |
| 93 | +// CHECK-NEXT:| | `-VarDecl {{.*}} byte_buf1 'unsigned char *__single __sized_by(n3)':'unsigned char *__single' |
| 94 | +// CHECK-NEXT:| |-DeclStmt {{.*}} |
| 95 | +// CHECK-NEXT:| | `-VarDecl {{.*}} used n4 'int' cinit |
| 96 | +// CHECK-NEXT:| | |-ImplicitCastExpr {{.*}} 'int' <IntegralCast> |
| 97 | +// CHECK-NEXT:| | | `-BinaryOperator {{.*}} 'unsigned long' '*' |
| 98 | +// CHECK-NEXT:| | | |-UnaryExprOrTypeTraitExpr {{.*}} 'unsigned long' sizeof 'int' |
| 99 | +// CHECK-NEXT:| | | `-ImplicitCastExpr {{.*}} 'unsigned long' <IntegralCast> |
| 100 | +// CHECK-NEXT:| | | `-ImplicitCastExpr {{.*}} 'int' <LValueToRValue> |
| 101 | +// CHECK-NEXT:| | | `-DeclRefExpr {{.*}} 'int' lvalue Var {{.*}} 'n2' 'int' |
| 102 | +// CHECK-NEXT:| | `-DependerDeclsAttr {{.*}} Implicit {{.*}} 0 |
| 103 | +// CHECK-NEXT:| `-DeclStmt {{.*}} |
| 104 | +// CHECK-NEXT:| `-VarDecl {{.*}} byte_buf2 'unsigned char *__single __sized_by(n4)':'unsigned char *__single' |
| 105 | +// CHECK-NEXT:|-FunctionDecl {{.*}} frob_body 'int *__single __counted_by(len)(int)' |
| 106 | +// CHECK-NEXT:| |-ParmVarDecl {{.*}} used len 'int' |
| 107 | +// CHECK-NEXT:| `-CompoundStmt {{.*}} |
| 108 | +// CHECK-NEXT:| `-ReturnStmt {{.*}} |
| 109 | +// CHECK-NEXT:| `-ImplicitCastExpr {{.*}} 'int *__single __counted_by(len)':'int *__single' <NullToPointer> |
| 110 | +// CHECK-NEXT:| `-IntegerLiteral {{.*}} 'int' 0 |
| 111 | +// CHECK-NEXT:`-FunctionDecl {{.*}} byte_frob_body 'int *__single __sized_by(len)(int)' |
| 112 | +// CHECK-NEXT: |-ParmVarDecl {{.*}} used len 'int' |
| 113 | +// CHECK-NEXT: `-CompoundStmt {{.*}} |
| 114 | +// CHECK-NEXT: `-ReturnStmt {{.*}} |
| 115 | +// CHECK-NEXT: `-ImplicitCastExpr {{.*}} 'int *__single __sized_by(len)':'int *__single' <NullToPointer> |
| 116 | +// CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 0 |
0 commit comments