|
| 1 | +// RUN: rm -rf %t && mkdir -p %t |
| 2 | +// RUN: split-file %s %t/Headers |
| 3 | +// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fsyntax-only -fapinotes-modules -I %t/Headers -fexperimental-bounds-safety-attributes %t/Headers/SemaErrors.c 2>&1 | FileCheck %s |
| 4 | +// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fsyntax-only -fapinotes-modules -I %t/Headers -fexperimental-bounds-safety-attributes %t/Headers/NegLevel.c 2>&1 | FileCheck %s --check-prefix NEGLEVEL |
| 5 | +// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fsyntax-only -fapinotes-modules -I %t/Headers -fexperimental-bounds-safety-attributes %t/Headers/InvalidKind.c 2>&1 | FileCheck %s --check-prefix INVALIDKIND |
| 6 | + |
| 7 | +//--- module.modulemap |
| 8 | +module SemaErrors { |
| 9 | + header "SemaErrors.h" |
| 10 | +} |
| 11 | +module NegLevel { |
| 12 | + header "NegLevel.h" |
| 13 | +} |
| 14 | +module InvalidKind { |
| 15 | + header "InvalidKind.h" |
| 16 | +} |
| 17 | + |
| 18 | +//--- SemaErrors.c |
| 19 | +#include "SemaErrors.h" |
| 20 | +//--- SemaErrors.apinotes |
| 21 | +Name: OOBLevel |
| 22 | +Functions: |
| 23 | + - Name: oob_level |
| 24 | + Parameters: |
| 25 | + - Position: 0 |
| 26 | + BoundsSafety: |
| 27 | + Kind: counted_by |
| 28 | + Level: 42 |
| 29 | + BoundedBy: len |
| 30 | + - Name: off_by_1_level |
| 31 | + Parameters: |
| 32 | + - Position: 0 |
| 33 | + BoundsSafety: |
| 34 | + Kind: counted_by |
| 35 | + Level: 1 |
| 36 | + BoundedBy: len |
| 37 | + - Name: nonpointer_param |
| 38 | + Parameters: |
| 39 | + - Position: 0 |
| 40 | + BoundsSafety: |
| 41 | + Kind: counted_by |
| 42 | + Level: 0 |
| 43 | + BoundedBy: len |
| 44 | + - Name: wrong_name |
| 45 | + Parameters: |
| 46 | + - Position: 0 |
| 47 | + BoundsSafety: |
| 48 | + Kind: counted_by |
| 49 | + Level: 0 |
| 50 | + BoundedBy: len |
| 51 | + - Name: wrong_scope |
| 52 | + Parameters: |
| 53 | + - Position: 0 |
| 54 | + BoundsSafety: |
| 55 | + Kind: counted_by |
| 56 | + Level: 0 |
| 57 | + BoundedBy: static_len |
| 58 | +//--- SemaErrors.h |
| 59 | +// CHECK: SemaErrors.h:{{.*}}:{{.*}}: error: __counted_by attribute only applies to pointer arguments |
| 60 | +// CHECK-NEXT: oob_level |
| 61 | +void oob_level(int * buf, int len); |
| 62 | +// CHECK: SemaErrors.h:{{.*}}:{{.*}}: error: __counted_by attribute only applies to pointer arguments |
| 63 | +// CHECK-NEXT: off_by_1_level |
| 64 | +void off_by_1_level(int * buf, int len); |
| 65 | +// CHECK: SemaErrors.h:{{.*}}:{{.*}}: error: __counted_by attribute only applies to pointer arguments |
| 66 | +// CHECK-NEXT: nonpointer_param |
| 67 | +void nonpointer_param(int buf, int len); |
| 68 | +// CHECK: <API Notes>:1:1: error: use of undeclared identifier 'len'; did you mean 'len2'? |
| 69 | +// CHECK: SemaErrors.h:{{.*}}:{{.*}}: note: 'len2' declared here |
| 70 | +// CHECK-NEXT: wrong_name |
| 71 | +void wrong_name(int * buf, int len2); |
| 72 | +// CHECK: SemaErrors.h:{{.*}}:{{.*}}: error: count expression in function declaration may only reference parameters of that function |
| 73 | +// CHECK-NEXT: wrong_scope |
| 74 | +int static_len = 5; |
| 75 | +void wrong_scope(int * buf); |
| 76 | +// CHECK: SemaErrors.c:{{.*}}:{{.*}}: fatal error: could not build module 'SemaErrors' |
| 77 | + |
| 78 | + |
| 79 | +//--- NegLevel.apinotes |
| 80 | +Name: NegLevel |
| 81 | +Functions: |
| 82 | + - Name: neg_level |
| 83 | + Parameters: |
| 84 | + - Position: 0 |
| 85 | + BoundsSafety: |
| 86 | + Kind: counted_by |
| 87 | + Level: -1 |
| 88 | + BoundedBy: len |
| 89 | +//--- NegLevel.h |
| 90 | +void neg_level(int * buf, int len); |
| 91 | +//--- NegLevel.c |
| 92 | +#include "NegLevel.h" |
| 93 | +// NEGLEVEL: NegLevel.apinotes:{{.*}}:{{.*}}: error: invalid number |
| 94 | +// NEGLEVEL-NEXT: Level: -1 |
| 95 | +// NEGLEVEL: NegLevel.c:{{.*}}:{{.*}}: fatal error: could not build module 'NegLevel' |
| 96 | + |
| 97 | + |
| 98 | +//--- InvalidKind.apinotes |
| 99 | +Name: InvalidKind |
| 100 | +Functions: |
| 101 | + - Name: invalid_kind |
| 102 | + Parameters: |
| 103 | + - Position: 0 |
| 104 | + BoundsSafety: |
| 105 | + Kind: __counted_by |
| 106 | + Level: 0 |
| 107 | + BoundedBy: len |
| 108 | +//--- InvalidKind.h |
| 109 | +void invalid_kind(int * buf, int len); |
| 110 | +//--- InvalidKind.c |
| 111 | +#include "InvalidKind.h" |
| 112 | +// INVALIDKIND: InvalidKind.apinotes:{{.*}}:{{.*}}: error: unknown enumerated scalar |
| 113 | +// INVALIDKIND-NEXT: Kind: __counted_by |
| 114 | +// INVALIDKIND: InvalidKind.c:{{.*}}:{{.*}}: fatal error: could not build module 'InvalidKind' |
| 115 | + |
0 commit comments