[LLVMbugs] [Bug 7071] New: Less-than-awesome warning about unreachable code

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu May 6 08:48:32 PDT 2010


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

           Summary: Less-than-awesome warning about unreachable code
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
        AssignedTo: kremenek at apple.com
        ReportedBy: hv at crypt.org
                CC: llvmbugs at cs.uiuc.edu


zen% cat clangtest3.c
#define limited(type, value) type ? ((type * value <= 1) ? value : 1) : value
unsigned int arena_value = limited(0, sizeof(int));
zen% clang -c -W clangtest3.c
clangtest3.c:2:28: warning: comparison of 0 <= unsigned expression is always
      true [-Wsign-compare]
unsigned int arena_value = limited(0, sizeof(int));
                           ^~~~~~~~~~~~~~~~~~~~~~~
clangtest3.c:1:52: note: instantiated from:
#define limited(type, value) type ? ((type * value <= 1) ? value : 1) : value
                                                   ^  ~
1 warning generated.
zen% 

(This is cut down from an example using FIT_ARENA() in the perl source code.)

Note that if 'sizeof(int)' is replaced with a literal 4, this does not warn.
While the warning is true, it is unuseful: it would in principle be possible to
determine that due to the constant in the conditional, the complained-of code
is not reached.

Hugo

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list