r183283 - Model temporary lifetime-extension explicitly in the AST. Use this model to

Eli Friedman eli.friedman at gmail.com
Sun Jun 30 18:39:24 PDT 2013


On Tue, Jun 4, 2013 at 5:46 PM, Richard Smith <richard-llvm at metafoo.co.uk>wrote:

> Author: rsmith
> Date: Tue Jun  4 19:46:14 2013
> New Revision: 183283
>
> URL: http://llvm.org/viewvc/llvm-project?rev=183283&view=rev
> Log:
> Model temporary lifetime-extension explicitly in the AST. Use this model to
> handle temporaries which have been lifetime-extended to static storage
> duration
> within constant expressions. This correctly handles nested lifetime
> extension
> (through reference members of aggregates in aggregate initializers) but
> non-constant-expression emission hasn't yet been updated to do the same.
>
> Modified:
>     cfe/trunk/include/clang/AST/ASTContext.h
>     cfe/trunk/include/clang/AST/Decl.h
>     cfe/trunk/include/clang/AST/ExprCXX.h
>     cfe/trunk/include/clang/AST/Stmt.h
>     cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
>     cfe/trunk/include/clang/Basic/Specifiers.h
>     cfe/trunk/include/clang/Sema/Initialization.h
>     cfe/trunk/lib/AST/ASTContext.cpp
>     cfe/trunk/lib/AST/ASTDumper.cpp
>     cfe/trunk/lib/AST/ExprConstant.cpp
>     cfe/trunk/lib/CodeGen/CGExprConstant.cpp
>     cfe/trunk/lib/CodeGen/CodeGenModule.cpp
>     cfe/trunk/lib/CodeGen/CodeGenModule.h
>     cfe/trunk/lib/Sema/SemaExpr.cpp
>     cfe/trunk/lib/Sema/SemaInit.cpp
>     cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
>     cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
>     cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp
>     cfe/trunk/test/CodeGenCXX/const-init-cxx1y.cpp
>     cfe/trunk/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
>     cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
>     cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp
>
> Modified: cfe/trunk/include/clang/AST/ASTContext.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=183283&r1=183282&r2=183283&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/AST/ASTContext.h (original)
> +++ cfe/trunk/include/clang/AST/ASTContext.h Tue Jun  4 19:46:14 2013
> @@ -55,6 +55,7 @@ namespace clang {
>    class ExternalASTSource;
>    class ASTMutationListener;
>    class IdentifierTable;
> +  class MaterializeTemporaryExpr;
>    class SelectorTable;
>    class TargetInfo;
>    class CXXABI;
> @@ -163,6 +164,11 @@ class ASTContext : public RefCountedBase
>    llvm::DenseMap<const FunctionDecl*, FunctionDecl*>
>      ClassScopeSpecializationPattern;
>
> +  /// \brief Mapping from materialized temporaries with static storage
> duration
> +  /// that appear in constant initializers to their evaluated values.
> +  llvm::DenseMap<const MaterializeTemporaryExpr*, APValue>
> +    MaterializedTemporaryValues;
> +
>    /// \brief Representation of a "canonical" template template parameter
> that
>    /// is used in canonical template names.
>    class CanonicalTemplateTemplateParm : public llvm::FoldingSetNode {
> @@ -2117,7 +2123,12 @@ public:
>    /// \brief Used by ParmVarDecl to retrieve on the side the
>    /// index of the parameter when it exceeds the size of the normal
> bitfield.
>    unsigned getParameterIndex(const ParmVarDecl *D) const;
> -
> +
> +  /// \brief Get the storage for the constant value of a materialized
> temporary
> +  /// of static storage duration.
> +  APValue *getMaterializedTemporaryValue(const MaterializeTemporaryExpr
> *E,
> +                                         bool MayCreate);
>
>
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?

-Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130630/8f837837/attachment.html>


More information about the cfe-commits mailing list