Files
clang-p2996/clang/lib/CIR/CodeGen/TargetInfo.cpp
Andres-Salamanca bd36f7331a [CIR] Add initial support for bitfields in structs (#142041)
This change adds support for bitfields CIR records can now contain bit
fields.

I’ve updated the `CIRGenBitFieldInfo` comment, which originally came
from the incubator and was identical to the one in OGCodeGen, to better
reflect the current implementation.

Support for bitfields in unions big-endian architectures and `get` and
`set` operations remains unimplemented and will be addressed in a future
patch.
2025-06-20 09:03:02 -05:00

73 lines
1.8 KiB
C++

#include "TargetInfo.h"
#include "ABIInfo.h"
using namespace clang;
using namespace clang::CIRGen;
bool clang::CIRGen::isEmptyRecordForLayout(const ASTContext &context,
QualType t) {
const RecordType *rt = t->getAs<RecordType>();
if (!rt)
return false;
const RecordDecl *rd = rt->getDecl();
// If this is a C++ record, check the bases first.
if (const CXXRecordDecl *cxxrd = dyn_cast<CXXRecordDecl>(rd)) {
if (cxxrd->isDynamicClass())
return false;
for (const auto &I : cxxrd->bases())
if (!isEmptyRecordForLayout(context, I.getType()))
return false;
}
for (const auto *I : rd->fields())
if (!isEmptyFieldForLayout(context, I))
return false;
return true;
}
bool clang::CIRGen::isEmptyFieldForLayout(const ASTContext &context,
const FieldDecl *fd) {
if (fd->isZeroLengthBitField())
return true;
if (fd->isUnnamedBitField())
return false;
return isEmptyRecordForLayout(context, fd->getType());
}
namespace {
class X8664ABIInfo : public ABIInfo {
public:
X8664ABIInfo(CIRGenTypes &cgt) : ABIInfo(cgt) {}
};
class X8664TargetCIRGenInfo : public TargetCIRGenInfo {
public:
X8664TargetCIRGenInfo(CIRGenTypes &cgt)
: TargetCIRGenInfo(std::make_unique<X8664ABIInfo>(cgt)) {}
};
} // namespace
std::unique_ptr<TargetCIRGenInfo>
clang::CIRGen::createX8664TargetCIRGenInfo(CIRGenTypes &cgt) {
return std::make_unique<X8664TargetCIRGenInfo>(cgt);
}
ABIInfo::~ABIInfo() noexcept = default;
bool TargetCIRGenInfo::isNoProtoCallVariadic(
const FunctionNoProtoType *fnType) const {
// The following conventions are known to require this to be false:
// x86_stdcall
// MIPS
// For everything else, we just prefer false unless we opt out.
return false;
}