diff options
-rw-r--r-- | include/clang/AST/Expr.h | 11 | ||||
-rw-r--r-- | include/clang/Frontend/PCHBitCodes.h | 3 | ||||
-rw-r--r-- | lib/Frontend/PCHReader.cpp | 13 | ||||
-rw-r--r-- | lib/Frontend/PCHWriter.cpp | 9 | ||||
-rw-r--r-- | test/PCH/exprs.c | 4 | ||||
-rw-r--r-- | test/PCH/exprs.h | 3 |
6 files changed, 40 insertions, 3 deletions
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index fbe2953300..9936965bbb 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -1137,13 +1137,20 @@ public: : Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init), FileScope(fileScope) {} + /// \brief Construct an empty compound literal. + explicit CompoundLiteralExpr(EmptyShell Empty) + : Expr(CompoundLiteralExprClass, Empty) { } + const Expr *getInitializer() const { return cast<Expr>(Init); } Expr *getInitializer() { return cast<Expr>(Init); } + void setInitializer(Expr *E) { Init = E; } bool isFileScope() const { return FileScope; } - + void setFileScope(bool FS) { FileScope = FS; } + SourceLocation getLParenLoc() const { return LParenLoc; } - + void setLParenLoc(SourceLocation L) { LParenLoc = L; } + virtual SourceRange getSourceRange() const { // FIXME: Init should never be null. if (!Init) diff --git a/include/clang/Frontend/PCHBitCodes.h b/include/clang/Frontend/PCHBitCodes.h index 6a75245b80..a4a0675df0 100644 --- a/include/clang/Frontend/PCHBitCodes.h +++ b/include/clang/Frontend/PCHBitCodes.h @@ -419,7 +419,8 @@ namespace clang { EXPR_IMPLICIT_CAST, /// \brief A CStyleCastExpr record. EXPR_CSTYLE_CAST, - /// FIXME: CompoundLiteralExpr + /// \brief A CompoundLiteralExpr record. + EXPR_COMPOUND_LITERAL, /// \brief An ExtVectorElementExpr record. EXPR_EXT_VECTOR_ELEMENT, /// \brief An InitListExpr record. diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp index 2da35a09d6..e24a155146 100644 --- a/lib/Frontend/PCHReader.cpp +++ b/lib/Frontend/PCHReader.cpp @@ -257,6 +257,7 @@ namespace { unsigned VisitImplicitCastExpr(ImplicitCastExpr *E); unsigned VisitExplicitCastExpr(ExplicitCastExpr *E); unsigned VisitCStyleCastExpr(CStyleCastExpr *E); + unsigned VisitCompoundLiteralExpr(CompoundLiteralExpr *E); unsigned VisitExtVectorElementExpr(ExtVectorElementExpr *E); unsigned VisitInitListExpr(InitListExpr *E); unsigned VisitDesignatedInitExpr(DesignatedInitExpr *E); @@ -447,6 +448,14 @@ unsigned PCHStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) { return 1; } +unsigned PCHStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { + VisitExpr(E); + E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setInitializer(ExprStack.back()); + E->setFileScope(Record[Idx++]); + return 1; +} + unsigned PCHStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) { VisitExpr(E); E->setBase(ExprStack.back()); @@ -2103,6 +2112,10 @@ Expr *PCHReader::ReadExpr() { E = new (Context) CStyleCastExpr(Empty); break; + case pch::EXPR_COMPOUND_LITERAL: + E = new (Context) CompoundLiteralExpr(Empty); + break; + case pch::EXPR_EXT_VECTOR_ELEMENT: E = new (Context) ExtVectorElementExpr(Empty); break; diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp index f96288864b..c89e3546bf 100644 --- a/lib/Frontend/PCHWriter.cpp +++ b/lib/Frontend/PCHWriter.cpp @@ -464,6 +464,7 @@ namespace { void VisitImplicitCastExpr(ImplicitCastExpr *E); void VisitExplicitCastExpr(ExplicitCastExpr *E); void VisitCStyleCastExpr(CStyleCastExpr *E); + void VisitCompoundLiteralExpr(CompoundLiteralExpr *E); void VisitExtVectorElementExpr(ExtVectorElementExpr *E); void VisitInitListExpr(InitListExpr *E); void VisitDesignatedInitExpr(DesignatedInitExpr *E); @@ -647,6 +648,14 @@ void PCHStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) { Code = pch::EXPR_CSTYLE_CAST; } +void PCHStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { + VisitExpr(E); + Writer.AddSourceLocation(E->getLParenLoc(), Record); + Writer.WriteSubExpr(E->getInitializer()); + Record.push_back(E->isFileScope()); + Code = pch::EXPR_COMPOUND_LITERAL; +} + void PCHStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) { VisitExpr(E); Writer.WriteSubExpr(E->getBase()); diff --git a/test/PCH/exprs.c b/test/PCH/exprs.c index e08024b9bb..ced6d178b4 100644 --- a/test/PCH/exprs.c +++ b/test/PCH/exprs.c @@ -61,6 +61,10 @@ conditional_operator *double_ptr4 = &floating; // CStyleCastExpr void_ptr vp1 = &integer; +// CompoundLiteral +struct S s; +compound_literal *sptr = &s; + // ExtVectorElementExpr ext_vector_element *double_ptr5 = &floating; diff --git a/test/PCH/exprs.h b/test/PCH/exprs.h index 43fd89595e..7012422aad 100644 --- a/test/PCH/exprs.h +++ b/test/PCH/exprs.h @@ -56,6 +56,9 @@ typedef typeof(i? : d0) conditional_operator; // CStyleCastExpr typedef typeof((void *)0) void_ptr; +// CompoundLiteral +typedef typeof((struct S){.x = 3.5}) compound_literal; + // ExtVectorElementExpr typedef __attribute__(( ext_vector_type(2) )) double double2; extern double2 vec2, vec2b; |