[PATCH] D36876: [IRGen] Evaluate constant static variables referenced through member expressions

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 18 10:45:01 PDT 2017

rsmith added inline comments.

Comment at: lib/CodeGen/CGExprComplex.cpp:156
+    auto Constant = tryEmitDeclRefOrMemberExprAsConstant(
+        ME, ME->getMemberDecl(), /*AllowSideEffects=*/true);
+    if (Constant) {
If we can (correctly) allow side-effects in the initializer here, why can we not also do so when emitting a `DeclRefExpr`?

Comment at: lib/CodeGen/CGExprScalar.cpp:1314-1321
+  } else {
+    // Fields can evaluate to constants if their base can be evaluated.
+    llvm::APSInt Value;
+    if (E->EvaluateAsInt(Value, CGF.getContext(), Expr::SE_AllowSideEffects))
+      V = Builder.getInt(Value);
+    else
+      V = nullptr;
Can we remove this and just use `tryEmit...` unconditionally?



More information about the cfe-commits mailing list