Skip to content

Commit 62c31af

Browse files
committed
[CIR][CIRGen][NFC] More skeleton for unimplemented lvalue pieces
1 parent 4aff677 commit 62c31af

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,25 @@ static Address buildAddrOfFieldStorage(CIRGenFunction &CGF, Address Base,
7171
return addr;
7272
}
7373

74+
static bool hasAnyVptr(const QualType Type, const ASTContext &Context) {
75+
const auto *RD = Type.getTypePtr()->getAsCXXRecordDecl();
76+
if (!RD)
77+
return false;
78+
79+
if (RD->isDynamicClass())
80+
return true;
81+
82+
for (const auto &Base : RD->bases())
83+
if (hasAnyVptr(Base.getType(), Context))
84+
return true;
85+
86+
for (const FieldDecl *Field : RD->fields())
87+
if (hasAnyVptr(Field->getType(), Context))
88+
return true;
89+
90+
return false;
91+
}
92+
7493
LValue CIRGenFunction::buildLValueForField(LValue base,
7594
const FieldDecl *field) {
7695
LValueBaseInfo BaseInfo = base.getBaseInfo();
@@ -87,10 +106,9 @@ LValue CIRGenFunction::buildLValueForField(LValue base,
87106
LValueBaseInfo FieldBaseInfo(getFieldAlignmentSource(BaseAlignSource));
88107
if (UnimplementedFeature::tbaa() || rec->hasAttr<MayAliasAttr>() ||
89108
FieldType->isVectorType()) {
90-
// TODO(CIR): TBAAAccessInfo FieldTBAAInfo
91-
llvm_unreachable("NYI");
109+
assert(!UnimplementedFeature::tbaa() && "NYI");
92110
} else if (rec->isUnion()) {
93-
llvm_unreachable("NYI");
111+
assert(!UnimplementedFeature::tbaa() && "NYI");
94112
} else {
95113
// If no base type been assigned for the base access, then try to generate
96114
// one for this base lvalue.
@@ -107,7 +125,20 @@ LValue CIRGenFunction::buildLValueForField(LValue base,
107125

108126
unsigned RecordCVR = base.getVRQualifiers();
109127
if (rec->isUnion()) {
110-
llvm_unreachable("NYI");
128+
// For unions, there is no pointer adjustment.
129+
if (CGM.getCodeGenOpts().StrictVTablePointers &&
130+
hasAnyVptr(FieldType, getContext()))
131+
// Because unions can easily skip invariant.barriers, we need to add
132+
// a barrier every time CXXRecord field with vptr is referenced.
133+
assert(!UnimplementedFeature::createLaunderInvariantGroup());
134+
135+
if (IsInPreservedAIRegion ||
136+
(getDebugInfo() && rec->hasAttr<BPFPreserveAccessIndexAttr>())) {
137+
assert(!UnimplementedFeature::generateDebugInfo());
138+
}
139+
140+
if (FieldType->isReferenceType())
141+
llvm_unreachable("NYI");
111142
} else {
112143
if (!IsInPreservedAIRegion &&
113144
(!getDebugInfo() || !rec->hasAttr<BPFPreserveAccessIndexAttr>())) {

clang/lib/CIR/CodeGen/UnimplementedFeatureGuarding.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct UnimplementedFeature {
7878
static bool armComputeVolatileBitfields() { return false; }
7979
static bool setCommonAttributes() { return false; }
8080
static bool insertBuiltinUnpredictable() { return false; }
81+
static bool createLaunderInvariantGroup() { return false; }
8182
};
8283
} // namespace cir
8384

0 commit comments

Comments
 (0)