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

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 21 23:06:58 PDT 2017

rjmccall added inline comments.

Comment at: lib/CodeGen/CGExpr.cpp:1323
+  if (result.HasSideEffects && !AllowSideEffects) {
+    assert(!isa<DeclRefExpr>(E) && "declrefs should not have side effects");
     return ConstantEmission();
The side effects here are those associated with the initializer of the referenced declaration, not the DRE itself.  Some expressions can be constant-evaluated despite having side-effects because the side-effects occur in an ignored operand, like the LHS of a comma or the base of a MemberExpr that refers to a static member.

We can't allow side effects here because (1) we're not actually collecting the side-effectful expressions to emit and (2) we'd need some permission from the context to decide that we're allowed to do so anyway (with a lambda capture, those side-effects have actually already been emitted, but I'm not convinced that's always true).

On the other hand, I think we need to be able to emit MemberExprs to static members as constants despite the presence of side-effects in their base expressions, and I can't think of any reasonable way to do that except actually making a temporary DeclRefExpr to try to constant-emit instead.



More information about the cfe-commits mailing list