forked from OSchip/llvm-project
Eli points out that we really must diagnose "void* > 0" as an extension.
Explicitly add it as an EXTENSION instead of an EXTWARN so that it only comes out with -pedantic. Thanks Eli! llvm-svn: 79791
This commit is contained in:
parent
faeccc622f
commit
d99bd52c73
|
@ -1348,6 +1348,8 @@ def err_typecheck_sub_ptr_compatible : Error<
|
||||||
"%0 and %1 are not pointers to compatible types">;
|
"%0 and %1 are not pointers to compatible types">;
|
||||||
def ext_typecheck_ordered_comparison_of_pointer_integer : ExtWarn<
|
def ext_typecheck_ordered_comparison_of_pointer_integer : ExtWarn<
|
||||||
"ordered comparison between pointer and integer (%0 and %1)">;
|
"ordered comparison between pointer and integer (%0 and %1)">;
|
||||||
|
def ext_typecheck_ordered_comparison_of_pointer_and_zero : Extension<
|
||||||
|
"ordered comparison between pointer and zero (%0 and %1) is an extension">;
|
||||||
def ext_typecheck_ordered_comparison_of_function_pointers : ExtWarn<
|
def ext_typecheck_ordered_comparison_of_function_pointers : ExtWarn<
|
||||||
"ordered comparison of function pointers (%0 and %1)">;
|
"ordered comparison of function pointers (%0 and %1)">;
|
||||||
def ext_typecheck_comparison_of_pointer_integer : ExtWarn<
|
def ext_typecheck_comparison_of_pointer_integer : ExtWarn<
|
||||||
|
|
|
@ -4358,10 +4358,16 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (lType->isAnyPointerType() && rType->isIntegerType()) {
|
if (lType->isAnyPointerType() && rType->isIntegerType()) {
|
||||||
if (!RHSIsNull) {
|
unsigned DiagID = 0;
|
||||||
unsigned DiagID = isRelational
|
if (RHSIsNull) {
|
||||||
? diag::ext_typecheck_ordered_comparison_of_pointer_integer
|
if (isRelational)
|
||||||
: diag::ext_typecheck_comparison_of_pointer_integer;
|
DiagID = diag::ext_typecheck_ordered_comparison_of_pointer_and_zero;
|
||||||
|
} else if (isRelational)
|
||||||
|
DiagID = diag::ext_typecheck_ordered_comparison_of_pointer_integer;
|
||||||
|
else
|
||||||
|
DiagID = diag::ext_typecheck_comparison_of_pointer_integer;
|
||||||
|
|
||||||
|
if (DiagID) {
|
||||||
Diag(Loc, DiagID)
|
Diag(Loc, DiagID)
|
||||||
<< lType << rType << lex->getSourceRange() << rex->getSourceRange();
|
<< lType << rType << lex->getSourceRange() << rex->getSourceRange();
|
||||||
}
|
}
|
||||||
|
@ -4369,11 +4375,16 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
|
||||||
return ResultTy;
|
return ResultTy;
|
||||||
}
|
}
|
||||||
if (lType->isIntegerType() && rType->isAnyPointerType()) {
|
if (lType->isIntegerType() && rType->isAnyPointerType()) {
|
||||||
if (!LHSIsNull) {
|
unsigned DiagID = 0;
|
||||||
unsigned DiagID = isRelational
|
if (LHSIsNull) {
|
||||||
? diag::ext_typecheck_ordered_comparison_of_pointer_integer
|
if (isRelational)
|
||||||
: diag::ext_typecheck_comparison_of_pointer_integer;
|
DiagID = diag::ext_typecheck_ordered_comparison_of_pointer_and_zero;
|
||||||
|
} else if (isRelational)
|
||||||
|
DiagID = diag::ext_typecheck_ordered_comparison_of_pointer_integer;
|
||||||
|
else
|
||||||
|
DiagID = diag::ext_typecheck_comparison_of_pointer_integer;
|
||||||
|
|
||||||
|
if (DiagID) {
|
||||||
Diag(Loc, DiagID)
|
Diag(Loc, DiagID)
|
||||||
<< lType << rType << lex->getSourceRange() << rex->getSourceRange();
|
<< lType << rType << lex->getSourceRange() << rex->getSourceRange();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ int test(char *C) { // nothing here should warn.
|
||||||
return C != ((void*)0);
|
return C != ((void*)0);
|
||||||
return C != (void*)0;
|
return C != (void*)0;
|
||||||
return C != 0;
|
return C != 0;
|
||||||
|
return C != 1; // expected-warning {{comparison between pointer and integer ('char *' and 'int')}}
|
||||||
}
|
}
|
||||||
|
|
||||||
int equal(char *a, const char *b) {
|
int equal(char *a, const char *b) {
|
||||||
|
@ -18,7 +19,8 @@ int arrays(char (*a)[5], char(*b)[10], char(*c)[5]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int pointers(int *a) {
|
int pointers(int *a) {
|
||||||
return a > 0; // no warning. rdar://7163039
|
return a > 0; // expected-warning {{ordered comparison between pointer and zero ('int *' and 'int') is an extension}}
|
||||||
|
return a > 42; // expected-warning {{ordered comparison between pointer and integer ('int *' and 'int')}}
|
||||||
return a > (void *)0; // expected-warning {{comparison of distinct pointer types}}
|
return a > (void *)0; // expected-warning {{comparison of distinct pointer types}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue