Index: lib/AST/ASTImporter.cpp =================================================================== --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -169,6 +169,9 @@ ClassTemplateSpecializationDecl *D); Decl *VisitVarTemplateDecl(VarTemplateDecl *D); Decl *VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); + Decl *VisitFriendDecl(FriendDecl *D); + Decl *VisitAccessSpecDecl(AccessSpecDecl *D); + Decl *VisitStaticAssertDecl(StaticAssertDecl *D); // Importing statements DeclGroupRef ImportDeclGroup(DeclGroupRef DG); @@ -211,20 +214,43 @@ Stmt *VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); // Importing expressions + bool ImportCastPath(CastExpr *E, CXXCastPath &Path); + Expr *VisitExpr(Expr *E); Expr *VisitDeclRefExpr(DeclRefExpr *E); Expr *VisitIntegerLiteral(IntegerLiteral *E); Expr *VisitCharacterLiteral(CharacterLiteral *E); + Expr *VisitStringLiteral(StringLiteral *E); + Expr *VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); + Expr *VisitFloatingLiteral(FloatingLiteral *E); + Expr *VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); + Expr *VisitCXXThisExpr(CXXThisExpr *E); + Expr *VisitCXXThrowExpr(CXXThrowExpr *E); + Expr *VisitCXXNewExpr(CXXNewExpr *E); + Expr *VisitCXXDeleteExpr(CXXDeleteExpr *E); Expr *VisitParenExpr(ParenExpr *E); Expr *VisitUnaryOperator(UnaryOperator *E); Expr *VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); + Expr *VisitArraySubscriptExpr(ArraySubscriptExpr *E); Expr *VisitBinaryOperator(BinaryOperator *E); Expr *VisitCompoundAssignOperator(CompoundAssignOperator *E); + Expr *VisitConditionalOperator(ConditionalOperator *E); Expr *VisitImplicitCastExpr(ImplicitCastExpr *E); Expr *VisitCStyleCastExpr(CStyleCastExpr *E); + Expr *VisitInitListExpr(InitListExpr *E); + Expr *VisitDesignatedInitExpr(DesignatedInitExpr *E); + Expr *VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); + Expr *VisitCXXStaticCastExpr(CXXStaticCastExpr *E); + Expr *VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E); + Expr *VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E); + Expr *VisitCXXConstCastExpr(CXXConstCastExpr *E); + Expr *VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E); Expr *VisitCXXConstructExpr(CXXConstructExpr *E); + Expr *VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); + Expr *VisitExprWithCleanups(ExprWithCleanups *E); Expr *VisitMemberExpr(MemberExpr *E); Expr *VisitCallExpr(CallExpr *E); + Expr *VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); }; } using namespace clang; @@ -4567,6 +4593,57 @@ return D2; } +Decl *ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { + ASTContext &Context = Importer.getToContext(); + DeclContext *DC = Importer.ImportContext(D->getDeclContext()); + if (!DC) + return nullptr; + + FriendDecl::FriendUnion FU; + if (TypeSourceInfo *TSInfo = D->getFriendType()) { + FU = Importer.Import(TSInfo); + } else { + Decl *NDecl = D->getFriendDecl(); + assert(NDecl); + NamedDecl *NewDecl = cast(Importer.Import(NDecl)); + NewDecl->setObjectOfFriendDecl(); + FU = NewDecl; + } + + FriendDecl *FDecl = FriendDecl::Create(Context, DC, + Importer.Import(D->getLocation()), FU, Importer.Import(D->getFriendLoc())); + FDecl->setAccess(D->getAccess()); + + Importer.Imported(D, FDecl); + return FDecl; +} + +Decl *ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { + ASTContext &Context = Importer.getToContext(); + DeclContext *DC = Importer.ImportContext(D->getDeclContext()); + if (!DC) + return nullptr; + + AccessSpecDecl *ASDecl = AccessSpecDecl::Create(Context, D->getAccess(), DC, + Importer.Import(D->getLocation()), Importer.Import(D->getColonLoc())); + Importer.Imported(D, ASDecl); + return ASDecl; +} + +Decl *ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { + DeclContext *DC = Importer.ImportContext(D->getDeclContext()); + SourceLocation Loc = Importer.Import(D->getLocation()); + Expr *AssertExpr = Importer.Import(D->getAssertExpr()); + StringLiteral *Message = cast( + Importer.Import(D->getMessage())); + SourceLocation RParenLoc = Importer.Import(D->getRParenLoc()); + + StaticAssertDecl *To = StaticAssertDecl::Create(Importer.getToContext(), DC, + Loc, AssertExpr, Message, RParenLoc, D->isFailed()); + Importer.Imported(D, To); + return To; +} + //---------------------------------------------------------------------------- // Import Statements //---------------------------------------------------------------------------- @@ -5084,6 +5161,106 @@ Importer.Import(E->getLocation())); } +Expr *ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { + QualType Ty = Importer.Import(E->getType()); + if (Ty.isNull()) + return nullptr; + + SmallVector NewLocations; + for (auto I = E->tokloc_begin(), End = E->tokloc_end(); I != End; ++I) + NewLocations.push_back(Importer.Import(*I)); + + ASTContext &ToCtx = Importer.getToContext(); + return StringLiteral::Create(ToCtx, E->getBytes(), E->getKind(), + E->isPascal(), Ty, NewLocations.data(), + E->getNumConcatenated()); +} + +Expr *ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { + ASTContext &ToCtx = Importer.getToContext(); + return new(ToCtx) CXXBoolLiteralExpr(E->getValue(), ToCtx.BoolTy, + Importer.Import(E->getLocation())); +} + +Expr *ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { + QualType Ty = Importer.Import(E->getType()); + if (Ty.isNull()) + return nullptr; + return FloatingLiteral::Create(Importer.getToContext(), E->getValue(), + E->isExact(), Ty, Importer.Import(E->getLocation())); +} + +Expr *ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { + ASTContext &ToCtx = Importer.getToContext(); + return new(ToCtx) CXXNullPtrLiteralExpr(ToCtx.NullPtrTy, + Importer.Import(E->getLocation())); +} + +Expr *ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { + QualType Ty = Importer.Import(E->getType()); + if (Ty.isNull()) + return nullptr; + SourceLocation Loc = Importer.Import(E->getLocation()); + return new(Importer.getToContext()) CXXThisExpr(Loc, Ty, E->isImplicit()); +} + +Expr *ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { + QualType Ty = Importer.Import(E->getType()); + if (Ty.isNull()) + return nullptr; + Expr *Ex = Importer.Import(E->getSubExpr()); + SourceLocation Loc = Importer.Import(E->getThrowLoc()); + return new(Importer.getToContext()) CXXThrowExpr(Ex, Ty, Loc, + E->isThrownVariableInScope()); +} + +Expr *ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { + QualType Ty = Importer.Import(E->getType()); + if (Ty.isNull()) + return nullptr; + + Decl *OpNew = Importer.Import(E->getOperatorNew()); + if (!OpNew) + return nullptr; + Decl *OpDelete = Importer.Import(E->getOperatorDelete()); + + SmallVector PlacementArgs; + for (auto I = E->placement_arg_begin(), End = E->placement_arg_end(); + I != End; ++I) + PlacementArgs.push_back(Importer.Import(*I)); + + SourceRange TIDParens = Importer.Import(E->getTypeIdParens()); + SourceRange Range = Importer.Import(E->getSourceRange()); + SourceRange DIRange = Importer.Import(E->getDirectInitRange()); + + Expr *ArraySize = Importer.Import(E->getArraySize()); + Expr *Initializer = Importer.Import(E->getInitializer()); + + TypeSourceInfo *AllocatedTypeInfo = Importer.Import( + E->getAllocatedTypeSourceInfo()); + + ASTContext &ToCtx = Importer.getToContext(); + return new(ToCtx) CXXNewExpr(ToCtx, E->isGlobalNew(), + cast(OpNew), cast_or_null(OpDelete), + E->doesUsualArrayDeleteWantSize(), PlacementArgs, TIDParens, ArraySize, + E->getInitializationStyle(), Initializer, Ty, AllocatedTypeInfo, Range, + DIRange); +} + +Expr *ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { + QualType Ty = Importer.Import(E->getType()); + if (Ty.isNull()) + return nullptr; + + FunctionDecl *OpDelete = cast( + Importer.Import(E->getOperatorDelete())); + Expr *Arg = Importer.Import(E->getArgument()); + SourceLocation Loc = Importer.Import(E->getLocStart()); + return new(Importer.getToContext()) CXXDeleteExpr(Ty, E->isGlobalDelete(), + E->isArrayForm(), E->isArrayFormAsWritten(), + E->doesUsualArrayDeleteWantSize(), OpDelete, Arg, Loc); +} + Expr *ASTNodeImporter::VisitParenExpr(ParenExpr *E) { Expr *SubExpr = Importer.Import(E->getSubExpr()); if (!SubExpr) @@ -5135,6 +5312,23 @@ Importer.Import(E->getRParenLoc())); } +Expr *ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { + QualType Ty = Importer.Import(E->getType()); + if (Ty.isNull()) + return nullptr; + + Expr *LHS = Importer.Import(E->getLHS()); + if (!LHS) + return nullptr; + Expr *RHS = Importer.Import(E->getRHS()); + if (!RHS) + return nullptr; + + return new(Importer.getToContext()) ArraySubscriptExpr(LHS, RHS, Ty, + E->getValueKind(), E->getObjectKind(), + Importer.Import(E->getRBracketLoc())); +} + Expr *ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { QualType T = Importer.Import(E->getType()); if (T.isNull()) @@ -5185,11 +5379,44 @@ E->isFPContractable()); } -static bool ImportCastPath(CastExpr *E, CXXCastPath &Path) { - if (E->path_empty()) return false; +Expr *ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { + QualType Ty = Importer.Import(E->getType()); + if (Ty.isNull()) + return nullptr; - // TODO: import cast paths - return true; + Expr *Cond = Importer.Import(E->getCond()); + if (!Cond) + return nullptr; + Expr *LHS = Importer.Import(E->getLHS()); + if (!LHS) + return nullptr; + Expr *RHS = Importer.Import(E->getRHS()); + if (!RHS) + return nullptr; + + return new(Importer.getToContext()) ConditionalOperator(Cond, + Importer.Import(E->getQuestionLoc()), LHS, + Importer.Import(E->getColonLoc()), RHS, + Ty, E->getValueKind(), E->getObjectKind()); +} + +bool ASTNodeImporter::ImportCastPath(CastExpr *E, CXXCastPath &Path) { + if (E->path_empty()) + return false; + + for (auto *I = E->path_begin(), *End = E->path_end(); I != End; ++I) { + CXXBaseSpecifier *FromBase = *I; + SourceRange RLoc = Importer.Import(FromBase->getSourceRange()); + SourceLocation ELoc = Importer.Import(FromBase->getEllipsisLoc()); + TypeSourceInfo *TInfo = Importer.Import(FromBase->getTypeSourceInfo()); + CXXBaseSpecifier *ToBase = new(Importer.getToContext()) CXXBaseSpecifier( + RLoc, FromBase->isVirtual(), FromBase->isBaseOfClass(), + FromBase->getAccessSpecifier(), TInfo, ELoc); + if (!ToBase) + return true; + Path.push_back(ToBase); + } + return false; } Expr *ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { @@ -5233,6 +5460,183 @@ Importer.Import(E->getRParenLoc())); } +Expr *ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { + QualType Ty = Importer.Import(E->getType()); + if (Ty.isNull()) + return nullptr; + + SmallVector InitExprs; + for (unsigned I = 0; I < E->getNumInits(); ++I) { + Expr *IE = Importer.Import(E->getInit(I)); + if (!IE) + return nullptr; + InitExprs.push_back(IE); + } + + SourceLocation LBLoc = Importer.Import(E->getLBraceLoc()); + SourceLocation RBLoc = Importer.Import(E->getRBraceLoc()); + ASTContext &ToCtx = Importer.getToContext(); + InitListExpr *Res = new(ToCtx) InitListExpr(ToCtx, LBLoc, InitExprs, RBLoc); + Res->setType(Ty); + + if (InitListExpr *SF = E->getSyntacticForm()) + Res->setSyntacticForm(cast(Importer.Import(SF))); + + if (E->hasArrayFiller()) + Res->setArrayFiller(Importer.Import(E->getArrayFiller())); + + if (FieldDecl *FD = E->getInitializedFieldInUnion()) + Res->setInitializedFieldInUnion(cast(Importer.Import(FD))); + + if (E->hadArrayRangeDesignator()) + Res->sawArrayRangeDesignator(); + + return Res; +} + +static DesignatedInitExpr::Designator +ImportDesignator(ASTImporter &Importer, DesignatedInitExpr::Designator *D) { + if (D->isFieldDesignator()) { + Decl *FldDecl = Importer.Import(D->getField()); + IdentifierInfo *II = Importer.Import(D->getFieldName()); + SourceLocation DotLoc = Importer.Import(D->getDotLoc()); + SourceLocation FieldLoc = Importer.Import(D->getFieldLoc()); + + DesignatedInitExpr::Designator DI(II, DotLoc, FieldLoc); + if (FldDecl) + DI.setField(cast(FldDecl)); + return DI; + } + + if (D->isArrayDesignator()) { + SourceLocation LBLoc = Importer.Import(D->getLBracketLoc()); + SourceLocation RBLoc = Importer.Import(D->getRBracketLoc()); + return DesignatedInitExpr::Designator(D->getFirstExprIndex(), LBLoc, RBLoc); + } + + assert(D->isArrayRangeDesignator()); + SourceLocation LBLoc = Importer.Import(D->getLBracketLoc()); + SourceLocation ElLoc = Importer.Import(D->getEllipsisLoc()); + SourceLocation RBLoc = Importer.Import(D->getRBracketLoc()); + return DesignatedInitExpr::Designator(D->getFirstExprIndex(), LBLoc, ElLoc, + RBLoc); +} + +Expr *ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { + unsigned NumIndexExprs = E->getNumSubExprs(); + SmallVector IndexExprs; + for (unsigned I = 1; I < NumIndexExprs; ++I) + IndexExprs.push_back(Importer.Import(E->getSubExpr(I))); + + SmallVector Designators; + for (auto *D = E->designators_begin(); D != E->designators_end(); ++D) + Designators.emplace_back(ImportDesignator(Importer, D)); + + return DesignatedInitExpr::Create(Importer.getToContext(), Designators.data(), + Designators.size(), IndexExprs, Importer.Import(E->getEqualOrColonLoc()), + E->usesGNUSyntax(), Importer.Import(E->getInit())); +} + +Expr *ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { + QualType Ty = Importer.Import(E->getType()); + if (Ty.isNull()) + return nullptr; + + return new (Importer.getToContext()) ImplicitValueInitExpr(Ty); +} + +Expr *ASTNodeImporter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) { + QualType Ty = Importer.Import(E->getType()); + if (Ty.isNull()) + return nullptr; + + Expr *Op = Importer.Import(E->getSubExpr()); + TypeSourceInfo *Written = Importer.Import(E->getTypeInfoAsWritten()); + SourceLocation L = Importer.Import(E->getOperatorLoc()); + SourceLocation RPLoc = Importer.Import(E->getRParenLoc()); + SourceRange ABLoc = Importer.Import(E->getAngleBrackets()); + + CXXCastPath Path; + if (ImportCastPath(E, Path)) + return nullptr; + + return CXXStaticCastExpr::Create(Importer.getToContext(), Ty, + E->getValueKind(), E->getCastKind(), Op, &Path, Written, L, RPLoc, ABLoc); +} + +Expr *ASTNodeImporter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) { + QualType Ty = Importer.Import(E->getType()); + if (Ty.isNull()) + return nullptr; + + Expr *OP = Importer.Import(E->getSubExpr()); + TypeSourceInfo *WrittenTy = Importer.Import(E->getTypeInfoAsWritten()); + SourceLocation Loc = Importer.Import(E->getLocStart()); + SourceLocation RPLoc = Importer.Import(E->getRParenLoc()); + SourceRange ABLoc = Importer.Import(E->getAngleBrackets()); + + CXXCastPath Path; + if (ImportCastPath(E, Path)) + return 0; + + return CXXDynamicCastExpr::Create(Importer.getToContext(), + Ty, E->getValueKind(), E->getCastKind(), + OP, &Path, WrittenTy, Loc, RPLoc, ABLoc); +} + +Expr *ASTNodeImporter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) { + QualType Ty = Importer.Import(E->getType()); + if (Ty.isNull()) + return nullptr; + + Expr *OP = Importer.Import(E->getSubExpr()); + TypeSourceInfo *WrittenTy = Importer.Import(E->getTypeInfoAsWritten()); + SourceLocation Loc = Importer.Import(E->getLocStart()); + SourceLocation RPLoc = Importer.Import(E->getRParenLoc()); + SourceRange ABLoc = Importer.Import(E->getAngleBrackets()); + + CXXCastPath Path; + if (ImportCastPath(E, Path)) + return 0; + + return CXXReinterpretCastExpr::Create(Importer.getToContext(), + Ty, E->getValueKind(), E->getCastKind(), + OP, &Path, WrittenTy, Loc, RPLoc, ABLoc); +} + +Expr *ASTNodeImporter::VisitCXXConstCastExpr(CXXConstCastExpr *E) { + QualType Ty = Importer.Import(E->getType()); + if (Ty.isNull()) + return nullptr; + + Expr *OP = Importer.Import(E->getSubExpr()); + TypeSourceInfo *WrittenTy = Importer.Import(E->getTypeInfoAsWritten()); + SourceLocation Loc = Importer.Import(E->getLocStart()); + SourceLocation RPLoc = Importer.Import(E->getRParenLoc()); + SourceRange ABLoc = Importer.Import(E->getAngleBrackets()); + + return CXXConstCastExpr::Create(Importer.getToContext(), Ty, + E->getValueKind(), OP, WrittenTy, Loc, RPLoc, ABLoc); +} + +Expr *ASTNodeImporter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) { + QualType Ty = Importer.Import(E->getType()); + if (Ty.isNull()) + return nullptr; + + Expr *OP = Importer.Import(E->getSubExpr()); + TypeSourceInfo *WrittenTy = Importer.Import(E->getTypeInfoAsWritten()); + SourceLocation RPLoc = Importer.Import(E->getRParenLoc()); + SourceLocation LPLoc = Importer.Import(E->getLParenLoc()); + + CXXCastPath Path; + if (ImportCastPath(E, Path)) + return nullptr; + + return CXXFunctionalCastExpr::Create(Importer.getToContext(), Ty, + E->getValueKind(), WrittenTy, E->getCastKind(), OP, &Path, LPLoc, RPLoc); +} + Expr *ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { QualType T = Importer.Import(E->getType()); if (T.isNull()) @@ -5266,6 +5670,34 @@ Importer.Import(E->getParenOrBraceRange())); } +Expr *ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { + CXXDestructorDecl *FromDestructor = const_cast( + E->getTemporary()->getDestructor()); + CXXDestructorDecl *ToDestructor = cast( + Importer.Import(FromDestructor)); + Importer.Imported(FromDestructor, ToDestructor); + + CXXTemporary *Temp = CXXTemporary::Create(Importer.getToContext(), + ToDestructor); + Expr *SubExpr = Importer.Import(E->getSubExpr()); + return CXXBindTemporaryExpr::Create(Importer.getToContext(), Temp, SubExpr); +} + +Expr *ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { + Expr *SubExpr = Importer.Import(E->getSubExpr()); + assert(SubExpr && "SubExpr should be set"); + + SmallVector Objects; + for (unsigned int i = 0; i < E->getNumObjects(); ++i) { + BlockDecl *From = E->getObject(i); + BlockDecl *To = cast(Importer.Import(From)); + Importer.Imported(From, To); + Objects.push_back(To); + } + + return ExprWithCleanups::Create(Importer.getToContext(), SubExpr, Objects); +} + Expr *ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { QualType T = Importer.Import(E->getType()); if (T.isNull()) @@ -5334,6 +5766,28 @@ Importer.Import(E->getRParenLoc())); } +Expr *ASTNodeImporter::VisitMaterializeTemporaryExpr( + MaterializeTemporaryExpr *E) { + QualType Ty = Importer.Import(E->getType()); + if (Ty.isNull()) + return nullptr; + + Expr *Temp = Importer.Import(E->GetTemporaryExpr()); + + ValueDecl *FromExtendedBy = const_cast(E->getExtendingDecl()); + ValueDecl *ToExtendedBy = nullptr; + if (FromExtendedBy) { + ToExtendedBy = cast(Importer.Import(FromExtendedBy)); + Importer.Imported(FromExtendedBy, ToExtendedBy); + } + + MaterializeTemporaryExpr *To = new(Importer.getToContext()) + MaterializeTemporaryExpr(Ty, Temp, E->isBoundToLvalueReference()); + To->setExtendingDecl(ToExtendedBy, E->getManglingNumber()); + + return To; +} + ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, ASTContext &FromContext, FileManager &FromFileManager, bool MinimalImport) Index: test/ASTMerge/Inputs/class3.cpp =================================================================== --- /dev/null +++ test/ASTMerge/Inputs/class3.cpp @@ -0,0 +1,23 @@ +class C1 { +public: + C1(); + ~C1(); + C1 *method_1() { + return this; + } + C1 method_2() { + return C1(); + } + void method_3() { + const C1 &ref = C1(); + } +}; + +class C11 : public C1 { +}; + +class C2 { + int x; + friend class C3; + static_assert(sizeof(x) == sizeof(int), "Error"); +}; Index: test/ASTMerge/Inputs/exprs3.cpp =================================================================== --- /dev/null +++ test/ASTMerge/Inputs/exprs3.cpp @@ -0,0 +1,92 @@ +// Integer literals +const char Ch1 = 'a'; +const signed char Ch2 = 'b'; +const unsigned char Ch3 = 'c'; + +const wchar_t Ch4 = L'd'; +const signed wchar_t Ch5 = L'e'; +const unsigned wchar_t Ch6 = L'f'; + +const short C1 = 12; +const unsigned short C2 = 13; + +const int C3 = 12; +const unsigned int C4 = 13; + +const long C5 = 22; +const unsigned long C6 = 23; + +const long long C7 = 66; +const unsigned long long C8 = 67; + + +// String literals +const char str1[] = "ABCD"; +const char str2[] = "ABCD" "0123"; + +const wchar_t wstr1[] = L"DEF"; +const wchar_t wstr2[] = L"DEF" L"123"; + + +// Boolean literals +const bool bval1 = true; +const bool bval2 = false; + +// Floating Literals +const float F1 = 12.2F; +const double F2 = 1E4; +const long double F3 = 1.2E-3L; + + +// nullptr literal +const void *vptr = nullptr; + + +int glb_1[4] = { 10, 20, 30, 40 }; + +struct S1 { + int a; + int b[3]; +}; + +struct S2 { + int c; + S1 d; +}; + +S2 glb_2 = { 22, .d.a = 44, .d.b[0] = 55, .d.b[1] = 66 }; + +void func() { + throw; + char *p = new char[10]; + delete[] p; +} + +int func_2(int *x, int n) { + return x[n]; +} + +int func_3(int c, int x, int y) { + return c ? x : y; +} + +S1 &func_4(const S1 &x) { + return const_cast(x); +} + +S1 &func_5(S1 &x) { + return static_cast(x); +} + +S1 &func_6(S1 &x) { + return reinterpret_cast(x); +} + +S1 &func_7(S1 &x) { + return dynamic_cast(x); +} + +int func_8(int x) { + return int(x); +} + Index: test/ASTMerge/class2.cpp =================================================================== --- /dev/null +++ test/ASTMerge/class2.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++1z -emit-pch -o %t.1.ast %S/Inputs/class3.cpp +// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++1z -ast-merge %t.1.ast -fsyntax-only -verify %s +// expected-no-diagnostics + +class C3 { + int method_1(C2 *x) { + return x->x; + } +}; Index: test/ASTMerge/exprs.cpp =================================================================== --- /dev/null +++ test/ASTMerge/exprs.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++1z -fcxx-exceptions -emit-pch -o %t.1.ast %S/Inputs/exprs3.cpp +// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++1z -fcxx-exceptions -ast-merge %t.1.ast -fsyntax-only -verify %s +// expected-no-diagnostics + +static_assert(Ch1 == 'a'); +static_assert(Ch2 == 'b'); +static_assert(Ch3 == 'c'); + +static_assert(Ch4 == L'd'); +static_assert(Ch5 == L'e'); +static_assert(Ch6 == L'f'); + +static_assert(C1 == 12); +static_assert(C2 == 13); + +static_assert(C3 == 12); +static_assert(C4 == 13); + +static_assert(C5 == 22L); +static_assert(C6 == 23L); + +static_assert(C7 == 66LL); +static_assert(C8 == 67ULL); + +static_assert(bval1 == true); +static_assert(bval2 == false);