@@ -3218,9 +3218,18 @@ bool ByteCodeExprGen<Emitter>::visitAPValue(const APValue &Val,
3218
3218
return this ->emitConst (Val.getInt (), ValType, E);
3219
3219
3220
3220
if (Val.isLValue ()) {
3221
+ if (Val.isNullPointer ())
3222
+ return this ->emitNull (ValType, nullptr , E);
3221
3223
APValue::LValueBase Base = Val.getLValueBase ();
3222
3224
if (const Expr *BaseExpr = Base.dyn_cast <const Expr *>())
3223
3225
return this ->visit (BaseExpr);
3226
+ else if (const auto *VD = Base.dyn_cast <const ValueDecl *>()) {
3227
+ return this ->visitDeclRef (VD, E);
3228
+ }
3229
+ } else if (Val.isMemberPointer ()) {
3230
+ if (const ValueDecl *MemberDecl = Val.getMemberPointerDecl ())
3231
+ return this ->emitGetMemberPtr (MemberDecl, E);
3232
+ return this ->emitNullMemberPtr (nullptr , E);
3224
3233
}
3225
3234
3226
3235
return false ;
@@ -3229,15 +3238,15 @@ bool ByteCodeExprGen<Emitter>::visitAPValue(const APValue &Val,
3229
3238
template <class Emitter >
3230
3239
bool ByteCodeExprGen<Emitter>::visitAPValueInitializer(const APValue &Val,
3231
3240
const Expr *E) {
3241
+
3232
3242
if (Val.isStruct ()) {
3233
3243
const Record *R = this ->getRecord (E->getType ());
3234
3244
assert (R);
3235
-
3236
3245
for (unsigned I = 0 , N = Val.getStructNumFields (); I != N; ++I) {
3237
3246
const APValue &F = Val.getStructField (I);
3238
3247
const Record::Field *RF = R->getField (I);
3239
3248
3240
- if (F.isInt () || F.isLValue ()) {
3249
+ if (F.isInt () || F.isLValue () || F. isMemberPointer () ) {
3241
3250
PrimType T = classifyPrim (RF->Decl ->getType ());
3242
3251
if (!this ->visitAPValue (F, T, E))
3243
3252
return false ;
@@ -3263,11 +3272,30 @@ bool ByteCodeExprGen<Emitter>::visitAPValueInitializer(const APValue &Val,
3263
3272
3264
3273
if (!this ->emitPopPtr (E))
3265
3274
return false ;
3275
+ } else if (F.isStruct () || F.isUnion ()) {
3276
+ if (!this ->emitDupPtr (E))
3277
+ return false ;
3278
+ if (!this ->emitGetPtrField (RF->Offset , E))
3279
+ return false ;
3280
+ if (!this ->visitAPValueInitializer (F, E))
3281
+ return false ;
3282
+ if (!this ->emitPopPtr (E))
3283
+ return false ;
3266
3284
} else {
3267
3285
assert (false && " I don't think this should be possible" );
3268
3286
}
3269
3287
}
3270
3288
return true ;
3289
+ } else if (Val.isUnion ()) {
3290
+ const FieldDecl *UnionField = Val.getUnionField ();
3291
+ const Record *R = this ->getRecord (UnionField->getParent ());
3292
+ assert (R);
3293
+ const APValue &F = Val.getUnionValue ();
3294
+ const Record::Field *RF = R->getField (UnionField);
3295
+ PrimType T = classifyPrim (RF->Decl ->getType ());
3296
+ if (!this ->visitAPValue (F, T, E))
3297
+ return false ;
3298
+ return this ->emitInitElem (T, 0 , E);
3271
3299
}
3272
3300
// TODO: Other types.
3273
3301
@@ -3827,12 +3855,10 @@ bool ByteCodeExprGen<Emitter>::VisitComplexUnaryOperator(
3827
3855
}
3828
3856
3829
3857
template <class Emitter >
3830
- bool ByteCodeExprGen<Emitter>::VisitDeclRefExpr (const DeclRefExpr *E) {
3858
+ bool ByteCodeExprGen<Emitter>::visitDeclRef (const ValueDecl *D, const Expr *E) {
3831
3859
if (DiscardResult)
3832
3860
return true ;
3833
3861
3834
- const auto *D = E->getDecl ();
3835
-
3836
3862
if (const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
3837
3863
return this ->emitConst (ECD->getInitVal (), E);
3838
3864
} else if (const auto *BD = dyn_cast<BindingDecl>(D)) {
@@ -3900,7 +3926,7 @@ bool ByteCodeExprGen<Emitter>::VisitDeclRefExpr(const DeclRefExpr *E) {
3900
3926
if (!this ->visitVarDecl (VD))
3901
3927
return false ;
3902
3928
// Retry.
3903
- return this ->VisitDeclRefExpr ( E);
3929
+ return this ->visitDeclRef (VD, E);
3904
3930
}
3905
3931
}
3906
3932
} else {
@@ -3910,7 +3936,7 @@ bool ByteCodeExprGen<Emitter>::VisitDeclRefExpr(const DeclRefExpr *E) {
3910
3936
if (!this ->visitVarDecl (VD))
3911
3937
return false ;
3912
3938
// Retry.
3913
- return this ->VisitDeclRefExpr ( E);
3939
+ return this ->visitDeclRef (VD, E);
3914
3940
}
3915
3941
}
3916
3942
@@ -3927,7 +3953,15 @@ bool ByteCodeExprGen<Emitter>::VisitDeclRefExpr(const DeclRefExpr *E) {
3927
3953
return true ;
3928
3954
}
3929
3955
3930
- return this ->emitInvalidDeclRef (E, E);
3956
+ if (const auto *DRE = dyn_cast<DeclRefExpr>(E))
3957
+ return this ->emitInvalidDeclRef (DRE, E);
3958
+ return false ;
3959
+ }
3960
+
3961
+ template <class Emitter >
3962
+ bool ByteCodeExprGen<Emitter>::VisitDeclRefExpr(const DeclRefExpr *E) {
3963
+ const auto *D = E->getDecl ();
3964
+ return this ->visitDeclRef (D, E);
3931
3965
}
3932
3966
3933
3967
template <class Emitter >
0 commit comments