[cfe-commits] r70963 - in /cfe/trunk/lib/Sema: Sema.h SemaExpr.cpp SemaExprCXX.cpp
Douglas Gregor
dgregor at apple.com
Mon May 4 21:50:51 PDT 2009
Author: dgregor
Date: Mon May 4 23:50:50 2009
New Revision: 70963
URL: http://llvm.org/viewvc/llvm-project?rev=70963&view=rev
Log:
Turns out that Sebastian already implemented the logic to compute the
composite pointer type, and his is better! Updated relational- and
equality-operator checking accordingly.
Modified:
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=70963&r1=70962&r2=70963&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Mon May 4 23:50:50 2009
@@ -2420,8 +2420,6 @@
QualType rhsType);
bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
- QualType CompositePointerType(Expr *LHS, Expr *RHS,
- bool LHSIsNull, bool RHSIsNull);
bool PerformImplicitConversion(Expr *&From, QualType ToType,
const char *Flavor,
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=70963&r1=70962&r2=70963&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon May 4 23:50:50 2009
@@ -3771,7 +3771,7 @@
//
// C++ [expr.eq]p2 uses the same notion for (in)equality
// comparisons of pointers.
- QualType T = CompositePointerType(lex, rex, LHSIsNull, RHSIsNull);
+ QualType T = FindCompositePointerType(lex, rex);
if (T.isNull()) {
Diag(Loc, diag::err_typecheck_comparison_of_distinct_pointers)
<< lType << rType << lex->getSourceRange() << rex->getSourceRange();
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=70963&r1=70962&r2=70963&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Mon May 4 23:50:50 2009
@@ -768,77 +768,6 @@
return false;
}
-/// \brief Determine the composite pointer type (C++ [expr.rel]p2)
-/// given the left- and right-hand expressions in a relational
-/// operation.
-///
-/// While the notion of a composite pointer type is only described for
-/// relational operators (<, >, <=, >=), the same computation is used
-/// to determine the "common type" used for the equality operators
-/// (==, !=) when comparing pointers.
-///
-/// \param LHS the left-hand operand.
-/// \param RHS the right-hand operand.
-/// \param LHSIsNull whether \p LHS is the NULL pointer constant
-/// \param RHSIsNull whether \p RHS is the NULL pointer constant
-///
-/// \returns the composite pointer type, if any, or the null type if
-/// no such type exists. It is the caller's responsibility to emit
-/// diagnostic.
-QualType Sema::CompositePointerType(Expr *LHS, Expr *RHS,
- bool LHSIsNull, bool RHSIsNull) {
- // First, determine whether LHS and RHS have pointer types, and what
- // types they point to.
- QualType LHSPointee;
- QualType RHSPointee;
- if (const PointerType *LHSPtr = LHS->getType()->getAsPointerType())
- LHSPointee = LHSPtr->getPointeeType();
- if (const PointerType *RHSPtr = RHS->getType()->getAsPointerType())
- RHSPointee = RHSPtr->getPointeeType();
-
- // C++ [expr.rel]p2:
- // [...] If one operand is a null pointer constant, the composite
- // pointer type is the type of the other operand.
- if (LHSIsNull && !RHSPointee.isNull())
- return RHS->getType();
- if (RHSIsNull && !LHSPointee.isNull())
- return LHS->getType();
-
- // If neither LHS nor RHS has pointer type, we're done.
- if (LHSPointee.isNull() && RHSPointee.isNull())
- return QualType();
-
- // [...] Otherwise, if one of the operands has type "pointer to cv1
- // void", then the other has type "pointer to cv2 T" and the
- // composite pointer type is "pointer to cv12 void", where cv12 is
- // the union of cv1 and cv2.
- QualType LHSPointeeCanon = Context.getCanonicalType(LHSPointee);
- QualType RHSPointeeCanon = Context.getCanonicalType(RHSPointee);
- unsigned CVQuals =
- (LHSPointeeCanon.getCVRQualifiers() | RHSPointeeCanon.getCVRQualifiers());
- if (LHSPointeeCanon->isVoidType() || RHSPointeeCanon->isVoidType())
- return Context.getPointerType(Context.VoidTy.getQualifiedType(CVQuals));
-
- // [...] Otherwise, the composite pointer type is a pointer type
- // similar (4.4) to the type of one of the operands, with a
- // cv-qualification signature (4.4) that is the union of the
- // cv-qualification signatures of the operand types.
- QualType FullyQualifiedLHSType
- = Context.getPointerType(LHSPointee.getQualifiedType(CVQuals));
- QualType CompositePointerType;
- bool IncompatibleObjC = false;
- if (IsPointerConversion(RHS, RHS->getType(), FullyQualifiedLHSType,
- CompositePointerType, IncompatibleObjC))
- return CompositePointerType;
- QualType FullyQualifiedRHSType
- = Context.getPointerType(RHSPointee.getQualifiedType(CVQuals));
- if (IsPointerConversion(LHS, LHS->getType(), FullyQualifiedRHSType,
- CompositePointerType, IncompatibleObjC))
- return CompositePointerType;
-
- return QualType();
-}
-
/// PerformImplicitConversion - Perform an implicit conversion of the
/// expression From to the type ToType. Returns true if there was an
/// error, false otherwise. The expression From is replaced with the
More information about the cfe-commits
mailing list