nlewycky created this revision.
Make ObjCBoxedExpr less of a special case, teach the expression evaluator to
handle it in general, sometimes descending through to its subexpr. Remove the
code that called CheckForIntOverflow from outside BuildObjCBoxedExpr, leaving
its only caller CheckCompletedExpr.
To make the existing tests continue to work, we also need to whitelist
ObjCBoxedExpr as a top-level expression in CheckForIntOverflow. Ultimately that
we shouldn't need to whitelist, but one piece at a time.
https://reviews.llvm.org/D32410
Files:
lib/AST/ExprConstant.cpp
lib/Sema/SemaChecking.cpp
lib/Sema/SemaExprObjC.cpp
Index: lib/Sema/SemaExprObjC.cpp
===================================================================
--- lib/Sema/SemaExprObjC.cpp
+++ lib/Sema/SemaExprObjC.cpp
@@ -595,7 +595,6 @@
break;
}
}
- CheckForIntOverflow(ValueExpr);
// FIXME: Do I need to do anything special with BoolTy expressions?
// Look for the appropriate method within NSNumber.
Index: lib/Sema/SemaChecking.cpp
===================================================================
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -9882,6 +9882,9 @@
if (auto InitList = dyn_cast<InitListExpr>(E))
Exprs.append(InitList->inits().begin(), InitList->inits().end());
+
+ if (isa<ObjCBoxedExpr>(E))
+ E->IgnoreParenCasts()->EvaluateForOverflow(Context);
} while (!Exprs.empty());
}
Index: lib/AST/ExprConstant.cpp
===================================================================
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -4466,6 +4466,8 @@
{ return StmtVisitorTy::Visit(E->getSubExpr()); }
bool VisitUnaryPlus(const UnaryOperator *E)
{ return StmtVisitorTy::Visit(E->getSubExpr()); }
+ bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E)
+ { return StmtVisitorTy::Visit(E->getSubExpr()); }
bool VisitChooseExpr(const ChooseExpr *E)
{ return StmtVisitorTy::Visit(E->getChosenSubExpr()); }
bool VisitGenericSelectionExpr(const GenericSelectionExpr *E)
@@ -5471,7 +5473,26 @@
bool VisitObjCStringLiteral(const ObjCStringLiteral *E)
{ return Success(E); }
bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E)
- { return Success(E); }
+ {
+ // Should we continue evaluation after determining the result value?
+ switch (Info.EvalMode) {
+ case EvalInfo::EM_PotentialConstantExpression:
+ case EvalInfo::EM_PotentialConstantExpressionUnevaluated:
+ case EvalInfo::EM_EvaluateForOverflow:
+ case EvalInfo::EM_IgnoreSideEffects:
+ if (!E->getSubExpr()->isValueDependent()) {
+ APValue Discard;
+ Evaluate(Discard, Info, E->getSubExpr());
+ }
+
+ case EvalInfo::EM_ConstantExpression:
+ case EvalInfo::EM_ConstantExpressionUnevaluated:
+ case EvalInfo::EM_ConstantFold:
+ case EvalInfo::EM_OffsetFold:
+ return Success(E);
+ }
+ llvm_unreachable("Missed EvalMode case");
+ }
bool VisitAddrLabelExpr(const AddrLabelExpr *E)
{ return Success(E); }
bool VisitCallExpr(const CallExpr *E);
Index: lib/Sema/SemaExprObjC.cpp
===================================================================
--- lib/Sema/SemaExprObjC.cpp
+++ lib/Sema/SemaExprObjC.cpp
@@ -595,7 +595,6 @@
break;
}
}
- CheckForIntOverflow(ValueExpr);
// FIXME: Do I need to do anything special with BoolTy expressions?
// Look for the appropriate method within NSNumber.
Index: lib/Sema/SemaChecking.cpp
===================================================================
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -9882,6 +9882,9 @@
if (auto InitList = dyn_cast<InitListExpr>(E))
Exprs.append(InitList->inits().begin(), InitList->inits().end());
+
+ if (isa<ObjCBoxedExpr>(E))
+ E->IgnoreParenCasts()->EvaluateForOverflow(Context);
} while (!Exprs.empty());
}
Index: lib/AST/ExprConstant.cpp
===================================================================
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -4466,6 +4466,8 @@
{ return StmtVisitorTy::Visit(E->getSubExpr()); }
bool VisitUnaryPlus(const UnaryOperator *E)
{ return StmtVisitorTy::Visit(E->getSubExpr()); }
+ bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E)
+ { return StmtVisitorTy::Visit(E->getSubExpr()); }
bool VisitChooseExpr(const ChooseExpr *E)
{ return StmtVisitorTy::Visit(E->getChosenSubExpr()); }
bool VisitGenericSelectionExpr(const GenericSelectionExpr *E)
@@ -5471,7 +5473,26 @@
bool VisitObjCStringLiteral(const ObjCStringLiteral *E)
{ return Success(E); }
bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E)
- { return Success(E); }
+ {
+ // Should we continue evaluation after determining the result value?
+ switch (Info.EvalMode) {
+ case EvalInfo::EM_PotentialConstantExpression:
+ case EvalInfo::EM_PotentialConstantExpressionUnevaluated:
+ case EvalInfo::EM_EvaluateForOverflow:
+ case EvalInfo::EM_IgnoreSideEffects:
+ if (!E->getSubExpr()->isValueDependent()) {
+ APValue Discard;
+ Evaluate(Discard, Info, E->getSubExpr());
+ }
+
+ case EvalInfo::EM_ConstantExpression:
+ case EvalInfo::EM_ConstantExpressionUnevaluated:
+ case EvalInfo::EM_ConstantFold:
+ case EvalInfo::EM_OffsetFold:
+ return Success(E);
+ }
+ llvm_unreachable("Missed EvalMode case");
+ }
bool VisitAddrLabelExpr(const AddrLabelExpr *E)
{ return Success(E); }
bool VisitCallExpr(const CallExpr *E);
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits