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: [email protected]
        ReportedBy: [email protected]
                CC: [email protected]


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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to