[LLVMbugs] [Bug 9296] New: -Warray-bounds thinks 'true' is negative.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Feb 23 06:54:02 PST 2011


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

           Summary: -Warray-bounds thinks 'true' is negative.
           Product: new-bugs
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: fvbommel at gmail.com
                CC: llvmbugs at cs.uiuc.edu


Compiling this (C++) code:
=====
int foo() {
    int array[2];
    return array[true];
}
=====
results in this warning:
=====
test.cpp:3:12: warning: array index of '-1' indexes before the beginning of the
      array [-Warray-bounds]
    return array[true];
           ^     ~~~~
test.cpp:2:5: note: array 'array' declared here
    int array[2];
    ^
1 warning generated.
=====

even though the actual array access is compiled to:
=====
  %arrayidx = getelementptr inbounds [2 x i32]* %array, i32 0, i64 1
  %tmp = load i32* %arrayidx
=====
(meaning 'true' is treated as unsigned '1', not signed '-1' when actually
compiling the code, but the other way around when generating this warning)

Note also that '(int)true' evaluates to 1, so clearly booleans are usually
treated as unsigned.


In other words, the warning seems to be nagging me about perfectly functional
code.

-- 
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