[LLVMbugs] [Bug 20951] New: No -Wtautological-pointer-compare warning on variables within parentheses, and the column number might be improved

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Sep 15 14:06:24 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=20951

            Bug ID: 20951
           Summary: No -Wtautological-pointer-compare warning on variables
                    within parentheses, and the column number might be
                    improved
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: chengniansun at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Clang emits a -Wtautological-pointer-compare on the following expressions,
  NULL == &a,
but does not on the following one
  NULL == (&a)

Moreover, the column of this warning points to the location of the variable a,
but not the location of the comparison expression. Is this deliberate? I find
that a number of Clang warnings point to the operator location. 


========================================================================

$: cat t.c
#include <stdlib.h>
int f(short a) {
  if (NULL == 
             (&a)) { /*no warning here*/
    return 0;
  } else if (NULL ==
              &a) { /*warning here.*/
    return 2;
  } else 
    return 1;
}
$: clang-trunk -Wtautological-pointer-compare -c t.c
t.c:7:16: warning: comparison of address of 'a' equal to a null pointer is
always false [-Wtautological-pointer-compare]
              &a) { /*warning here.*/
               ^
1 warning generated.
$: gcc-trunk -Waddress -c t.c
t.c: In function ‘f’:
t.c:3:12: warning: the comparison will always evaluate as ‘false’ for the
address of ‘a’ will never be NULL [-Waddress]
   if (NULL == 
            ^
t.c:6:19: warning: the comparison will always evaluate as ‘false’ for the
address of ‘a’ will never be NULL [-Waddress]
   } else if (NULL ==
                   ^
$: clang-trunk -v
clang version 3.6.0 (trunk 217725)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.1
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Candidate multilib: .;@m64
Selected multilib: .;@m64
$:

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140915/c848fab8/attachment.html>


More information about the llvm-bugs mailing list