diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Sema/Sema.h | 3 | ||||
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 12 | ||||
-rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 2 |
3 files changed, 12 insertions, 5 deletions
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h index e97417680b0..4c81cb18de7 100644 --- a/clang/lib/Sema/Sema.h +++ b/clang/lib/Sema/Sema.h @@ -1609,6 +1609,9 @@ public: void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, Expr **Args, unsigned NumArgs); + void CheckSignCompare(Expr *LHS, Expr *RHS, SourceLocation Loc, + const PartialDiagnostic &PD); + virtual ExpressionEvaluationContext PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext); diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index c9a28a74ee0..f1d6f2bb17c 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -3340,6 +3340,8 @@ QualType Sema::CheckConditionalOperands(Expr *&Cond, Expr *&LHS, Expr *&RHS, if (getLangOptions().CPlusPlus) return CXXCheckConditionalOperands(Cond, LHS, RHS, QuestionLoc); + CheckSignCompare(LHS, RHS, QuestionLoc, diag::warn_mixed_sign_conditional); + UsualUnaryConversions(Cond); UsualUnaryConversions(LHS); UsualUnaryConversions(RHS); @@ -4428,8 +4430,8 @@ QualType Sema::CheckShiftOperands(Expr *&lex, Expr *&rex, SourceLocation Loc, } /// Implements -Wsign-compare. -static void DiagnoseSignCompare(Sema &S, Expr *lex, Expr *rex, - BinaryOperator::Opcode Opc, SourceLocation OpLoc) { +void Sema::CheckSignCompare(Expr *lex, Expr *rex, SourceLocation OpLoc, + const PartialDiagnostic &PD) { QualType lt = lex->getType(), rt = rex->getType(); // Only warn if both operands are integral. @@ -4450,14 +4452,14 @@ static void DiagnoseSignCompare(Sema &S, Expr *lex, Expr *rex, // If the value is a non-negative integer constant, then the // signed->unsigned conversion won't change it. llvm::APSInt value; - if (signedOperand->isIntegerConstantExpr(value, S.Context)) { + if (signedOperand->isIntegerConstantExpr(value, Context)) { assert(value.isSigned() && "result of signed expression not signed"); if (value.isNonNegative()) return; } - S.Diag(OpLoc, diag::warn_mixed_sign_comparison) + Diag(OpLoc, PD) << lex->getType() << rex->getType() << lex->getSourceRange() << rex->getSourceRange(); } @@ -4470,7 +4472,7 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc, if (lex->getType()->isVectorType() || rex->getType()->isVectorType()) return CheckVectorCompareOperands(lex, rex, Loc, isRelational); - DiagnoseSignCompare(*this, lex, rex, Opc, Loc); + CheckSignCompare(lex, rex, Loc, diag::warn_mixed_sign_comparison); // C99 6.5.8p3 / C99 6.5.9p4 if (lex->getType()->isArithmeticType() && rex->getType()->isArithmeticType()) diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 6fdecc26752..dc576815735 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -1603,6 +1603,8 @@ QualType Sema::CXXCheckConditionalOperands(Expr *&Cond, Expr *&LHS, Expr *&RHS, if (LHS->isTypeDependent() || RHS->isTypeDependent()) return Context.DependentTy; + CheckSignCompare(LHS, RHS, QuestionLoc, diag::warn_mixed_sign_conditional); + // C++0x 5.16p2 // If either the second or the third operand has type (cv) void, ... QualType LTy = LHS->getType(); |