From f187237d916afa97c491ac32fe98be7d335c5b63 Mon Sep 17 00:00:00 2001 From: Francois Pichet Date: Wed, 8 Dec 2010 22:35:30 +0000 Subject: [PATCH] Remove the TypesCompatibleExprClass AST node. Merge its functionality into BinaryTypeTraitExpr. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121298 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Expr.h | 46 ---------------------- include/clang/AST/ExprCXX.h | 2 +- include/clang/AST/RecursiveASTVisitor.h | 5 --- include/clang/Basic/StmtNodes.td | 1 - include/clang/Basic/TypeTraits.h | 3 +- include/clang/Frontend/StmtXML.def | 7 ---- include/clang/Sema/Sema.h | 10 ----- include/clang/Serialization/ASTBitCodes.h | 4 +- lib/AST/Expr.cpp | 8 ---- lib/AST/ExprClassification.cpp | 1 - lib/AST/ExprConstant.cpp | 11 ------ lib/AST/StmtDumper.cpp | 9 ----- lib/AST/StmtPrinter.cpp | 9 +---- lib/AST/StmtProfile.cpp | 6 --- lib/Checker/GRExprEngine.cpp | 1 - lib/Checker/IdempotentOperationChecker.cpp | 2 +- lib/CodeGen/CGExprScalar.cpp | 7 +--- lib/CodeGen/Mangle.cpp | 1 - lib/Frontend/StmtXML.cpp | 7 ---- lib/Parse/ParseExpr.cpp | 21 +--------- lib/Parse/ParseExprCXX.cpp | 3 +- lib/Sema/SemaExpr.cpp | 29 -------------- lib/Sema/SemaExprCXX.cpp | 19 ++++++++- lib/Sema/TreeTransform.h | 37 ----------------- lib/Serialization/ASTReaderStmt.cpp | 15 +------ lib/Serialization/ASTWriter.cpp | 1 - lib/Serialization/ASTWriterStmt.cpp | 12 +----- tools/libclang/CIndex.cpp | 5 --- tools/libclang/CXCursor.cpp | 1 - 29 files changed, 31 insertions(+), 252 deletions(-) diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index a2e00675d7..c288ec6ea1 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -2641,52 +2641,6 @@ public: virtual child_iterator child_end(); }; -/// TypesCompatibleExpr - GNU builtin-in function __builtin_types_compatible_p. -/// This AST node represents a function that returns 1 if two *types* (not -/// expressions) are compatible. The result of this built-in function can be -/// used in integer constant expressions. -class TypesCompatibleExpr : public Expr { - TypeSourceInfo *TInfo1; - TypeSourceInfo *TInfo2; - SourceLocation BuiltinLoc, RParenLoc; -public: - TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc, - TypeSourceInfo *tinfo1, TypeSourceInfo *tinfo2, - SourceLocation RP) : - Expr(TypesCompatibleExprClass, ReturnType, VK_RValue, OK_Ordinary, - false, false), - TInfo1(tinfo1), TInfo2(tinfo2), BuiltinLoc(BLoc), RParenLoc(RP) {} - - /// \brief Build an empty __builtin_type_compatible_p expression. - explicit TypesCompatibleExpr(EmptyShell Empty) - : Expr(TypesCompatibleExprClass, Empty) { } - - TypeSourceInfo *getArgTInfo1() const { return TInfo1; } - void setArgTInfo1(TypeSourceInfo *TInfo) { TInfo1 = TInfo; } - TypeSourceInfo *getArgTInfo2() const { return TInfo2; } - void setArgTInfo2(TypeSourceInfo *TInfo) { TInfo2 = TInfo; } - - QualType getArgType1() const { return TInfo1->getType(); } - QualType getArgType2() const { return TInfo2->getType(); } - - SourceLocation getBuiltinLoc() const { return BuiltinLoc; } - void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } - - SourceLocation getRParenLoc() const { return RParenLoc; } - void setRParenLoc(SourceLocation L) { RParenLoc = L; } - - virtual SourceRange getSourceRange() const { - return SourceRange(BuiltinLoc, RParenLoc); - } - static bool classof(const Stmt *T) { - return T->getStmtClass() == TypesCompatibleExprClass; - } - static bool classof(const TypesCompatibleExpr *) { return true; } - - // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); -}; /// ShuffleVectorExpr - clang-specific builtin-in function /// __builtin_shufflevector. diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index d7dc56b4a9..a822bcaffe 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -1488,7 +1488,7 @@ public: explicit BinaryTypeTraitExpr(EmptyShell Empty) : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false), - LhsType() { } + LhsType(), RhsType() { } virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen); diff --git a/include/clang/AST/RecursiveASTVisitor.h b/include/clang/AST/RecursiveASTVisitor.h index 4b449ccc3d..269f03d545 100644 --- a/include/clang/AST/RecursiveASTVisitor.h +++ b/include/clang/AST/RecursiveASTVisitor.h @@ -1726,11 +1726,6 @@ DEF_TRAVERSE_STMT(CXXUuidofExpr, { TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc())); }) -DEF_TRAVERSE_STMT(TypesCompatibleExpr, { - TRY_TO(TraverseTypeLoc(S->getArgTInfo1()->getTypeLoc())); - TRY_TO(TraverseTypeLoc(S->getArgTInfo2()->getTypeLoc())); - }) - DEF_TRAVERSE_STMT(UnaryTypeTraitExpr, { TRY_TO(TraverseTypeLoc(S->getQueriedTypeSourceInfo()->getTypeLoc())); }) diff --git a/include/clang/Basic/StmtNodes.td b/include/clang/Basic/StmtNodes.td index 56db943025..0e2fb575e6 100644 --- a/include/clang/Basic/StmtNodes.td +++ b/include/clang/Basic/StmtNodes.td @@ -76,7 +76,6 @@ def VAArgExpr : DStmt; // GNU Extensions. def AddrLabelExpr : DStmt; def StmtExpr : DStmt; -def TypesCompatibleExpr : DStmt; def ChooseExpr : DStmt; def GNUNullExpr : DStmt; diff --git a/include/clang/Basic/TypeTraits.h b/include/clang/Basic/TypeTraits.h index 8847d7ad7d..aecc813d31 100644 --- a/include/clang/Basic/TypeTraits.h +++ b/include/clang/Basic/TypeTraits.h @@ -38,7 +38,8 @@ namespace clang { /// BinaryTypeTrait - Names for the binary type traits. enum BinaryTypeTrait { - BTT_IsBaseOf + BTT_IsBaseOf, + BTT_TypeCompatible }; } diff --git a/include/clang/Frontend/StmtXML.def b/include/clang/Frontend/StmtXML.def index c03a5a8835..8a859e6898 100644 --- a/include/clang/Frontend/StmtXML.def +++ b/include/clang/Frontend/StmtXML.def @@ -415,13 +415,6 @@ NODE_XML(StmtExpr, "StmtExpr") // StmtExpr contains a s SUB_NODE_XML(CompoundStmt) END_NODE_XML -NODE_XML(TypesCompatibleExpr, "TypesCompatibleExpr") // GNU builtin-in function __builtin_types_compatible_p - ATTRIBUTE_FILE_LOCATION_XML - TYPE_ATTRIBUTE_XML(getType()) - ATTRIBUTE_XML(getArgType1(), "type1_ref") // id of type1 - ATTRIBUTE_XML(getArgType2(), "type2_ref") // id of type2 -END_NODE_XML - NODE_XML(ChooseExpr, "ChooseExpr") // GNU builtin-in function __builtin_choose_expr(expr1, expr2, expr3) ATTRIBUTE_FILE_LOCATION_XML TYPE_ATTRIBUTE_XML(getType()) diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 56cf99ec79..676934c0ec 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -1953,16 +1953,6 @@ public: unsigned NumComponents, SourceLocation RParenLoc); - // __builtin_types_compatible_p(type1, type2) - ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc, - ParsedType arg1, - ParsedType arg2, - SourceLocation RPLoc); - ExprResult BuildTypesCompatibleExpr(SourceLocation BuiltinLoc, - TypeSourceInfo *argTInfo1, - TypeSourceInfo *argTInfo2, - SourceLocation RPLoc); - // __builtin_choose_expr(constExpr, expr1, expr2) ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, Expr *cond, Expr *expr1, diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h index 3e96fd6047..29eb49106f 100644 --- a/include/clang/Serialization/ASTBitCodes.h +++ b/include/clang/Serialization/ASTBitCodes.h @@ -826,8 +826,6 @@ namespace clang { EXPR_ADDR_LABEL, /// \brief A StmtExpr record. EXPR_STMT, - /// \brief A TypesCompatibleExpr record. - EXPR_TYPES_COMPATIBLE, /// \brief A ChooseExpr record. EXPR_CHOOSE, /// \brief A GNUNullExpr record. @@ -927,7 +925,7 @@ namespace clang { EXPR_CXX_NOEXCEPT, // CXXNoexceptExpr EXPR_OPAQUE_VALUE, // OpaqueValueExpr - EXPR_CXX_BINARY_TYPE_TRAIT // BinaryTypeTraitExpr + EXPR_BINARY_TYPE_TRAIT // BinaryTypeTraitExpr }; /// \brief The kinds of designators that can occur in a diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index eef5cd16e4..9439d6875e 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -2708,14 +2708,6 @@ Stmt::child_iterator AddrLabelExpr::child_end() { return child_iterator(); } Stmt::child_iterator StmtExpr::child_begin() { return &SubStmt; } Stmt::child_iterator StmtExpr::child_end() { return &SubStmt+1; } -// TypesCompatibleExpr -Stmt::child_iterator TypesCompatibleExpr::child_begin() { - return child_iterator(); -} - -Stmt::child_iterator TypesCompatibleExpr::child_end() { - return child_iterator(); -} // ChooseExpr Stmt::child_iterator ChooseExpr::child_begin() { return &SubExprs[0]; } diff --git a/lib/AST/ExprClassification.cpp b/lib/AST/ExprClassification.cpp index 76e98865ec..05d175c135 100644 --- a/lib/AST/ExprClassification.cpp +++ b/lib/AST/ExprClassification.cpp @@ -130,7 +130,6 @@ static Cl::Kinds ClassifyInternal(ASTContext &Ctx, const Expr *E) { case Expr::CXXNewExprClass: case Expr::CXXThisExprClass: case Expr::CXXNullPtrLiteralExprClass: - case Expr::TypesCompatibleExprClass: case Expr::ImaginaryLiteralClass: case Expr::GNUNullExprClass: case Expr::OffsetOfExprClass: diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 459981886e..5e5c3a0e12 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -910,16 +910,6 @@ public: bool VisitCharacterLiteral(const CharacterLiteral *E) { return Success(E->getValue(), E); } - bool VisitTypesCompatibleExpr(const TypesCompatibleExpr *E) { - // Per gcc docs "this built-in function ignores top level - // qualifiers". We need to use the canonical version to properly - // be able to strip CRV qualifiers from the type. - QualType T0 = Info.Ctx.getCanonicalType(E->getArgType1()); - QualType T1 = Info.Ctx.getCanonicalType(E->getArgType2()); - return Success(Info.Ctx.typesAreCompatible(T0.getUnqualifiedType(), - T1.getUnqualifiedType()), - E); - } bool CheckReferencedDecl(const Expr *E, const Decl *D); bool VisitDeclRefExpr(const DeclRefExpr *E) { @@ -2527,7 +2517,6 @@ static ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) { case Expr::CharacterLiteralClass: case Expr::CXXBoolLiteralExprClass: case Expr::CXXScalarValueInitExprClass: - case Expr::TypesCompatibleExprClass: case Expr::UnaryTypeTraitExprClass: case Expr::BinaryTypeTraitExprClass: case Expr::CXXNoexceptExprClass: diff --git a/lib/AST/StmtDumper.cpp b/lib/AST/StmtDumper.cpp index 67ba3ec9c7..60792bbd00 100644 --- a/lib/AST/StmtDumper.cpp +++ b/lib/AST/StmtDumper.cpp @@ -152,7 +152,6 @@ namespace { void VisitBinaryOperator(BinaryOperator *Node); void VisitCompoundAssignOperator(CompoundAssignOperator *Node); void VisitAddrLabelExpr(AddrLabelExpr *Node); - void VisitTypesCompatibleExpr(TypesCompatibleExpr *Node); // C++ void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node); @@ -482,14 +481,6 @@ void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) { << " " << (void*)Node->getLabel(); } -void StmtDumper::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) { - DumpExpr(Node); - OS << " "; - DumpType(Node->getArgType1()); - OS << " "; - DumpType(Node->getArgType2()); -} - //===----------------------------------------------------------------------===// // C++ Expressions //===----------------------------------------------------------------------===// diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index f17ff0b659..6bbe8f9cd9 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -814,12 +814,6 @@ void StmtPrinter::VisitStmtExpr(StmtExpr *E) { OS << ")"; } -void StmtPrinter::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) { - OS << "__builtin_types_compatible_p("; - OS << Node->getArgType1().getAsString(Policy) << ","; - OS << Node->getArgType2().getAsString(Policy) << ")"; -} - void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) { OS << "__builtin_choose_expr("; PrintExpr(Node->getCond()); @@ -1229,7 +1223,8 @@ static const char *getTypeTraitName(UnaryTypeTrait UTT) { static const char *getTypeTraitName(BinaryTypeTrait BTT) { switch (BTT) { default: llvm_unreachable("Unknown binary type trait"); - case BTT_IsBaseOf: return "__is_base_of"; + case BTT_IsBaseOf: return "__is_base_of"; + case BTT_TypeCompatible: return "__builtin_types_compatible_p"; } return ""; } diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp index abcda7303f..418b241009 100644 --- a/lib/AST/StmtProfile.cpp +++ b/lib/AST/StmtProfile.cpp @@ -359,12 +359,6 @@ void StmtProfiler::VisitStmtExpr(StmtExpr *S) { VisitExpr(S); } -void StmtProfiler::VisitTypesCompatibleExpr(TypesCompatibleExpr *S) { - VisitExpr(S); - VisitType(S->getArgType1()); - VisitType(S->getArgType2()); -} - void StmtProfiler::VisitShuffleVectorExpr(ShuffleVectorExpr *S) { VisitExpr(S); } diff --git a/lib/Checker/GRExprEngine.cpp b/lib/Checker/GRExprEngine.cpp index bee2db36cf..e01f5d9f03 100644 --- a/lib/Checker/GRExprEngine.cpp +++ b/lib/Checker/GRExprEngine.cpp @@ -866,7 +866,6 @@ void GRExprEngine::Visit(const Stmt* S, ExplodedNode* Pred, case Stmt::ParenListExprClass: case Stmt::PredefinedExprClass: case Stmt::ShuffleVectorExprClass: - case Stmt::TypesCompatibleExprClass: case Stmt::VAArgExprClass: // Fall through. diff --git a/lib/Checker/IdempotentOperationChecker.cpp b/lib/Checker/IdempotentOperationChecker.cpp index 245caef485..fbf25ba4a8 100644 --- a/lib/Checker/IdempotentOperationChecker.cpp +++ b/lib/Checker/IdempotentOperationChecker.cpp @@ -646,7 +646,7 @@ bool IdempotentOperationChecker::CanVary(const Expr *Ex, case Stmt::OffsetOfExprClass: case Stmt::CompoundLiteralExprClass: case Stmt::AddrLabelExprClass: - case Stmt::TypesCompatibleExprClass: + case Stmt::BinaryTypeTraitExprClass: case Stmt::GNUNullExprClass: case Stmt::InitListExprClass: case Stmt::DesignatedInitExprClass: diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 62a18dbeab..6b22fc48d4 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -188,11 +188,6 @@ public: Value *VisitGNUNullExpr(const GNUNullExpr *E) { return EmitNullValue(E->getType()); } - Value *VisitTypesCompatibleExpr(const TypesCompatibleExpr *E) { - return llvm::ConstantInt::get(ConvertType(E->getType()), - CGF.getContext().typesAreCompatible( - E->getArgType1(), E->getArgType2())); - } Value *VisitOffsetOfExpr(OffsetOfExpr *E); Value *VisitSizeOfAlignOfExpr(const SizeOfAlignOfExpr *E); Value *VisitAddrLabelExpr(const AddrLabelExpr *E) { @@ -354,7 +349,7 @@ public: } Value *VisitBinaryTypeTraitExpr(const BinaryTypeTraitExpr *E) { - return llvm::ConstantInt::get(Builder.getInt1Ty(), E->getValue()); + return llvm::ConstantInt::get(ConvertType(E->getType()), E->getValue()); } Value *VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *E) { diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp index b95573227b..026f6ba3ff 100644 --- a/lib/CodeGen/Mangle.cpp +++ b/lib/CodeGen/Mangle.cpp @@ -1662,7 +1662,6 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity) { case Expr::PredefinedExprClass: case Expr::ShuffleVectorExprClass: case Expr::StmtExprClass: - case Expr::TypesCompatibleExprClass: case Expr::UnaryTypeTraitExprClass: case Expr::BinaryTypeTraitExprClass: case Expr::VAArgExprClass: diff --git a/lib/Frontend/StmtXML.cpp b/lib/Frontend/StmtXML.cpp index fdd40b15c9..c2ffe4f2a7 100644 --- a/lib/Frontend/StmtXML.cpp +++ b/lib/Frontend/StmtXML.cpp @@ -133,7 +133,6 @@ namespace { void VisitBinaryOperator(BinaryOperator *Node); void VisitCompoundAssignOperator(CompoundAssignOperator *Node); void VisitAddrLabelExpr(AddrLabelExpr *Node); - void VisitTypesCompatibleExpr(TypesCompatibleExpr *Node); // C++ void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node); @@ -356,12 +355,6 @@ void StmtXML::VisitAddrLabelExpr(AddrLabelExpr *Node) { Doc.addAttribute("name", Node->getLabel()->getName()); } -void StmtXML::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) { - DumpExpr(Node); - DumpTypeExpr(Node->getArgType1()); - DumpTypeExpr(Node->getArgType2()); -} - //===----------------------------------------------------------------------===// // C++ Expressions //===----------------------------------------------------------------------===// diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index 65b6249877..47b60b5f47 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -728,7 +728,6 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression, case tok::kw___builtin_va_arg: case tok::kw___builtin_offsetof: case tok::kw___builtin_choose_expr: - case tok::kw___builtin_types_compatible_p: return ParseBuiltinPrimaryExpression(); case tok::kw___null: return Actions.ActOnGNUNullExpr(ConsumeToken()); @@ -987,6 +986,7 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression, case tok::kw___has_virtual_destructor: return ParseUnaryTypeTrait(); + case tok::kw___builtin_types_compatible_p: case tok::kw___is_base_of: return ParseBinaryTypeTrait(); @@ -1477,25 +1477,6 @@ ExprResult Parser::ParseBuiltinPrimaryExpression() { Expr2.take(), ConsumeParen()); break; } - case tok::kw___builtin_types_compatible_p: - TypeResult Ty1 = ParseTypeName(); - - if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "",tok::r_paren)) - return ExprError(); - - TypeResult Ty2 = ParseTypeName(); - - if (Tok.isNot(tok::r_paren)) { - Diag(Tok, diag::err_expected_rparen); - return ExprError(); - } - - if (Ty1.isInvalid() || Ty2.isInvalid()) - Res = ExprError(); - else - Res = Actions.ActOnTypesCompatibleExpr(StartLoc, Ty1.get(), Ty2.get(), - ConsumeParen()); - break; } if (Res.isInvalid()) diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index 9d6023e7f4..8014dbd50e 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -1823,7 +1823,8 @@ static UnaryTypeTrait UnaryTypeTraitFromTokKind(tok::TokenKind kind) { static BinaryTypeTrait BinaryTypeTraitFromTokKind(tok::TokenKind kind) { switch(kind) { default: llvm_unreachable("Not a known binary type trait"); - case tok::kw___is_base_of: return BTT_IsBaseOf; + case tok::kw___is_base_of: return BTT_IsBaseOf; + case tok::kw___builtin_types_compatible_p: return BTT_TypeCompatible; } } diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index c9e7f2733a..52ef579b31 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -8126,35 +8126,6 @@ ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S, } -ExprResult Sema::ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc, - ParsedType arg1, ParsedType arg2, - SourceLocation RPLoc) { - TypeSourceInfo *argTInfo1; - QualType argT1 = GetTypeFromParser(arg1, &argTInfo1); - TypeSourceInfo *argTInfo2; - QualType argT2 = GetTypeFromParser(arg2, &argTInfo2); - - assert((!argT1.isNull() && !argT2.isNull()) && "Missing type argument(s)"); - - return BuildTypesCompatibleExpr(BuiltinLoc, argTInfo1, argTInfo2, RPLoc); -} - -ExprResult -Sema::BuildTypesCompatibleExpr(SourceLocation BuiltinLoc, - TypeSourceInfo *argTInfo1, - TypeSourceInfo *argTInfo2, - SourceLocation RPLoc) { - if (getLangOptions().CPlusPlus) { - Diag(BuiltinLoc, diag::err_types_compatible_p_in_cplusplus) - << SourceRange(BuiltinLoc, RPLoc); - return ExprError(); - } - - return Owned(new (Context) TypesCompatibleExpr(Context.IntTy, BuiltinLoc, - argTInfo1, argTInfo2, RPLoc)); -} - - ExprResult Sema::ActOnChooseExpr(SourceLocation BuiltinLoc, Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr, diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 100f787059..92441918d1 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -2378,6 +2378,9 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, BinaryTypeTrait BTT, return true; return false; + case BTT_TypeCompatible: + return Self.Context.typesAreCompatible(LhsT.getUnqualifiedType(), + RhsT.getUnqualifiedType()); } llvm_unreachable("Unknown type trait or not implemented"); } @@ -2402,15 +2405,29 @@ ExprResult Sema::BuildBinaryTypeTrait(BinaryTypeTrait BTT, RequireCompleteType(KWLoc, RhsT, diag::err_incomplete_type_used_in_type_trait_expr)) return ExprError(); + } else if (BTT == BTT_TypeCompatible) { + if (getLangOptions().CPlusPlus) { + Diag(KWLoc, diag::err_types_compatible_p_in_cplusplus) + << SourceRange(KWLoc, RParen); + return ExprError(); + } } bool Value = false; if (!LhsT->isDependentType() && !RhsT->isDependentType()) Value = EvaluateBinaryTypeTrait(*this, BTT, LhsT, RhsT, KWLoc); + // Select trait result type. + QualType ResultType; + switch (BTT) { + default: llvm_unreachable("Unknown type trait or not implemented"); + case BTT_IsBaseOf: ResultType = Context.BoolTy; break; + case BTT_TypeCompatible: ResultType = Context.IntTy; break; + } + return Owned(new (Context) BinaryTypeTraitExpr(KWLoc, BTT, LhsTSInfo, RhsTSInfo, Value, RParen, - Context.BoolTy)); + ResultType)); } QualType Sema::CheckPointerToMemberOperands(Expr *&lex, Expr *&rex, diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 816a1701d8..c0bafc7cb0 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -1348,19 +1348,6 @@ public: return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); } - /// \brief Build a new __builtin_types_compatible_p expression. - /// - /// By default, performs semantic analysis to build the new expression. - /// Subclasses may override this routine to provide different behavior. - ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, - TypeSourceInfo *TInfo1, - TypeSourceInfo *TInfo2, - SourceLocation RParenLoc) { - return getSema().BuildTypesCompatibleExpr(BuiltinLoc, - TInfo1, TInfo2, - RParenLoc); - } - /// \brief Build a new __builtin_choose_expr expression. /// /// By default, performs semantic analysis to build the new expression. @@ -4934,30 +4921,6 @@ TreeTransform::TransformStmtExpr(StmtExpr *E) { E->getRParenLoc()); } -template -ExprResult -TreeTransform::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { - TypeSourceInfo *TInfo1; - TypeSourceInfo *TInfo2; - - TInfo1 = getDerived().TransformType(E->getArgTInfo1()); - if (!TInfo1) - return ExprError(); - - TInfo2 = getDerived().TransformType(E->getArgTInfo2()); - if (!TInfo2) - return ExprError(); - - if (!getDerived().AlwaysRebuild() && - TInfo1 == E->getArgTInfo1() && - TInfo2 == E->getArgTInfo2()) - return SemaRef.Owned(E); - - return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), - TInfo1, TInfo2, - E->getRParenLoc()); -} - template ExprResult TreeTransform::TransformChooseExpr(ChooseExpr *E) { diff --git a/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp index f00b10743e..ab9d677f4a 100644 --- a/lib/Serialization/ASTReaderStmt.cpp +++ b/lib/Serialization/ASTReaderStmt.cpp @@ -115,7 +115,6 @@ namespace clang { void VisitVAArgExpr(VAArgExpr *E); void VisitAddrLabelExpr(AddrLabelExpr *E); void VisitStmtExpr(StmtExpr *E); - void VisitTypesCompatibleExpr(TypesCompatibleExpr *E); void VisitChooseExpr(ChooseExpr *E); void VisitGNUNullExpr(GNUNullExpr *E); void VisitShuffleVectorExpr(ShuffleVectorExpr *E); @@ -759,14 +758,6 @@ void ASTStmtReader::VisitStmtExpr(StmtExpr *E) { E->setSubStmt(cast_or_null(Reader.ReadSubStmt())); } -void ASTStmtReader::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) { - VisitExpr(E); - E->setArgTInfo1(GetTypeSourceInfo(Record, Idx)); - E->setArgTInfo2(GetTypeSourceInfo(Record, Idx)); - E->setBuiltinLoc(ReadSourceLocation(Record, Idx)); - E->setRParenLoc(ReadSourceLocation(Record, Idx)); -} - void ASTStmtReader::VisitChooseExpr(ChooseExpr *E) { VisitExpr(E); E->setCond(Reader.ReadSubExpr()); @@ -1606,10 +1597,6 @@ Stmt *ASTReader::ReadStmtFromStream(PerFileData &F) { S = new (Context) StmtExpr(Empty); break; - case EXPR_TYPES_COMPATIBLE: - S = new (Context) TypesCompatibleExpr(Empty); - break; - case EXPR_CHOOSE: S = new (Context) ChooseExpr(Empty); break; @@ -1812,7 +1799,7 @@ Stmt *ASTReader::ReadStmtFromStream(PerFileData &F) { S = new (Context) UnaryTypeTraitExpr(Empty); break; - case EXPR_CXX_BINARY_TYPE_TRAIT: + case EXPR_BINARY_TYPE_TRAIT: S = new (Context) BinaryTypeTraitExpr(Empty); break; diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index ea63e7b9d8..e95e422fbd 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -581,7 +581,6 @@ static void AddStmtsExprs(llvm::BitstreamWriter &Stream, RECORD(EXPR_VA_ARG); RECORD(EXPR_ADDR_LABEL); RECORD(EXPR_STMT); - RECORD(EXPR_TYPES_COMPATIBLE); RECORD(EXPR_CHOOSE); RECORD(EXPR_GNU_NULL); RECORD(EXPR_SHUFFLE_VECTOR); diff --git a/lib/Serialization/ASTWriterStmt.cpp b/lib/Serialization/ASTWriterStmt.cpp index 5e00b86cf3..99599a7505 100644 --- a/lib/Serialization/ASTWriterStmt.cpp +++ b/lib/Serialization/ASTWriterStmt.cpp @@ -86,7 +86,6 @@ namespace clang { void VisitVAArgExpr(VAArgExpr *E); void VisitAddrLabelExpr(AddrLabelExpr *E); void VisitStmtExpr(StmtExpr *E); - void VisitTypesCompatibleExpr(TypesCompatibleExpr *E); void VisitChooseExpr(ChooseExpr *E); void VisitGNUNullExpr(GNUNullExpr *E); void VisitShuffleVectorExpr(ShuffleVectorExpr *E); @@ -728,15 +727,6 @@ void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) { Code = serialization::EXPR_STMT; } -void ASTStmtWriter::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) { - VisitExpr(E); - Writer.AddTypeSourceInfo(E->getArgTInfo1(), Record); - Writer.AddTypeSourceInfo(E->getArgTInfo2(), Record); - Writer.AddSourceLocation(E->getBuiltinLoc(), Record); - Writer.AddSourceLocation(E->getRParenLoc(), Record); - Code = serialization::EXPR_TYPES_COMPATIBLE; -} - void ASTStmtWriter::VisitChooseExpr(ChooseExpr *E) { VisitExpr(E); Writer.AddStmt(E->getCond()); @@ -1293,7 +1283,7 @@ void ASTStmtWriter::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { Writer.AddSourceRange(E->getSourceRange(), Record); Writer.AddTypeSourceInfo(E->getLhsTypeSourceInfo(), Record); Writer.AddTypeSourceInfo(E->getRhsTypeSourceInfo(), Record); - Code = serialization::EXPR_CXX_BINARY_TYPE_TRAIT; + Code = serialization::EXPR_BINARY_TYPE_TRAIT; } void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 54f8e5b4c2..d85e801d38 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -1605,7 +1605,6 @@ public: void VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E); void VisitStmt(Stmt *S); void VisitSwitchStmt(SwitchStmt *S); - void VisitTypesCompatibleExpr(TypesCompatibleExpr *E); void VisitWhileStmt(WhileStmt *W); void VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E); void VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *E); @@ -1878,10 +1877,6 @@ void EnqueueVisitor::VisitSwitchStmt(SwitchStmt *S) { AddStmt(S->getCond()); AddDecl(S->getConditionVariable()); } -void EnqueueVisitor::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) { - AddTypeLoc(E->getArgTInfo2()); - AddTypeLoc(E->getArgTInfo1()); -} void EnqueueVisitor::VisitWhileStmt(WhileStmt *W) { AddStmt(W->getBody()); diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp index ab4053260e..9d485f8acf 100644 --- a/tools/libclang/CXCursor.cpp +++ b/tools/libclang/CXCursor.cpp @@ -128,7 +128,6 @@ CXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent, case Stmt::VAArgExprClass: case Stmt::AddrLabelExprClass: case Stmt::StmtExprClass: - case Stmt::TypesCompatibleExprClass: case Stmt::ChooseExprClass: case Stmt::GNUNullExprClass: case Stmt::CXXStaticCastExprClass: