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
19 lines
455 B
C++
19 lines
455 B
C++
// REQUIRES: x86-registered-target
|
|
// RUN: %clang_cc1 -emit-llvm -triple x86_64 -fsanitize=array-bounds %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-STRICT-0
|
|
//
|
|
// Disable checks on FAM even though the class doesn't have standard layout.
|
|
|
|
struct C {
|
|
int head;
|
|
};
|
|
|
|
struct S : C {
|
|
int tail[1];
|
|
};
|
|
|
|
// CHECK-LABEL: define {{.*}} @_Z8test_oneP1Si(
|
|
int test_one(S *p, int i) {
|
|
// CHECK-STRICT-0-NOT: @__ubsan
|
|
return p->tail[i] + (p->tail)[i];
|
|
}
|