[PATCH] D46241: [CodeGen] Recognize more cases of zero initialization

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 10 14:53:19 PDT 2018


rsmith added inline comments.


================
Comment at: lib/CodeGen/CGExprConstant.cpp:1414-1415
+    Expr::EvalResult Result;
+    if (Init->EvaluateAsRValue(Result, CE.CGM.getContext()) &&
+        !Result.hasUnacceptableSideEffect(Expr::SE_NoSideEffects))
+      return (Result.Val.isInt() && Result.Val.getInt().isNullValue()) ||
----------------
Please call `D.evaluateValue()` here rather than inventing your own evaluation scheme. That way, we'll cache the evaluated initializer on the variable for other uses or reuse the value if we've already evaluated it, and you don't need to worry about the corner cases involved in getting the evaluation right. (As it happens, you're getting some minor details wrong because evaluating an initializer is not quite the same as evaluating an rvalue, but in practice it's not a big deal here.)


Repository:
  rC Clang

https://reviews.llvm.org/D46241





More information about the cfe-commits mailing list