@@ -71,6 +71,25 @@ static Address buildAddrOfFieldStorage(CIRGenFunction &CGF, Address Base,
71
71
return addr;
72
72
}
73
73
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
+
74
93
LValue CIRGenFunction::buildLValueForField (LValue base,
75
94
const FieldDecl *field) {
76
95
LValueBaseInfo BaseInfo = base.getBaseInfo ();
@@ -87,10 +106,9 @@ LValue CIRGenFunction::buildLValueForField(LValue base,
87
106
LValueBaseInfo FieldBaseInfo (getFieldAlignmentSource (BaseAlignSource));
88
107
if (UnimplementedFeature::tbaa () || rec->hasAttr <MayAliasAttr>() ||
89
108
FieldType->isVectorType ()) {
90
- // TODO(CIR): TBAAAccessInfo FieldTBAAInfo
91
- llvm_unreachable (" NYI" );
109
+ assert (!UnimplementedFeature::tbaa () && " NYI" );
92
110
} else if (rec->isUnion ()) {
93
- llvm_unreachable ( " NYI" );
111
+ assert (! UnimplementedFeature::tbaa () && " NYI" );
94
112
} else {
95
113
// If no base type been assigned for the base access, then try to generate
96
114
// one for this base lvalue.
@@ -107,7 +125,20 @@ LValue CIRGenFunction::buildLValueForField(LValue base,
107
125
108
126
unsigned RecordCVR = base.getVRQualifiers ();
109
127
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" );
111
142
} else {
112
143
if (!IsInPreservedAIRegion &&
113
144
(!getDebugInfo () || !rec->hasAttr <BPFPreserveAccessIndexAttr>())) {
0 commit comments