@@ -1170,27 +1170,30 @@ static bool interp__builtin_constant_p(InterpState &S, CodePtr OpPC,
11701170 Stk.clear ();
11711171 }
11721172
1173- const APValue &LV = Res.toAPValue ();
1174- if (!Res.isInvalid () && LV.isLValue ()) {
1175- APValue::LValueBase Base = LV.getLValueBase ();
1176- if (Base.isNull ()) {
1177- // A null base is acceptable.
1178- return returnInt (true );
1179- } else if (const auto *E = Base.dyn_cast <const Expr *>()) {
1180- if (!isa<StringLiteral>(E))
1173+ if (!Res.isInvalid () && !Res.empty ()) {
1174+ const APValue &LV = Res.toAPValue ();
1175+ if (LV.isLValue ()) {
1176+ APValue::LValueBase Base = LV.getLValueBase ();
1177+ if (Base.isNull ()) {
1178+ // A null base is acceptable.
1179+ return returnInt (true );
1180+ } else if (const auto *E = Base.dyn_cast <const Expr *>()) {
1181+ if (!isa<StringLiteral>(E))
1182+ return returnInt (false );
1183+ return returnInt (LV.getLValueOffset ().isZero ());
1184+ } else if (Base.is <TypeInfoLValue>()) {
1185+ // Surprisingly, GCC considers __builtin_constant_p(&typeid(int)) to
1186+ // evaluate to true.
1187+ return returnInt (true );
1188+ } else {
1189+ // Any other base is not constant enough for GCC.
11811190 return returnInt (false );
1182- return returnInt (LV.getLValueOffset ().isZero ());
1183- } else if (Base.is <TypeInfoLValue>()) {
1184- // Surprisingly, GCC considers __builtin_constant_p(&typeid(int)) to
1185- // evaluate to true.
1186- return returnInt (true );
1187- } else {
1188- // Any other base is not constant enough for GCC.
1189- return returnInt (false );
1191+ }
11901192 }
11911193 }
11921194
1193- return returnInt (!Res.isInvalid () && !Res.empty ());
1195+ // Otherwise, any constant value is good enough.
1196+ return returnInt (true );
11941197 }
11951198
11961199 return returnInt (false );
0 commit comments