[c Sema]. Patch fixes pointer-bool-conversion warning on C code
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 18 Dec 2014 23:14:51 +0000 (23:14 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 18 Dec 2014 23:14:51 +0000 (23:14 +0000)
when source range is incorrect causing the warning to be
issued when it should not because expression is in a macro.
rdar://19256338

llvm-svn: 224549

clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/warn-tautological-compare.c

index 5504741..55de708 100644 (file)
@@ -6685,11 +6685,11 @@ void AnalyzeImplicitConversions(Sema &S, Expr *OrigE, SourceLocation CC) {
   if (BO && BO->isLogicalOp()) {
     Expr *SubExpr = BO->getLHS()->IgnoreParenImpCasts();
     if (!IsLogicalAndOperator || !isa<StringLiteral>(SubExpr))
-      ::CheckBoolLikeConversion(S, SubExpr, SubExpr->getExprLoc());
+      ::CheckBoolLikeConversion(S, SubExpr, BO->getExprLoc());
 
     SubExpr = BO->getRHS()->IgnoreParenImpCasts();
     if (!IsLogicalAndOperator || !isa<StringLiteral>(SubExpr))
-      ::CheckBoolLikeConversion(S, SubExpr, SubExpr->getExprLoc());
+      ::CheckBoolLikeConversion(S, SubExpr, BO->getExprLoc());
   }
 
   if (const UnaryOperator *U = dyn_cast<UnaryOperator>(E))
index 2856edd..247e740 100644 (file)
@@ -77,4 +77,18 @@ void test3() {
        (!array && array[0])) {} // expected-warning {{address of array 'array' will always evaluate to 'true'}}
  }
 
-
+// rdar://19256338
+#define SAVE_READ(PTR, RESULT) if( (PTR) && *(PTR) ) *RESULT=*PTR;
+// Source
+typedef unsigned char Boolean;
+struct HTTPClientPrivate
+{
+   Boolean readSuspended;
+};
+typedef struct HTTPClientPrivate * HTTPClientRef;
+static void _HTTPClientErrorHandler( HTTPClientRef me)
+{
+  Boolean result;
+  SAVE_READ(&me->readSuspended, &result);
+}