From fc144e207b4556319ab2e830e7eec3306da8f5ee Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 4 Jan 2008 23:18:45 +0000 Subject: [PATCH] simplify some of this code by removing the else/if chain and by stripping down to canonical types early. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45599 91177308-0d34-0410-b5e6-96231b3b80d8 --- Sema/SemaExpr.cpp | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index bf96712aad..087fb95d00 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -1083,20 +1083,28 @@ Sema::CheckPointerTypesForAssignment(QualType lhsType, QualType rhsType) { /// Sema::AssignConvertType Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { - if (lhsType.getCanonicalType().getUnqualifiedType() == - rhsType.getCanonicalType().getUnqualifiedType()) + // Get canonical types. We're not formatting these types, just comparing + // them. + lhsType = lhsType.getCanonicalType(); + rhsType = rhsType.getCanonicalType(); + + if (lhsType.getUnqualifiedType() == rhsType.getUnqualifiedType()) return Compatible; // common case, fast path... if (lhsType->isReferenceType() || rhsType->isReferenceType()) { if (Context.referenceTypesAreCompatible(lhsType, rhsType)) return Compatible; + return Incompatible; } - else if (lhsType->isObjcQualifiedIdType() + + if (lhsType->isObjcQualifiedIdType() || rhsType->isObjcQualifiedIdType()) { if (Context.ObjcQualifiedIdTypesAreCompatible(lhsType, rhsType)) return Compatible; + return Incompatible; } - else if (lhsType->isArithmeticType() && rhsType->isArithmeticType()) { + + if (lhsType->isArithmeticType() && rhsType->isArithmeticType()) { if (lhsType->isVectorType() || rhsType->isVectorType()) { // For OCUVector, allow vector splats; float -> if (const OCUVectorType *LV = lhsType->getAsOCUVectorType()) { @@ -1104,7 +1112,7 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { return Compatible; } if (!getLangOptions().LaxVectorConversions) { - if (lhsType.getCanonicalType() != rhsType.getCanonicalType()) + if (lhsType != rhsType) return Incompatible; } else { if (lhsType->isVectorType() && rhsType->isVectorType()) { @@ -1123,20 +1131,29 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { } } return Compatible; - } else if (lhsType->isPointerType()) { + } + + if (lhsType->isPointerType()) { if (rhsType->isIntegerType()) return IntToPointer; if (rhsType->isPointerType()) return CheckPointerTypesForAssignment(lhsType, rhsType); - } else if (rhsType->isPointerType()) { + return Incompatible; + } + + if (rhsType->isPointerType()) { // C99 6.5.16.1p1: the left operand is _Bool and the right is a pointer. if ((lhsType->isIntegerType()) && (lhsType != Context.BoolTy)) return PointerToInt; if (lhsType->isPointerType()) return CheckPointerTypesForAssignment(lhsType, rhsType); - } else if (isa(lhsType) && isa(rhsType)) { + return Incompatible; + + } + + if (isa(lhsType) && isa(rhsType)) { if (Context.tagTypesAreCompatible(lhsType, rhsType)) return Compatible; } -- 2.40.0