From: Richard Trieu Date: Thu, 15 Sep 2011 21:56:47 +0000 (+0000) Subject: Finish the lex->LHS and rex->RHS cleanup in Sema. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dd22509c82eb7681a0f46b41d61cb2e25a4d8fa1;p=clang Finish the lex->LHS and rex->RHS cleanup in Sema. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139856 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index c08244490a..e5afd2d1ac 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -5614,7 +5614,7 @@ public: QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS, ExprResult &RHS); QualType CheckPointerToMemberOperands( // C++ 5.5 - ExprResult &lex, ExprResult &rex, ExprValueKind &VK, + ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK, SourceLocation OpLoc, bool isIndirect); QualType CheckMultiplyDivideOperands( // C99 6.5.5 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign, @@ -6059,7 +6059,7 @@ private: void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, SourceLocation ReturnLoc); - void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex); + void CheckFloatComparison(SourceLocation Loc, Expr* LHS, Expr* RHS); void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation()); void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field, diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 52a20798e7..6e750c182b 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -2504,11 +2504,11 @@ do { /// Check for comparisons of floating point operands using != and ==. /// Issue a warning if these are no self-comparisons, as they are not likely /// to do what the programmer intended. -void Sema::CheckFloatComparison(SourceLocation loc, Expr* lex, Expr *rex) { +void Sema::CheckFloatComparison(SourceLocation Loc, Expr* LHS, Expr *RHS) { bool EmitWarning = true; - Expr* LeftExprSansParen = lex->IgnoreParenImpCasts(); - Expr* RightExprSansParen = rex->IgnoreParenImpCasts(); + Expr* LeftExprSansParen = LHS->IgnoreParenImpCasts(); + Expr* RightExprSansParen = RHS->IgnoreParenImpCasts(); // Special case: check for x == x (which is OK). // Do not emit warnings for such cases. @@ -2547,8 +2547,8 @@ void Sema::CheckFloatComparison(SourceLocation loc, Expr* lex, Expr *rex) { // Emit the diagnostic. if (EmitWarning) - Diag(loc, diag::warn_floatingpoint_eq) - << lex->getSourceRange() << rex->getSourceRange(); + Diag(Loc, diag::warn_floatingpoint_eq) + << LHS->getSourceRange() << RHS->getSourceRange(); } //===--- CHECK: Integer mixed-sign comparisons (-Wsign-compare) --------===// @@ -3013,10 +3013,7 @@ void AnalyzeImpConvsInComparison(Sema &S, BinaryOperator *E) { /// \brief Implements -Wsign-compare. /// -/// \param lex the left-hand expression -/// \param rex the right-hand expression -/// \param OpLoc the location of the joining operator -/// \param BinOpc binary opcode or 0 +/// \param E the binary operator to check for warnings void AnalyzeComparison(Sema &S, BinaryOperator *E) { // The type the comparison is being performed in. QualType T = E->getLHS()->getType(); @@ -3033,20 +3030,20 @@ void AnalyzeComparison(Sema &S, BinaryOperator *E) { || E->isValueDependent() || E->isIntegerConstantExpr(S.Context)) return AnalyzeImpConvsInComparison(S, E); - Expr *lex = E->getLHS()->IgnoreParenImpCasts(); - Expr *rex = E->getRHS()->IgnoreParenImpCasts(); + Expr *LHS = E->getLHS()->IgnoreParenImpCasts(); + Expr *RHS = E->getRHS()->IgnoreParenImpCasts(); // Check to see if one of the (unmodified) operands is of different // signedness. Expr *signedOperand, *unsignedOperand; - if (lex->getType()->hasSignedIntegerRepresentation()) { - assert(!rex->getType()->hasSignedIntegerRepresentation() && + if (LHS->getType()->hasSignedIntegerRepresentation()) { + assert(!RHS->getType()->hasSignedIntegerRepresentation() && "unsigned comparison between two signed integer expressions?"); - signedOperand = lex; - unsignedOperand = rex; - } else if (rex->getType()->hasSignedIntegerRepresentation()) { - signedOperand = rex; - unsignedOperand = lex; + signedOperand = LHS; + unsignedOperand = RHS; + } else if (RHS->getType()->hasSignedIntegerRepresentation()) { + signedOperand = RHS; + unsignedOperand = LHS; } else { CheckTrivialUnsignedComparison(S, E); return AnalyzeImpConvsInComparison(S, E); @@ -3057,8 +3054,8 @@ void AnalyzeComparison(Sema &S, BinaryOperator *E) { // Go ahead and analyze implicit conversions in the operands. Note // that we skip the implicit conversions on both sides. - AnalyzeImplicitConversions(S, lex, E->getOperatorLoc()); - AnalyzeImplicitConversions(S, rex, E->getOperatorLoc()); + AnalyzeImplicitConversions(S, LHS, E->getOperatorLoc()); + AnalyzeImplicitConversions(S, RHS, E->getOperatorLoc()); // If the signed range is non-negative, -Wsign-compare won't fire, // but we should still check for comparisons which are always true @@ -3083,8 +3080,8 @@ void AnalyzeComparison(Sema &S, BinaryOperator *E) { } S.Diag(E->getOperatorLoc(), diag::warn_mixed_sign_comparison) - << lex->getType() << rex->getType() - << lex->getSourceRange() << rex->getSourceRange(); + << LHS->getType() << RHS->getType() + << LHS->getSourceRange() << RHS->getSourceRange(); } /// Analyzes an attempt to assign the given value to a bitfield. diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 08f4c437c3..98f96bc68d 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -3269,34 +3269,34 @@ ExprResult Sema::BuildExpressionTrait(ExpressionTrait ET, RParen, Context.BoolTy)); } -QualType Sema::CheckPointerToMemberOperands(ExprResult &lex, ExprResult &rex, +QualType Sema::CheckPointerToMemberOperands(ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK, SourceLocation Loc, bool isIndirect) { - assert(!lex.get()->getType()->isPlaceholderType() && - !rex.get()->getType()->isPlaceholderType() && + assert(!LHS.get()->getType()->isPlaceholderType() && + !RHS.get()->getType()->isPlaceholderType() && "placeholders should have been weeded out by now"); // The LHS undergoes lvalue conversions if this is ->*. if (isIndirect) { - lex = DefaultLvalueConversion(lex.take()); - if (lex.isInvalid()) return QualType(); + LHS = DefaultLvalueConversion(LHS.take()); + if (LHS.isInvalid()) return QualType(); } // The RHS always undergoes lvalue conversions. - rex = DefaultLvalueConversion(rex.take()); - if (rex.isInvalid()) return QualType(); + RHS = DefaultLvalueConversion(RHS.take()); + if (RHS.isInvalid()) return QualType(); const char *OpSpelling = isIndirect ? "->*" : ".*"; // C++ 5.5p2 // The binary operator .* [p3: ->*] binds its second operand, which shall // be of type "pointer to member of T" (where T is a completely-defined // class type) [...] - QualType RType = rex.get()->getType(); - const MemberPointerType *MemPtr = RType->getAs(); + QualType RHSType = RHS.get()->getType(); + const MemberPointerType *MemPtr = RHSType->getAs(); if (!MemPtr) { Diag(Loc, diag::err_bad_memptr_rhs) - << OpSpelling << RType << rex.get()->getSourceRange(); + << OpSpelling << RHSType << RHS.get()->getSourceRange(); return QualType(); } @@ -3312,21 +3312,21 @@ QualType Sema::CheckPointerToMemberOperands(ExprResult &lex, ExprResult &rex, // [...] to its first operand, which shall be of class T or of a class of // which T is an unambiguous and accessible base class. [p3: a pointer to // such a class] - QualType LType = lex.get()->getType(); + QualType LHSType = LHS.get()->getType(); if (isIndirect) { - if (const PointerType *Ptr = LType->getAs()) - LType = Ptr->getPointeeType(); + if (const PointerType *Ptr = LHSType->getAs()) + LHSType = Ptr->getPointeeType(); else { Diag(Loc, diag::err_bad_memptr_lhs) - << OpSpelling << 1 << LType + << OpSpelling << 1 << LHSType << FixItHint::CreateReplacement(SourceRange(Loc), ".*"); return QualType(); } } - if (!Context.hasSameUnqualifiedType(Class, LType)) { + if (!Context.hasSameUnqualifiedType(Class, LHSType)) { // If we want to check the hierarchy, we need a complete type. - if (RequireCompleteType(Loc, LType, PDiag(diag::err_bad_memptr_lhs) + if (RequireCompleteType(Loc, LHSType, PDiag(diag::err_bad_memptr_lhs) << OpSpelling << (int)isIndirect)) { return QualType(); } @@ -3334,23 +3334,24 @@ QualType Sema::CheckPointerToMemberOperands(ExprResult &lex, ExprResult &rex, /*DetectVirtual=*/false); // FIXME: Would it be useful to print full ambiguity paths, or is that // overkill? - if (!IsDerivedFrom(LType, Class, Paths) || + if (!IsDerivedFrom(LHSType, Class, Paths) || Paths.isAmbiguous(Context.getCanonicalType(Class))) { Diag(Loc, diag::err_bad_memptr_lhs) << OpSpelling - << (int)isIndirect << lex.get()->getType(); + << (int)isIndirect << LHS.get()->getType(); return QualType(); } // Cast LHS to type of use. QualType UseType = isIndirect ? Context.getPointerType(Class) : Class; ExprValueKind VK = - isIndirect ? VK_RValue : CastCategory(lex.get()); + isIndirect ? VK_RValue : CastCategory(LHS.get()); CXXCastPath BasePath; BuildBasePathArray(Paths, BasePath); - lex = ImpCastExprToType(lex.take(), UseType, CK_DerivedToBase, VK, &BasePath); + LHS = ImpCastExprToType(LHS.take(), UseType, CK_DerivedToBase, VK, + &BasePath); } - if (isa(rex.get()->IgnoreParens())) { + if (isa(RHS.get()->IgnoreParens())) { // Diagnose use of pointer-to-member type which when used as // the functional cast in a pointer-to-member expression. Diag(Loc, diag::err_pointer_to_member_type) << isIndirect; @@ -3363,7 +3364,7 @@ QualType Sema::CheckPointerToMemberOperands(ExprResult &lex, ExprResult &rex, // The cv qualifiers are the union of those in the pointer and the left side, // in accordance with 5.5p5 and 5.2.5. QualType Result = MemPtr->getPointeeType(); - Result = Context.getCVRQualifiedType(Result, LType.getCVRQualifiers()); + Result = Context.getCVRQualifiedType(Result, LHSType.getCVRQualifiers()); // C++0x [expr.mptr.oper]p6: // In a .* expression whose object expression is an rvalue, the program is @@ -3378,15 +3379,15 @@ QualType Sema::CheckPointerToMemberOperands(ExprResult &lex, ExprResult &rex, break; case RQ_LValue: - if (!isIndirect && !lex.get()->Classify(Context).isLValue()) + if (!isIndirect && !LHS.get()->Classify(Context).isLValue()) Diag(Loc, diag::err_pointer_to_member_oper_value_classify) - << RType << 1 << lex.get()->getSourceRange(); + << RHSType << 1 << LHS.get()->getSourceRange(); break; case RQ_RValue: - if (isIndirect || !lex.get()->Classify(Context).isRValue()) + if (isIndirect || !LHS.get()->Classify(Context).isRValue()) Diag(Loc, diag::err_pointer_to_member_oper_value_classify) - << RType << 0 << lex.get()->getSourceRange(); + << RHSType << 0 << LHS.get()->getSourceRange(); break; } } @@ -3404,7 +3405,7 @@ QualType Sema::CheckPointerToMemberOperands(ExprResult &lex, ExprResult &rex, } else if (isIndirect) { VK = VK_LValue; } else { - VK = lex.get()->getValueKind(); + VK = LHS.get()->getValueKind(); } return Result;