From 0fc95ad7584eacbf5b82a4890709e54b44318351 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Thu, 18 Dec 2014 23:14:51 +0000 Subject: [PATCH] [c Sema]. Patch fixes pointer-bool-conversion warning on C code 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 | 4 ++-- clang/test/Sema/warn-tautological-compare.c | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 5504741..55de708 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -6685,11 +6685,11 @@ void AnalyzeImplicitConversions(Sema &S, Expr *OrigE, SourceLocation CC) { if (BO && BO->isLogicalOp()) { Expr *SubExpr = BO->getLHS()->IgnoreParenImpCasts(); if (!IsLogicalAndOperator || !isa(SubExpr)) - ::CheckBoolLikeConversion(S, SubExpr, SubExpr->getExprLoc()); + ::CheckBoolLikeConversion(S, SubExpr, BO->getExprLoc()); SubExpr = BO->getRHS()->IgnoreParenImpCasts(); if (!IsLogicalAndOperator || !isa(SubExpr)) - ::CheckBoolLikeConversion(S, SubExpr, SubExpr->getExprLoc()); + ::CheckBoolLikeConversion(S, SubExpr, BO->getExprLoc()); } if (const UnaryOperator *U = dyn_cast(E)) diff --git a/clang/test/Sema/warn-tautological-compare.c b/clang/test/Sema/warn-tautological-compare.c index 2856edd..247e740 100644 --- a/clang/test/Sema/warn-tautological-compare.c +++ b/clang/test/Sema/warn-tautological-compare.c @@ -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); +} -- 2.7.4