1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/ABI/Types.h"
10#include "llvm/Support/Casting.h"
11
12using namespace llvm;
13using namespace llvm::abi;
14
15bool RecordType::isEmpty() const {
16 if (hasFlexibleArrayMember() || isPolymorphic() ||
17 getNumVirtualBaseClasses() != 0)
18 return false;
19
20 for (const FieldInfo &Base : getBaseClasses()) {
21 const auto *BaseRT = dyn_cast<RecordType>(Val: Base.FieldType);
22 if (!BaseRT || !BaseRT->isEmpty())
23 return false;
24 }
25
26 for (const FieldInfo &FI : getFields()) {
27 if (!FI.isEmpty())
28 return false;
29 }
30 return true;
31}
32
33bool FieldInfo::isEmpty() const {
34 if (IsUnnamedBitfield)
35 return true;
36 if (IsBitField && BitFieldWidth == 0)
37 return true;
38
39 const Type *Ty = FieldType;
40 while (const auto *AT = dyn_cast<ArrayType>(Val: Ty)) {
41 if (AT->getNumElements() != 1)
42 break;
43 Ty = AT->getElementType();
44 }
45
46 if (const auto *RT = dyn_cast<RecordType>(Val: Ty))
47 return RT->isEmpty();
48
49 return Ty->isZeroSize();
50}
51