@@ -40,7 +40,7 @@ void EvalEmitter::cleanup() { S.cleanup(); }
40
40
EvaluationResult EvalEmitter::interpretExpr (const Expr *E,
41
41
bool ConvertResultToRValue) {
42
42
S.setEvalLocation (E->getExprLoc ());
43
- this ->ConvertResultToRValue = ConvertResultToRValue;
43
+ this ->ConvertResultToRValue = ConvertResultToRValue && !isa<ConstantExpr>(E) ;
44
44
this ->CheckFullyInitialized = isa<ConstantExpr>(E);
45
45
EvalResult.setSource (E);
46
46
@@ -56,10 +56,14 @@ EvaluationResult EvalEmitter::interpretExpr(const Expr *E,
56
56
EvaluationResult EvalEmitter::interpretDecl (const VarDecl *VD,
57
57
bool CheckFullyInitialized) {
58
58
this ->CheckFullyInitialized = CheckFullyInitialized;
59
- this ->ConvertResultToRValue =
60
- VD->getAnyInitializer () &&
61
- (VD->getAnyInitializer ()->getType ()->isAnyComplexType () ||
62
- VD->getAnyInitializer ()->getType ()->isVectorType ());
59
+
60
+ if (const Expr *Init = VD->getAnyInitializer ()) {
61
+ QualType T = VD->getType ();
62
+ this ->ConvertResultToRValue = !Init->isGLValue () && !T->isPointerType () &&
63
+ !T->isObjCObjectPointerType ();
64
+ } else
65
+ this ->ConvertResultToRValue = false ;
66
+
63
67
EvalResult.setSource (VD);
64
68
65
69
if (!this ->visitDecl (VD) && EvalResult.empty ())
@@ -138,6 +142,10 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) {
138
142
return true ;
139
143
140
144
const Pointer &Ptr = S.Stk .pop <Pointer>();
145
+
146
+ if (CheckFullyInitialized && !EvalResult.checkFullyInitialized (S, Ptr ))
147
+ return false ;
148
+
141
149
// Implicitly convert lvalue to rvalue, if requested.
142
150
if (ConvertResultToRValue) {
143
151
if (std::optional<APValue> V = Ptr .toRValue (Ctx)) {
@@ -146,17 +154,7 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) {
146
154
return false ;
147
155
}
148
156
} else {
149
- if (CheckFullyInitialized) {
150
- if (!EvalResult.checkFullyInitialized (S, Ptr ))
151
- return false ;
152
-
153
- std::optional<APValue> RValueResult = Ptr .toRValue (Ctx);
154
- if (!RValueResult)
155
- return false ;
156
- EvalResult.setValue (*RValueResult);
157
- } else {
158
- EvalResult.setValue (Ptr .toAPValue ());
159
- }
157
+ EvalResult.setValue (Ptr .toAPValue ());
160
158
}
161
159
162
160
return true ;
0 commit comments