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

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 2 10:39:25 PDT 2018


rjmccall added inline comments.


================
Comment at: lib/CodeGen/CGExprConstant.cpp:1403
+  if (auto *IL = dyn_cast_or_null<InitListExpr>(Init)) {
+    if (InitTy->isConstantArrayType()) {
+      for (auto I : IL->inits())
----------------
Do you actually care if it's an array initialization instead of a struct/enum initialization?


================
Comment at: lib/CodeGen/CGExprConstant.cpp:1413
+  } else if (!Init->isEvaluatable(CE.CGM.getContext())) {
+    return false;
+  } else if (InitTy->hasPointerRepresentation()) {
----------------
Aren't the null-pointer and integer-constant-expression checks below already checking this?  Also, `isEvaluatable` actually computes the full value internally (as an `APValue`), so if you're worried about the memory and compile-time effects of producing such a value, you really shouldn't call it.

You could reasonably move this entire function to be a method on `Expr` that takes an `ASTContext`.


================
Comment at: lib/CodeGen/CGExprConstant.cpp:1417
+    if (Init->EvaluateAsRValue(ResVal, CE.CGM.getContext()))
+      return ResVal.Val.isLValue() && ResVal.Val.isNullPointer();
+  } else {
----------------
There's a `isNullPointerConstant` method (you should use `NPC_NeverValueDependent`).


Repository:
  rC Clang

https://reviews.llvm.org/D46241





More information about the cfe-commits mailing list