When a variable is named in a context where we can't directly emit a
reference to it (because we don't know for sure that it's going to be
defined, or it's from an enclosing function and not captured, or the
reference might not "work" for some reason), we emit a copy of the
variable as a global and use that for the known-to-be-read-only access.
Details
- Reviewers
rjmccall - Commits
- rG24cdcadcc5e8: C++ DR712 and others: handle non-odr-use resulting from an lvalue-to-rvalue…
rL363428: C++ DR712 and others: handle non-odr-use resulting from an lvalue-to-rvalue…
rC363428: C++ DR712 and others: handle non-odr-use resulting from an lvalue-to-rvalue…
rG17965d42f420: C++ DR712 and others: handle non-odr-use resulting from an lvalue-to-rvalue…
rC363295: C++ DR712 and others: handle non-odr-use resulting from an lvalue-to-rvalue…
rL363295: C++ DR712 and others: handle non-odr-use resulting from an lvalue-to-rvalue…
Diff Detail
- Repository
- rL LLVM
Event Timeline
lib/CodeGen/CGExpr.cpp | ||
---|---|---|
1429 ↗ | (On Diff #204131) | Isn't the old comment correct here? This is mandatory because of the enclosing-local-scope issues; that might be an "optimization" in the language, but it's not an optimization at the IRGen level because Sema literally is forcing us to do it. |
lib/Sema/SemaExpr.cpp | ||
15808 ↗ | (On Diff #204131) | This is really cute; I might steal this idea. That said, it's probably worth explaining the lifetime mechanics here so that non-experts can understand how this works. |
lib/CodeGen/CGExpr.cpp | ||
---|---|---|
1429 ↗ | (On Diff #204131) | In the absence of this code, we'd emit the variable as a global constant from EmitDeclRefLValue in the enclosing-local-scope case (as we now do in the more-complex cases), so this should never be necessary for correct code generation any more. |
lib/Sema/SemaExpr.cpp | ||
15808 ↗ | (On Diff #204131) | Done. I also added a [[clang::lifetimebound]] attribute so we'll get a warning if this is misused. |
Minor comment request, then LGTM.
lib/CodeGen/CGDecl.cpp | ||
---|---|---|
1102 ↗ | (On Diff #204589) | I don't think this cache is LRU in any meaningful sense; it just grows unbounded. There's this thing about requiring the initializer to match, but that's not LRU. |
lib/CodeGen/CGExpr.cpp | ||
1429 ↗ | (On Diff #204131) | Hmm, alright. |