-
Notifications
You must be signed in to change notification settings - Fork 745
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BoundsSafety] Add
-fexperimental-bounds-safety
CC1 and language op…
…tion and use it to tweak `counted_by`'s semantics (#92623) This adds the `-fexperimental-bounds-safety` cc1 and corresponding language option. This language option enables "-fbounds-safety" which is a bounds-safety extension for C that is being incrementally upstreamed. This cc1 flag is not exposed as a driver flag yet because most of the implementation isn't upstream yet. The language option is used to make a small semantic change to how the `counted_by` attribute is treated. Without `-fexperimental-bounds-safety` the attribute is allowed (but emits a warning) on a flexible array member where the element type is a struct with a flexible array member. With the flag this situation is an error. E.g. ``` struct has_unannotated_FAM { int count; char buffer[]; }; struct buffer_of_structs_with_unnannotated_FAM { int count; // Forbidden with `-fexperimental-bounds-safety` struct has_unannotated_FAM Arr[] __counted_by(count); }; ``` rdar://125400392
- Loading branch information
Showing
4 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// RUN: %clang_cc1 -fsyntax-only -fexperimental-bounds-safety -verify %s | ||
// | ||
// This is a portion of the `attr-counted-by-vla.c` test but is checked | ||
// under the semantics of `-fexperimental-bounds-safety` which has different | ||
// behavior. | ||
|
||
#define __counted_by(f) __attribute__((counted_by(f))) | ||
|
||
struct has_unannotated_VLA { | ||
int count; | ||
char buffer[]; | ||
}; | ||
|
||
struct has_annotated_VLA { | ||
int count; | ||
char buffer[] __counted_by(count); | ||
}; | ||
|
||
struct buffer_of_structs_with_unnannotated_vla { | ||
int count; | ||
// expected-error@+1{{'counted_by' cannot be applied to an array with element of unknown size because 'struct has_unannotated_VLA' is a struct type with a flexible array member}} | ||
struct has_unannotated_VLA Arr[] __counted_by(count); | ||
}; | ||
|
||
|
||
struct buffer_of_structs_with_annotated_vla { | ||
int count; | ||
// expected-error@+1{{'counted_by' cannot be applied to an array with element of unknown size because 'struct has_annotated_VLA' is a struct type with a flexible array member}} | ||
struct has_annotated_VLA Arr[] __counted_by(count); | ||
}; | ||
|
||
struct buffer_of_const_structs_with_annotated_vla { | ||
int count; | ||
// Make sure the `const` qualifier is printed when printing the element type. | ||
// expected-error@+1{{'counted_by' cannot be applied to an array with element of unknown size because 'const struct has_annotated_VLA' is a struct type with a flexible array member}} | ||
const struct has_annotated_VLA Arr[] __counted_by(count); | ||
}; |