From 6dcc3762a0297bf8d8542e94e55c2938a8f76875 Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Sun, 15 Jul 2012 00:23:57 +0000 Subject: [PATCH] Replace IsSameValue with the llvm::APSInt/llvm::APInt versions that we just copied from here and replace all uses. Part of rdar://11875995 llvm-svn: 160224 --- clang/lib/AST/ASTImporter.cpp | 45 +++-------------------------------- 1 file changed, 3 insertions(+), 42 deletions(-) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index bc139207cea4..3403b6276c98 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -237,45 +237,6 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, Decl *D1, Decl *D2); -/// \brief Determine if two APInts have the same value, after zero-extending -/// one of them (if needed!) to ensure that the bit-widths match. -static bool IsSameValue(const llvm::APInt &I1, const llvm::APInt &I2) { - if (I1.getBitWidth() == I2.getBitWidth()) - return I1 == I2; - - if (I1.getBitWidth() > I2.getBitWidth()) - return I1 == I2.zext(I1.getBitWidth()); - - return I1.zext(I2.getBitWidth()) == I2; -} - -/// \brief Determine if two APSInts have the same value, zero- or sign-extending -/// as needed. -static bool IsSameValue(const llvm::APSInt &I1, const llvm::APSInt &I2) { - if (I1.getBitWidth() == I2.getBitWidth() && I1.isSigned() == I2.isSigned()) - return I1 == I2; - - // Check for a bit-width mismatch. - if (I1.getBitWidth() > I2.getBitWidth()) - return IsSameValue(I1, I2.extend(I1.getBitWidth())); - else if (I2.getBitWidth() > I1.getBitWidth()) - return IsSameValue(I1.extend(I2.getBitWidth()), I2); - - // We have a signedness mismatch. Turn the signed value into an unsigned - // value. - if (I1.isSigned()) { - if (I1.isNegative()) - return false; - - return llvm::APSInt(I1, true) == I2; - } - - if (I2.isNegative()) - return false; - - return I1 == llvm::APSInt(I2, true); -} - /// \brief Determine structural equivalence of two expressions. static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, Expr *E1, Expr *E2) { @@ -322,7 +283,7 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, Arg2.getIntegralType())) return false; - return IsSameValue(Arg1.getAsIntegral(), Arg2.getAsIntegral()); + return llvm::APSInt::isSameValue(Arg1.getAsIntegral(), Arg2.getAsIntegral()); case TemplateArgument::Declaration: if (!Arg1.getAsDecl() || !Arg2.getAsDecl()) @@ -467,7 +428,7 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, case Type::ConstantArray: { const ConstantArrayType *Array1 = cast(T1); const ConstantArrayType *Array2 = cast(T2); - if (!IsSameValue(Array1->getSize(), Array2->getSize())) + if (!llvm::APInt::isSameValue(Array1->getSize(), Array2->getSize())) return false; if (!IsArrayStructurallyEquivalent(Context, Array1, Array2)) @@ -1053,7 +1014,7 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, llvm::APSInt Val1 = EC1->getInitVal(); llvm::APSInt Val2 = EC2->getInitVal(); - if (!IsSameValue(Val1, Val2) || + if (!llvm::APSInt::isSameValue(Val1, Val2) || !IsStructurallyEquivalent(EC1->getIdentifier(), EC2->getIdentifier())) { Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent) << Context.C2.getTypeDeclType(D2);