forked from OSchip/llvm-project
compare.c also needs a target triple now, and improve some comments while we're
at it. llvm-svn: 86243
This commit is contained in:
parent
99ce6bfe28
commit
e46fd8531c
|
@ -4450,8 +4450,8 @@ QualType Sema::CheckShiftOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
|
||||||
/// \param lex the left-hand expression
|
/// \param lex the left-hand expression
|
||||||
/// \param rex the right-hand expression
|
/// \param rex the right-hand expression
|
||||||
/// \param OpLoc the location of the joining operator
|
/// \param OpLoc the location of the joining operator
|
||||||
/// \param Equality whether this is an "equality-like" join;
|
/// \param Equality whether this is an "equality-like" join, which
|
||||||
/// this suppresses the warning in some cases
|
/// suppresses the warning in some cases
|
||||||
void Sema::CheckSignCompare(Expr *lex, Expr *rex, SourceLocation OpLoc,
|
void Sema::CheckSignCompare(Expr *lex, Expr *rex, SourceLocation OpLoc,
|
||||||
const PartialDiagnostic &PD, bool Equality) {
|
const PartialDiagnostic &PD, bool Equality) {
|
||||||
QualType lt = lex->getType(), rt = rex->getType();
|
QualType lt = lex->getType(), rt = rex->getType();
|
||||||
|
@ -4479,8 +4479,8 @@ void Sema::CheckSignCompare(Expr *lex, Expr *rex, SourceLocation OpLoc,
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the unsigned type is strictly smaller than the signed type,
|
// If the unsigned type is strictly smaller than the signed type,
|
||||||
// then (1) the result type will be signed and (2) the unsigned type
|
// then (1) the result type will be signed and (2) the unsigned
|
||||||
// will fight losslessly within the signed type, and so the result
|
// value will fit fully within the signed type, and thus the result
|
||||||
// of the comparison will be exact.
|
// of the comparison will be exact.
|
||||||
if (Context.getIntWidth(signedOperand->getType()) >
|
if (Context.getIntWidth(signedOperand->getType()) >
|
||||||
Context.getIntWidth(unsignedOperand->getType()))
|
Context.getIntWidth(unsignedOperand->getType()))
|
||||||
|
@ -4498,9 +4498,9 @@ void Sema::CheckSignCompare(Expr *lex, Expr *rex, SourceLocation OpLoc,
|
||||||
|
|
||||||
if (Equality) {
|
if (Equality) {
|
||||||
// For (in)equality comparisons, if the unsigned operand is a
|
// For (in)equality comparisons, if the unsigned operand is a
|
||||||
// constant no greater than the maximum signed operand, then
|
// constant which cannot collide with a overflowed signed operand,
|
||||||
// reinterpreting the signed operand as unsigned will not change
|
// then reinterpreting the signed operand as unsigned will not
|
||||||
// the result of the comparison.
|
// change the result of the comparison.
|
||||||
if (unsignedOperand->isIntegerConstantExpr(value, Context)) {
|
if (unsignedOperand->isIntegerConstantExpr(value, Context)) {
|
||||||
assert(!value.isSigned() && "result of unsigned expression is signed");
|
assert(!value.isSigned() && "result of unsigned expression is signed");
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// RUN: clang-cc -fsyntax-only -pedantic -verify -Wsign-compare %s
|
// RUN: clang-cc -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare %s
|
||||||
|
|
||||||
int test(char *C) { // nothing here should warn.
|
int test(char *C) { // nothing here should warn.
|
||||||
return C != ((void*)0);
|
return C != ((void*)0);
|
||||||
|
|
Loading…
Reference in New Issue