From 75c1723b3c4585ef5e2fcef79bee6ee7ae3811c3 Mon Sep 17 00:00:00 2001 From: Steve Naroff Date: Wed, 13 Jun 2007 21:41:08 +0000 Subject: [PATCH] Bug #: Submitted by: Reviewed by: Fix CheckRelationalOperands/CheckEqualityOperands to deal with null pointer constants. The new logic also deals (more) correctly for non-pointer/integer operands. llvm-svn: 39654 --- clang/Sema/SemaExpr.cpp | 43 ++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/clang/Sema/SemaExpr.cpp b/clang/Sema/SemaExpr.cpp index 5934621a40d5..53c5b048db74 100644 --- a/clang/Sema/SemaExpr.cpp +++ b/clang/Sema/SemaExpr.cpp @@ -813,12 +813,22 @@ inline QualType Sema::CheckRelationalOperands( // C99 6.5.8 if (lType->isRealType() && rType->isRealType()) return Context.IntTy; - if (lType->isPointerType() && rType->isPointerType()) - return Context.IntTy; - - if (lType->isIntegerType() || rType->isIntegerType()) { // GCC extension. - Diag(loc, diag::ext_typecheck_comparison_of_pointer_integer); - return Context.IntTy; + if (lType->isPointerType()) { + if (rType->isPointerType()) + return Context.IntTy; + if (rType->isIntegerType()) { + if (!rex->isNullPointerConstant()) + Diag(loc, diag::ext_typecheck_comparison_of_pointer_integer, + lex->getSourceRange(), rex->getSourceRange()); + return Context.IntTy; // the previous diagnostic is a GCC extension. + } + } else if (rType->isPointerType()) { + if (lType->isIntegerType()) { + if (!lex->isNullPointerConstant()) + Diag(loc, diag::ext_typecheck_comparison_of_pointer_integer, + lex->getSourceRange(), rex->getSourceRange()); + return Context.IntTy; // the previous diagnostic is a GCC extension. + } } InvalidOperands(loc, lex, rex); return QualType(); @@ -832,12 +842,23 @@ inline QualType Sema::CheckEqualityOperands( // C99 6.5.9 if (lType->isArithmeticType() && rType->isArithmeticType()) return Context.IntTy; - if (lType->isPointerType() && rType->isPointerType()) - return Context.IntTy; - if (lType->isIntegerType() || rType->isIntegerType()) { // GCC extension. - Diag(loc, diag::ext_typecheck_comparison_of_pointer_integer); - return Context.IntTy; + if (lType->isPointerType()) { + if (rType->isPointerType()) + return Context.IntTy; + if (rType->isIntegerType()) { + if (!rex->isNullPointerConstant()) + Diag(loc, diag::ext_typecheck_comparison_of_pointer_integer, + lex->getSourceRange(), rex->getSourceRange()); + return Context.IntTy; // the previous diagnostic is a GCC extension. + } + } else if (rType->isPointerType()) { + if (lType->isIntegerType()) { + if (!lex->isNullPointerConstant()) + Diag(loc, diag::ext_typecheck_comparison_of_pointer_integer, + lex->getSourceRange(), rex->getSourceRange()); + return Context.IntTy; // the previous diagnostic is a GCC extension. + } } InvalidOperands(loc, lex, rex); return QualType();