Skip to content

Commit 34ce74b

Browse files
committed
[BoundsSafety] Switch new bounds checks on by default and adjust test suite
This makes clang behave as if `-fbounds-safety-bringup-missing-checks=batch_0` was passed by default. This enables all the new bounds check in the `batch_0` group by default (which is currently all of them). Making this change broke a lot of tests. To handle this the following strategy was taken: * To avoid losing test coverage for when the legacy bounds checks are a new `clang/test/BoundsSafety-legacy-checks` directory has been created and all the tests that failed have been copied into this directory. This directory has a `lit.local.cfg.py` file that means the `%clang_cc1` substitution contains `-fno-bounds-safety-bringup-missing-checks=all`. Doing that means all tests under this directory build with the new bounds checks disabled implicitly which means the copies of the tests didn't need modification to pass. We can delete this directory when we drop support for the legacy bounds checks. * All failing tests under `clang/test/BoundsSafety` have been modified to pass with the new bounds checks enabled. Note I've not removed use of `-fbounds-safety-bringup-missing-checks=` under this test directory. This is something we should do as a separate clean up step. This strategy means we haven't lost any test coverage and we have gained much more test coverage for the new bounds checks. Unfortunately while doing this I discovered that enabling the new bounds checks breaks the experimental C++ support (see `BoundsSafety/AST/value-dependence.cpp` and `BoundsSafety/Sema/value-dependence.cpp`) (rdar://150044760). Given that this feature isn't currently adopted this seems acceptable and is something we can fix later if we need to. Unfortunately I also discovered that `clang/test/BoundsSafety/CodeGen/unique-trap-blocks-O2.c` is broken. I've XFAIL-ed the test and we'll need to fix a separate patch (rdar://150559639). rdar://148623233
1 parent 7a086fd commit 34ce74b

File tree

245 files changed

+33117
-6793
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

245 files changed

+33117
-6793
lines changed

clang/lib/Basic/LangOptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,6 @@ LangOptionsBase::getBoundsSafetyNewChecksMaskForGroup(StringRef GroupName) {
259259

260260
LangOptionsBase::BoundsSafetyNewChecksMaskIntTy
261261
LangOptionsBase::getDefaultBoundsSafetyNewChecksMask() {
262-
return BS_CHK_None;
262+
return getBoundsSafetyNewChecksMaskForGroup("batch_0");
263263
}
264264
/* TO_UPSTREAM(BoundsSafety) OFF*/

clang/test/BoundsSafety-legacy-checks/AST/SystemHeaders/builtin-function-main.c

Lines changed: 312 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../BoundsSafety/AST/SystemHeaders/include/builtin-function-sys.h

clang/test/BoundsSafety/AST/bounds-attributed-in-return-disabled.c renamed to clang/test/BoundsSafety-legacy-checks/AST/bounds-attributed-in-return-disabled.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include <ptrcheck.h>
77

8-
// TODO: Remove this test when return-size checks are enabled by default.
8+
// TODO: Remove this test when support for disabling return-size checks is removed.
99

1010
// CHECK: FunctionDecl [[func_cb_in_from_bidi:0x[^ ]+]] {{.+}} cb_in_from_bidi
1111
// CHECK: |-ParmVarDecl [[var_count:0x[^ ]+]]
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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

Comments
 (0)