diff options
author | John McCall <rjmccall@apple.com> | 2009-11-05 09:23:39 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2009-11-05 09:23:39 +0000 |
commit | 1fa36b7cabfa24ec4f61e2fb3807af3891dc9ee4 (patch) | |
tree | 9f98284ebc313a2b081c8eb18d794dab954ceba2 /clang/lib/Sema/SemaExpr.cpp | |
parent | c92ff053e9e5997d385182d509288cea438f969f (diff) | |
download | bcm5719-llvm-1fa36b7cabfa24ec4f61e2fb3807af3891dc9ee4.tar.gz bcm5719-llvm-1fa36b7cabfa24ec4f61e2fb3807af3891dc9ee4.zip |
Implement the conditional-operator part of -Wsign-compare. Turn
DiagnoseSignCompare into Sema::CheckSignCompare and call it from more places.
Add some enumerator tests. These seem to expose some oddities in the
types we're converting C++ enumerators to; in particular, they're converting
to unsigned before int, which seems to contradict 4.5 [conv.prom] p2.
Note to self: stop baiting Doug in my commit messages.
llvm-svn: 86128
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
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()) |