mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Fix Clang 16 UBSan issue with zero-length Array
The current implementation of `Array<T, 0>` has a zero-length C array as its storage type. While this is accepted as a GNU extension, when compiling with Clang 16, an UBSan error is raised every time an object is accessed whose only field is a zero-length array. This is likely a bug in Clang 16's implementation of UBSan, which has been reported here: https://github.com/llvm/llvm-project/issues/61775
This commit is contained in:
parent
e77552519e
commit
0016f63547
Notes:
sideshowbarker
2024-07-16 22:12:21 +09:00
Author: https://github.com/BertalanD Commit: https://github.com/SerenityOS/serenity/commit/0016f63547 Pull-request: https://github.com/SerenityOS/serenity/pull/18069 Reviewed-by: https://github.com/trflynn89 ✅
1 changed files with 11 additions and 1 deletions
12
AK/Array.h
12
AK/Array.h
|
@ -13,6 +13,16 @@
|
|||
|
||||
namespace AK {
|
||||
|
||||
namespace Detail {
|
||||
// This type serves as the storage of 0-sized `AK::Array`s. While zero-length `T[0]`
|
||||
// is accepted as a GNU extension, it causes problems with UBSan in Clang 16.
|
||||
template<typename T>
|
||||
struct EmptyArrayStorage {
|
||||
T& operator[](size_t) const { VERIFY_NOT_REACHED(); }
|
||||
constexpr operator T*() const { return nullptr; }
|
||||
};
|
||||
}
|
||||
|
||||
template<typename T, size_t Size>
|
||||
struct Array {
|
||||
using ValueType = T;
|
||||
|
@ -109,7 +119,7 @@ struct Array {
|
|||
return value;
|
||||
}
|
||||
|
||||
T __data[Size];
|
||||
Conditional<Size == 0, Detail::EmptyArrayStorage<T>, T[Size]> __data;
|
||||
};
|
||||
|
||||
template<typename T, typename... Types>
|
||||
|
|
Loading…
Reference in a new issue