Rename variables in SemaExpr.cpp to give a more consistant naming scheme.

ExprResult LHS, RHS,
Expr *LHSExpr, *RHSExpr
QualType LHSType, RHSType

Functions changed:
diagnoseArithmeticOnTwoVoidPointers()
checkArithmeticBinOpPointerOperands()
diagnosePointerIncompatibility()
CheckAdditionOperands()
CheckSubtractionOperands()


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139182 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Richard Trieu 2011-09-06 21:13:51 +00:00
Родитель 08062aaaa5
Коммит def75847c5
1 изменённых файлов: 57 добавлений и 55 удалений

Просмотреть файл

@ -5786,11 +5786,12 @@ QualType Sema::CheckRemainderOperands(
/// \brief Diagnose invalid arithmetic on two void pointers. /// \brief Diagnose invalid arithmetic on two void pointers.
static void diagnoseArithmeticOnTwoVoidPointers(Sema &S, SourceLocation Loc, static void diagnoseArithmeticOnTwoVoidPointers(Sema &S, SourceLocation Loc,
Expr *LHS, Expr *RHS) { Expr *LHSExpr, Expr *RHSExpr) {
S.Diag(Loc, S.getLangOptions().CPlusPlus S.Diag(Loc, S.getLangOptions().CPlusPlus
? diag::err_typecheck_pointer_arith_void_type ? diag::err_typecheck_pointer_arith_void_type
: diag::ext_gnu_void_ptr) : diag::ext_gnu_void_ptr)
<< 1 /* two pointers */ << LHS->getSourceRange() << RHS->getSourceRange(); << 1 /* two pointers */ << LHSExpr->getSourceRange()
<< RHSExpr->getSourceRange();
} }
/// \brief Diagnose invalid arithmetic on a void pointer. /// \brief Diagnose invalid arithmetic on a void pointer.
@ -5885,22 +5886,22 @@ static bool checkArithmeticOpPointerOperand(Sema &S, SourceLocation Loc,
/// ///
/// \returns True when the operand is valid to use (even if as an extension). /// \returns True when the operand is valid to use (even if as an extension).
static bool checkArithmeticBinOpPointerOperands(Sema &S, SourceLocation Loc, static bool checkArithmeticBinOpPointerOperands(Sema &S, SourceLocation Loc,
Expr *LHS, Expr *RHS) { Expr *LHSExpr, Expr *RHSExpr) {
bool isLHSPointer = LHS->getType()->isAnyPointerType(); bool isLHSPointer = LHSExpr->getType()->isAnyPointerType();
bool isRHSPointer = RHS->getType()->isAnyPointerType(); bool isRHSPointer = RHSExpr->getType()->isAnyPointerType();
if (!isLHSPointer && !isRHSPointer) return true; if (!isLHSPointer && !isRHSPointer) return true;
QualType LHSPointeeTy, RHSPointeeTy; QualType LHSPointeeTy, RHSPointeeTy;
if (isLHSPointer) LHSPointeeTy = LHS->getType()->getPointeeType(); if (isLHSPointer) LHSPointeeTy = LHSExpr->getType()->getPointeeType();
if (isRHSPointer) RHSPointeeTy = RHS->getType()->getPointeeType(); if (isRHSPointer) RHSPointeeTy = RHSExpr->getType()->getPointeeType();
// Check for arithmetic on pointers to incomplete types. // Check for arithmetic on pointers to incomplete types.
bool isLHSVoidPtr = isLHSPointer && LHSPointeeTy->isVoidType(); bool isLHSVoidPtr = isLHSPointer && LHSPointeeTy->isVoidType();
bool isRHSVoidPtr = isRHSPointer && RHSPointeeTy->isVoidType(); bool isRHSVoidPtr = isRHSPointer && RHSPointeeTy->isVoidType();
if (isLHSVoidPtr || isRHSVoidPtr) { if (isLHSVoidPtr || isRHSVoidPtr) {
if (!isRHSVoidPtr) diagnoseArithmeticOnVoidPointer(S, Loc, LHS); if (!isRHSVoidPtr) diagnoseArithmeticOnVoidPointer(S, Loc, LHSExpr);
else if (!isLHSVoidPtr) diagnoseArithmeticOnVoidPointer(S, Loc, RHS); else if (!isLHSVoidPtr) diagnoseArithmeticOnVoidPointer(S, Loc, RHSExpr);
else diagnoseArithmeticOnTwoVoidPointers(S, Loc, LHS, RHS); else diagnoseArithmeticOnTwoVoidPointers(S, Loc, LHSExpr, RHSExpr);
return !S.getLangOptions().CPlusPlus; return !S.getLangOptions().CPlusPlus;
} }
@ -5908,15 +5909,16 @@ static bool checkArithmeticBinOpPointerOperands(Sema &S, SourceLocation Loc,
bool isLHSFuncPtr = isLHSPointer && LHSPointeeTy->isFunctionType(); bool isLHSFuncPtr = isLHSPointer && LHSPointeeTy->isFunctionType();
bool isRHSFuncPtr = isRHSPointer && RHSPointeeTy->isFunctionType(); bool isRHSFuncPtr = isRHSPointer && RHSPointeeTy->isFunctionType();
if (isLHSFuncPtr || isRHSFuncPtr) { if (isLHSFuncPtr || isRHSFuncPtr) {
if (!isRHSFuncPtr) diagnoseArithmeticOnFunctionPointer(S, Loc, LHS); if (!isRHSFuncPtr) diagnoseArithmeticOnFunctionPointer(S, Loc, LHSExpr);
else if (!isLHSFuncPtr) diagnoseArithmeticOnFunctionPointer(S, Loc, RHS); else if (!isLHSFuncPtr) diagnoseArithmeticOnFunctionPointer(S, Loc,
else diagnoseArithmeticOnTwoFunctionPointers(S, Loc, LHS, RHS); RHSExpr);
else diagnoseArithmeticOnTwoFunctionPointers(S, Loc, LHSExpr, RHSExpr);
return !S.getLangOptions().CPlusPlus; return !S.getLangOptions().CPlusPlus;
} }
if (checkArithmeticIncompletePointerType(S, Loc, LHS)) return false; if (checkArithmeticIncompletePointerType(S, Loc, LHSExpr)) return false;
if (checkArithmeticIncompletePointerType(S, Loc, RHS)) return false; if (checkArithmeticIncompletePointerType(S, Loc, RHSExpr)) return false;
return true; return true;
} }
@ -5937,36 +5939,36 @@ static bool checkArithmethicPointerOnNonFragileABI(Sema &S,
/// \brief Warn when two pointers are incompatible. /// \brief Warn when two pointers are incompatible.
static void diagnosePointerIncompatibility(Sema &S, SourceLocation Loc, static void diagnosePointerIncompatibility(Sema &S, SourceLocation Loc,
Expr *LHS, Expr *RHS) { Expr *LHSExpr, Expr *RHSExpr) {
assert(LHS->getType()->isAnyPointerType()); assert(LHSExpr->getType()->isAnyPointerType());
assert(RHS->getType()->isAnyPointerType()); assert(RHSExpr->getType()->isAnyPointerType());
S.Diag(Loc, diag::err_typecheck_sub_ptr_compatible) S.Diag(Loc, diag::err_typecheck_sub_ptr_compatible)
<< LHS->getType() << RHS->getType() << LHS->getSourceRange() << LHSExpr->getType() << RHSExpr->getType() << LHSExpr->getSourceRange()
<< RHS->getSourceRange(); << RHSExpr->getSourceRange();
} }
QualType Sema::CheckAdditionOperands( // C99 6.5.6 QualType Sema::CheckAdditionOperands( // C99 6.5.6
ExprResult &lex, ExprResult &rex, SourceLocation Loc, QualType* CompLHSTy) { ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, QualType* CompLHSTy) {
if (lex.get()->getType()->isVectorType() || if (LHS.get()->getType()->isVectorType() ||
rex.get()->getType()->isVectorType()) { RHS.get()->getType()->isVectorType()) {
QualType compType = CheckVectorOperands(lex, rex, Loc, CompLHSTy); QualType compType = CheckVectorOperands(LHS, RHS, Loc, CompLHSTy);
if (CompLHSTy) *CompLHSTy = compType; if (CompLHSTy) *CompLHSTy = compType;
return compType; return compType;
} }
QualType compType = UsualArithmeticConversions(lex, rex, CompLHSTy); QualType compType = UsualArithmeticConversions(LHS, RHS, CompLHSTy);
if (lex.isInvalid() || rex.isInvalid()) if (LHS.isInvalid() || RHS.isInvalid())
return QualType(); return QualType();
// handle the common case first (both operands are arithmetic). // handle the common case first (both operands are arithmetic).
if (lex.get()->getType()->isArithmeticType() && if (LHS.get()->getType()->isArithmeticType() &&
rex.get()->getType()->isArithmeticType()) { RHS.get()->getType()->isArithmeticType()) {
if (CompLHSTy) *CompLHSTy = compType; if (CompLHSTy) *CompLHSTy = compType;
return compType; return compType;
} }
// Put any potential pointer into PExp // Put any potential pointer into PExp
Expr* PExp = lex.get(), *IExp = rex.get(); Expr* PExp = LHS.get(), *IExp = RHS.get();
if (IExp->getType()->isAnyPointerType()) if (IExp->getType()->isAnyPointerType())
std::swap(PExp, IExp); std::swap(PExp, IExp);
@ -5983,9 +5985,9 @@ QualType Sema::CheckAdditionOperands( // C99 6.5.6
CheckArrayAccess(PExp, IExp); CheckArrayAccess(PExp, IExp);
if (CompLHSTy) { if (CompLHSTy) {
QualType LHSTy = Context.isPromotableBitField(lex.get()); QualType LHSTy = Context.isPromotableBitField(LHS.get());
if (LHSTy.isNull()) { if (LHSTy.isNull()) {
LHSTy = lex.get()->getType(); LHSTy = LHS.get()->getType();
if (LHSTy->isPromotableIntegerType()) if (LHSTy->isPromotableIntegerType())
LHSTy = Context.getPromotedIntegerType(LHSTy); LHSTy = Context.getPromotedIntegerType(LHSTy);
} }
@ -5995,86 +5997,86 @@ QualType Sema::CheckAdditionOperands( // C99 6.5.6
} }
} }
return InvalidOperands(Loc, lex, rex); return InvalidOperands(Loc, LHS, RHS);
} }
// C99 6.5.6 // C99 6.5.6
QualType Sema::CheckSubtractionOperands(ExprResult &lex, ExprResult &rex, QualType Sema::CheckSubtractionOperands(ExprResult &LHS, ExprResult &RHS,
SourceLocation Loc, SourceLocation Loc,
QualType* CompLHSTy) { QualType* CompLHSTy) {
if (lex.get()->getType()->isVectorType() || if (LHS.get()->getType()->isVectorType() ||
rex.get()->getType()->isVectorType()) { RHS.get()->getType()->isVectorType()) {
QualType compType = CheckVectorOperands(lex, rex, Loc, CompLHSTy); QualType compType = CheckVectorOperands(LHS, RHS, Loc, CompLHSTy);
if (CompLHSTy) *CompLHSTy = compType; if (CompLHSTy) *CompLHSTy = compType;
return compType; return compType;
} }
QualType compType = UsualArithmeticConversions(lex, rex, CompLHSTy); QualType compType = UsualArithmeticConversions(LHS, RHS, CompLHSTy);
if (lex.isInvalid() || rex.isInvalid()) if (LHS.isInvalid() || RHS.isInvalid())
return QualType(); return QualType();
// Enforce type constraints: C99 6.5.6p3. // Enforce type constraints: C99 6.5.6p3.
// Handle the common case first (both operands are arithmetic). // Handle the common case first (both operands are arithmetic).
if (lex.get()->getType()->isArithmeticType() && if (LHS.get()->getType()->isArithmeticType() &&
rex.get()->getType()->isArithmeticType()) { RHS.get()->getType()->isArithmeticType()) {
if (CompLHSTy) *CompLHSTy = compType; if (CompLHSTy) *CompLHSTy = compType;
return compType; return compType;
} }
// Either ptr - int or ptr - ptr. // Either ptr - int or ptr - ptr.
if (lex.get()->getType()->isAnyPointerType()) { if (LHS.get()->getType()->isAnyPointerType()) {
QualType lpointee = lex.get()->getType()->getPointeeType(); QualType lpointee = LHS.get()->getType()->getPointeeType();
// Diagnose bad cases where we step over interface counts. // Diagnose bad cases where we step over interface counts.
if (!checkArithmethicPointerOnNonFragileABI(*this, Loc, lex.get())) if (!checkArithmethicPointerOnNonFragileABI(*this, Loc, LHS.get()))
return QualType(); return QualType();
// The result type of a pointer-int computation is the pointer type. // The result type of a pointer-int computation is the pointer type.
if (rex.get()->getType()->isIntegerType()) { if (RHS.get()->getType()->isIntegerType()) {
if (!checkArithmeticOpPointerOperand(*this, Loc, lex.get())) if (!checkArithmeticOpPointerOperand(*this, Loc, LHS.get()))
return QualType(); return QualType();
Expr *IExpr = rex.get()->IgnoreParenCasts(); Expr *IExpr = RHS.get()->IgnoreParenCasts();
UnaryOperator negRex(IExpr, UO_Minus, IExpr->getType(), VK_RValue, UnaryOperator negRex(IExpr, UO_Minus, IExpr->getType(), VK_RValue,
OK_Ordinary, IExpr->getExprLoc()); OK_Ordinary, IExpr->getExprLoc());
// Check array bounds for pointer arithemtic // Check array bounds for pointer arithemtic
CheckArrayAccess(lex.get()->IgnoreParenCasts(), &negRex); CheckArrayAccess(LHS.get()->IgnoreParenCasts(), &negRex);
if (CompLHSTy) *CompLHSTy = lex.get()->getType(); if (CompLHSTy) *CompLHSTy = LHS.get()->getType();
return lex.get()->getType(); return LHS.get()->getType();
} }
// Handle pointer-pointer subtractions. // Handle pointer-pointer subtractions.
if (const PointerType *RHSPTy if (const PointerType *RHSPTy
= rex.get()->getType()->getAs<PointerType>()) { = RHS.get()->getType()->getAs<PointerType>()) {
QualType rpointee = RHSPTy->getPointeeType(); QualType rpointee = RHSPTy->getPointeeType();
if (getLangOptions().CPlusPlus) { if (getLangOptions().CPlusPlus) {
// Pointee types must be the same: C++ [expr.add] // Pointee types must be the same: C++ [expr.add]
if (!Context.hasSameUnqualifiedType(lpointee, rpointee)) { if (!Context.hasSameUnqualifiedType(lpointee, rpointee)) {
diagnosePointerIncompatibility(*this, Loc, lex.get(), rex.get()); diagnosePointerIncompatibility(*this, Loc, LHS.get(), RHS.get());
} }
} else { } else {
// Pointee types must be compatible C99 6.5.6p3 // Pointee types must be compatible C99 6.5.6p3
if (!Context.typesAreCompatible( if (!Context.typesAreCompatible(
Context.getCanonicalType(lpointee).getUnqualifiedType(), Context.getCanonicalType(lpointee).getUnqualifiedType(),
Context.getCanonicalType(rpointee).getUnqualifiedType())) { Context.getCanonicalType(rpointee).getUnqualifiedType())) {
diagnosePointerIncompatibility(*this, Loc, lex.get(), rex.get()); diagnosePointerIncompatibility(*this, Loc, LHS.get(), RHS.get());
return QualType(); return QualType();
} }
} }
if (!checkArithmeticBinOpPointerOperands(*this, Loc, if (!checkArithmeticBinOpPointerOperands(*this, Loc,
lex.get(), rex.get())) LHS.get(), RHS.get()))
return QualType(); return QualType();
if (CompLHSTy) *CompLHSTy = lex.get()->getType(); if (CompLHSTy) *CompLHSTy = LHS.get()->getType();
return Context.getPointerDiffType(); return Context.getPointerDiffType();
} }
} }
return InvalidOperands(Loc, lex, rex); return InvalidOperands(Loc, LHS, RHS);
} }
static bool isScopedEnumerationType(QualType T) { static bool isScopedEnumerationType(QualType T) {