Skip to content

Commit 2b8f020

Browse files
committed
[BoundsSafety] Fix diagnostics test failures
In fceb9ce upstream changed the diagnostic engine to always wrap expressions in single quotes. We already had manual wrapping for most of those, so the manual single quotes needed to be removed. In other placed the test cases needed to be updated to reflect the new output. rdar://149359009
1 parent 8958c2a commit 2b8f020

17 files changed

+196
-196
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12581,7 +12581,7 @@ let CategoryName = "BoundsSafety Pointer Attributes Issue" in {
1258112581
def err_bounds_safety_conflicting_pointer_attributes : Error<
1258212582
"%select{array|pointer}0 cannot have more than one %select{bound|type|count|end|terminator}1 attribute">;
1258312583
def note_bounds_safety_conflicting_pointer_attribute_args : Note<
12584-
"conflicting arguments for %select{count|end|terminator}0 were '%1' and '%2'">;
12584+
"conflicting arguments for %select{count|end|terminator}0 were %1 and %2">;
1258512585
def warn_bounds_safety_duplicate_pointer_attributes : Warning<
1258612586
"%select{array|pointer}0 annotated with %select{__unsafe_indexable|__bidi_indexable|__indexable|__single|__terminated_by}1 "
1258712587
"multiple times. Annotate only once to remove this warning">, InGroup<BoundsSafetyRedundantAttribute>;
@@ -12603,7 +12603,7 @@ def err_bounds_safety_dynamic_count_function_call : Error<
1260312603
"argument of '%select{__counted_by|__sized_by|__counted_by_or_null|__sized_by_or_null}0' attribute can only reference "
1260412604
"function with 'const' attribute">;
1260512605
def err_bounds_safety_dynamic_count_function_call_argument : Error<
12606-
"argument of function call '%0' in '%select{__counted_by|__sized_by|__counted_by_or_null|__sized_by_or_null}1' attribute is not a constant expression">;
12606+
"argument of function call %0 in '%select{__counted_by|__sized_by|__counted_by_or_null|__sized_by_or_null}1' attribute is not a constant expression">;
1260712607
def err_attribute_invalid_argument_expression_for_pointer_bounds_attribute : Error<
1260812608
"invalid argument expression to bounds attribute">;
1260912609
def err_invalid_decl_kind_bounds_safety_dynamic_count : Error<
@@ -12761,7 +12761,7 @@ def warn_bounds_safety_conv_single_to_implicit_indexable_unsafe_zeroth_element :
1276112761
"returning|" // UnsafeOpKind::Return
1276212762
"passing|" // UnsafeOpKind::CallArg
1276312763
"UNUSED" // UnsafeOpKind::Cast
12764-
"}0 __bidi_indexable '%1'"
12764+
"}0 __bidi_indexable %1"
1276512765
"%select{"
1276612766
" at any index|||||||}0 "
1276712767
"will %select{"
@@ -12774,7 +12774,7 @@ def warn_bounds_safety_conv_single_to_implicit_indexable_unsafe_zeroth_element :
1277412774
"pass an out-of-bounds pointer|" // UnsafeOpKind::CallArg
1277512775
"UNUSED" // UnsafeOpKind::Cast
1277612776
"}0. At runtime %4 is assigned a __single pointer that"
12777-
" results in '%1' having bounds smaller than a single %2 (%3 byte%s3)">,
12777+
" results in %1 having bounds smaller than a single %2 (%3 byte%s3)">,
1277812778
InGroup<BoundsSafetyConvSingleToImplicitIndexableThenConvertToLargerType>;
1277912779

1278012780
def warn_bounds_safety_conv_single_to_implicit_indexable_unsafely_cast :
@@ -12800,7 +12800,7 @@ def note_single_entity_assigned_here_with_pointee_sizes : Note<
1280012800
"struct member|" // AssignmentSourceKind::StructMember
1280112801
"union member" // AssignmentSourceKind::UnionMember
1280212802
"}0 %1 %select{assigned to|used to initialize}9 %2 here results in %2 having the bounds of a single %3 "
12803-
"(%4 bytes) but %select{'%8'|cast of %2 to %8}7 has pointee type %5 (%6 bytes)">;
12803+
"(%4 bytes) but %select{%8|cast of %2 to %8}7 has pointee type %5 (%6 bytes)">;
1280412804

1280512805
def warn_bounds_safety_conv_single_to_implicit_indexable_dynamic_count_conversion :
1280612806
Warning<
@@ -12899,7 +12899,7 @@ def err_bounds_safety_typeof_dbpt : Error<
1289912899
"__typeof__ on an expression of type %0 is not yet supported">;
1290012900

1290112901
def err_bounds_safety_single_pointer_arithmetic : Error<
12902-
"pointer arithmetic on single pointer '%0' is out of bounds%select{|; consider adding '__counted_by' to '%2'}1">;
12902+
"pointer arithmetic on single pointer %0 is out of bounds%select{|; consider adding '__counted_by' to '%2'}1">;
1290312903
def err_bounds_safety_flexible_array_member_record_pointer_arithmetic : Error<
1290412904
"-fbounds-safety forbids arithmetic on pointers to types with a flexible array "
1290512905
"member">;
@@ -12965,16 +12965,16 @@ def err_bounds_safety_counted_by_on_incomplete_type_on_var_decl : Error<
1296512965
>;
1296612966

1296712967
def err_bounds_safety_pointer_subscript : Error<
12968-
"array subscript on %select{single|'__terminated_by'}0 pointer '%1' "
12968+
"array subscript on %select{single|'__terminated_by'}0 pointer %1 "
1296912969
"%select{must use a constant index of 0 to be in bounds|is not allowed}0">;
1297012970
def err_bounds_safety_indexable_pointer_arithmetic : Error<
12971-
"decremented indexable pointer '%0' is out of bounds">;
12971+
"decremented indexable pointer %0 is out of bounds">;
1297212972
def err_bounds_safety_indexable_pointer_subscript : Error<
12973-
"array subscript with a negative index on indexable pointer '%0' is out of bounds">;
12973+
"array subscript with a negative index on indexable pointer %0 is out of bounds">;
1297412974
def err_bounds_safety_terminated_by_pointer_arithmetic_dec : Error<
12975-
"cannot decrement '__terminated_by' pointer '%0'">;
12975+
"cannot decrement '__terminated_by' pointer %0">;
1297612976
def err_bounds_safety_terminated_by_pointer_arithmetic : Error<
12977-
"pointer arithmetic on '__terminated_by' pointer '%0' can only increase the "
12977+
"pointer arithmetic on '__terminated_by' pointer %0 can only increase the "
1297812978
"value by one">;
1297912979

1298012980
def err_bounds_safety_dynamic_bound_pointer_unary_arithmetic : Error<
@@ -13073,7 +13073,7 @@ def err_bounds_safety_dependent_assignments_order : Error<
1307313073
def note_bounds_safety_decl_assignment : Note<
1307413074
"'%0' has been assigned here">;
1307513075
def err_bounds_safety_dependent_struct_assignment : Error<
13076-
"cannot assign '%0' because it contains field %1 referred to by flexible array member %2">;
13076+
"cannot assign %0 because it contains field %1 referred to by flexible array member %2">;
1307713077
def note_bounds_safety_count_param_loc : Note<
1307813078
"referred to by count parameter here">;
1307913079
def err_bounds_safety_dependent_field_duplicates : Error<
@@ -13083,7 +13083,7 @@ def note_bounds_safety_struct_fields_only_in_fam : Note<
1308313083
def error_bounds_safety_no_arrow_members : Error<
1308413084
"arrow notation not allowed for struct member in count parameter">;
1308513085
def error_bounds_safety_no_count_in_unions : Error<
13086-
"count parameter refers to union '%0' of type %1">;
13086+
"count parameter refers to union %0 of type %1">;
1308713087

1308813088
def err_bounds_safety_taking_address_dynamic_bound_dependent : Error<
1308913089
"%select{variable|field}1 referred to by '%select{__counted_by|__sized_by|__counted_by_or_null|__sized_by_or_null|__ended_by}0' "
@@ -13105,7 +13105,7 @@ def err_bounds_safety_incompatible_dynamic_bound_argument: Error<
1310513105
def err_bounds_safety_mismatching_count_type_argument: Error<
1310613106
"incompatible pointer types assigning %0 with an expression with mismatching size attributes %1">;
1310713107
def err_bounds_safety_incompatible_count_expression: Error<
13108-
"incompatible count expression (%0) vs. (%1) in argument to function">;
13108+
"incompatible count expression %0 vs. %1 in argument to function">;
1310913109
def err_bounds_safety_unsynchronized_indirect_param: Error<
1311013110
"passing%select{| address of}1 %0 as an indirect parameter; "
1311113111
"must also pass %2 %select{|or its address }3because the type of %select{%0|%2}4, "
@@ -13190,7 +13190,7 @@ def note_bounds_safety_consider_adding_to_return : Note<
1319013190

1319113191
def warn_bounds_safety_initlist_range_partial_null : Warning<
1319213192
"%select{|implicitly }0initializing field %1 of type %2 to NULL while "
13193-
"'%3' is initialized with a value rarely succeeds">, InGroup<BoundsSafetyInitListPartialNull>;
13193+
"%3 is initialized with a value rarely succeeds">, InGroup<BoundsSafetyInitListPartialNull>;
1319413194

1319513195
def err_bounds_safety_dynamic_bound_init_side_effect : Error<
1319613196
"initalizer for %select{count|size|'__counted_by' pointer|'__sized_by' pointer|'__counted_by_or_null' pointer|'__sized_by_or_null' pointer|'__ended_by' pointer|end pointer}0 with side effects is not yet supported">;
@@ -13206,7 +13206,7 @@ def err_bounds_safety_flexible_global_wrong_count : Error<
1320613206
def err_bounds_safety_flexible_global_not_counted : Error<
1320713207
"flexible array member is initialized without a count">;
1320813208
def err_bounds_safety_flexible_global_non_int_count_init : Error<
13209-
"count '%0' has non-integer value '%1' of type %2">;
13209+
"count %0 has non-integer value %1 of type %2">;
1321013210

1321113211
def err_bounds_safety_local_external_dynamic_count : Error<
1321213212
"attribute %0 is not allowed for local variables with external storage">;
@@ -13399,7 +13399,7 @@ def err_bounds_safety_terminated_by_wrong_initializer_kind : Error<
1339913399
"string literal or an initializer list">;
1340013400
def err_bounds_safety_terminated_by_terminator_mismatch : Error<
1340113401
"array '%0' with '__terminated_by' attribute is initialized with an "
13402-
"incorrect terminator (expected: %1; got %2)">;
13402+
"incorrect terminator (expected: %quoted1; got %quoted2)">;
1340313403

1340413404
def err_bounds_safety_irrecoverable_attr : Error<
1340513405
"bounds attribute '%select{__bidi_indexable|__indexable|__single|__unsafe_indexable}0' cannot be applied to attributed type %1 in this context%select{| due to the surrounding 'typeof' specifier}2">;
@@ -13769,8 +13769,8 @@ def warn_unsafe_count_attributed_pointer_argument : Warning<
1376913769
InGroup<UnsafeBufferUsage>, DefaultIgnore;
1377013770
def note_unsafe_count_attributed_pointer_argument : Note<
1377113771
"consider using %select{|a safe container and passing '.data()' to the "
13772-
"parameter%select{| '%3'}2 and '.size()' to its dependent parameter '%4' or }0"
13773-
"'std::span' and passing '.first(...).data()' to the parameter%select{| '%3'}2">;
13772+
"parameter%select{| %3}2 and '.size()' to its dependent parameter %4 or }0"
13773+
"'std::span' and passing '.first(...).data()' to the parameter%select{| %3}2">;
1377413774
def warn_unsafe_single_pointer_argument : Warning<
1377513775
"unsafe assignment to function parameter of __single pointer type">,
1377613776
InGroup<UnsafeBufferUsage>, DefaultIgnore;

clang/test/BoundsSafety/AST/struct-init-with-side-effects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void test_count_annot() {
9898
struct s_count_annot s1 = {
9999
.len = 10,
100100
.ptr = arr,
101-
// expected-warning@+1{{initializer getlen() has a side effect; this may lead to an unexpected result because the evaluation order of initialization list expressions is indeterminate}}
101+
// expected-warning@+1{{initializer 'getlen()' has a side effect; this may lead to an unexpected result because the evaluation order of initialization list expressions is indeterminate}}
102102
.dummy = getlen()
103103
};
104104
struct s_count_annot s2;
@@ -157,7 +157,7 @@ void test_range_annot() {
157157
struct s_range_annot s1 = {
158158
.end = arr + 10,
159159
.start = arr,
160-
// expected-warning@+1{{initializer getlen() has a side effect; this may lead to an unexpected result because the evaluation order of initialization list expressions is indeterminate}}
160+
// expected-warning@+1{{initializer 'getlen()' has a side effect; this may lead to an unexpected result because the evaluation order of initialization list expressions is indeterminate}}
161161
.dummy = getlen()
162162
};
163163
struct s_count_annot s2;

clang/test/BoundsSafety/Sema/address-taken-dynamic-count-decls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ int main() {
9797

9898
foo(&s.len, &s.buf);
9999
foo(&local_len, &s.buf); // expected-error{{incompatible dynamic count pointer argument to parameter of type}}
100-
foo(&t.len, &t.buf); // expected-error{{incompatible count expression (*out_len) vs. (len + 1) in argument to function}}
100+
foo(&t.len, &t.buf); // expected-error{{incompatible count expression '*out_len' vs. 'len + 1' in argument to function}}
101101
// expected-error@+1{{passing address of 'len' as an indirect parameter; must also pass 'buf2' or its address because the type of 'buf2', 'int *__single __counted_by(len)' (aka 'int *__single'), refers to 'len'}}
102102
foo(&u.len, &u.buf);
103103
bar(&s.len, &s.buf); // expected-error{{passing address of 'len' referred to by '__counted_by' to a parameter that is not referred to by the same attribute}}

0 commit comments

Comments
 (0)