<div dir="ltr">On Tue, Jun 4, 2013 at 5:46 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard-llvm@metafoo.co.uk" target="_blank">richard-llvm@metafoo.co.uk</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rsmith<br>
Date: Tue Jun 4 19:46:14 2013<br>
New Revision: 183283<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=183283&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=183283&view=rev</a><br>
Log:<br>
Model temporary lifetime-extension explicitly in the AST. Use this model to<br>
handle temporaries which have been lifetime-extended to static storage duration<br>
within constant expressions. This correctly handles nested lifetime extension<br>
(through reference members of aggregates in aggregate initializers) but<br>
non-constant-expression emission hasn't yet been updated to do the same.<br>
<br>
Modified:<br>
cfe/trunk/include/clang/AST/ASTContext.h<br>
cfe/trunk/include/clang/AST/Decl.h<br>
cfe/trunk/include/clang/AST/ExprCXX.h<br>
cfe/trunk/include/clang/AST/Stmt.h<br>
cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td<br>
cfe/trunk/include/clang/Basic/Specifiers.h<br>
cfe/trunk/include/clang/Sema/Initialization.h<br>
cfe/trunk/lib/AST/ASTContext.cpp<br>
cfe/trunk/lib/AST/ASTDumper.cpp<br>
cfe/trunk/lib/AST/ExprConstant.cpp<br>
cfe/trunk/lib/CodeGen/CGExprConstant.cpp<br>
cfe/trunk/lib/CodeGen/CodeGenModule.cpp<br>
cfe/trunk/lib/CodeGen/CodeGenModule.h<br>
cfe/trunk/lib/Sema/SemaExpr.cpp<br>
cfe/trunk/lib/Sema/SemaInit.cpp<br>
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp<br>
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp<br>
cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp<br>
cfe/trunk/test/CodeGenCXX/const-init-cxx1y.cpp<br>
cfe/trunk/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp<br>
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp<br>
cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp<br>
<br>
Modified: cfe/trunk/include/clang/AST/ASTContext.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=183283&r1=183282&r2=183283&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=183283&r1=183282&r2=183283&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/ASTContext.h (original)<br>
+++ cfe/trunk/include/clang/AST/ASTContext.h Tue Jun 4 19:46:14 2013<br>
@@ -55,6 +55,7 @@ namespace clang {<br>
class ExternalASTSource;<br>
class ASTMutationListener;<br>
class IdentifierTable;<br>
+ class MaterializeTemporaryExpr;<br>
class SelectorTable;<br>
class TargetInfo;<br>
class CXXABI;<br>
@@ -163,6 +164,11 @@ class ASTContext : public RefCountedBase<br>
llvm::DenseMap<const FunctionDecl*, FunctionDecl*><br>
ClassScopeSpecializationPattern;<br>
<br>
+ /// \brief Mapping from materialized temporaries with static storage duration<br>
+ /// that appear in constant initializers to their evaluated values.<br>
+ llvm::DenseMap<const MaterializeTemporaryExpr*, APValue><br>
+ MaterializedTemporaryValues;<br>
+<br>
/// \brief Representation of a "canonical" template template parameter that<br>
/// is used in canonical template names.<br>
class CanonicalTemplateTemplateParm : public llvm::FoldingSetNode {<br>
@@ -2117,7 +2123,12 @@ public:<br>
/// \brief Used by ParmVarDecl to retrieve on the side the<br>
/// index of the parameter when it exceeds the size of the normal bitfield.<br>
unsigned getParameterIndex(const ParmVarDecl *D) const;<br>
-<br>
+<br>
+ /// \brief Get the storage for the constant value of a materialized temporary<br>
+ /// of static storage duration.<br>
+ APValue *getMaterializedTemporaryValue(const MaterializeTemporaryExpr *E,<br>
+ bool MayCreate);<br><br></blockquote><div><br></div><div>Having a global table of temporary values seems really fragile given the ability to modify the values of the temporaries in C++1y. (const-init-cxx1y.cpp happens to work given the precise order we call into the constant evaluator, but could easily break if we change how we do CodeGen.) Have you given any thought to this?</div>
<div><br></div><div>-Eli</div></div></div></div>