Some code [0] consider that trailing arrays are flexible, whatever their size.
Support for these legacy code has been introduced in
f8f6324983 but it prevents evaluation of
__builtin_object_size and __builtin_dynamic_object_size in some legit cases.
Introduce -fstrict-flex-arrays=<n> to have stricter conformance when it is
desirable.
n = 0: current behavior, any trailing array member is a flexible array. The default.
n = 1: any trailing array member of undefined, 0 or 1 size is a flexible array member
n = 2: any trailing array member of undefined or 0 size is a flexible array member
This takes into account two specificities of clang: array bounds as macro id
disqualify FAM, as well as non standard layout.
Similar patch for gcc discuss here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836
[0] https://docs.freebsd.org/en/books/developers-handbook/sockets/#sockets-essential-functions
17 lines
398 B
Objective-C
17 lines
398 B
Objective-C
// RUN: %clang_cc1 -x objective-c -emit-llvm -triple x86_64-apple-macosx10.10.0 -Wno-objc-root-class -fsanitize=array-bounds %s -o - | FileCheck %s
|
|
|
|
@interface FlexibleArray1 {
|
|
@public
|
|
char chars[0];
|
|
}
|
|
@end
|
|
@implementation FlexibleArray1
|
|
@end
|
|
|
|
// CHECK-LABEL: test_FlexibleArray1
|
|
char test_FlexibleArray1(FlexibleArray1 *FA1) {
|
|
// CHECK-NOT: !nosanitize
|
|
return FA1->chars[1];
|
|
// CHECK: }
|
|
}
|