<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Preprocessor generates bad code"
   href="http://llvm.org/bugs/show_bug.cgi?id=20144">20144</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Preprocessor generates bad code
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Frontend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>pelle@morth.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>clang -O2 -E generates bad code for this code:

#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[]) {
    if (argc > 3) {
        if (strcmp(argv[1], "-4") == 0) {
            printf("wat\n");
        }
    }
    return 0;
}

It seems to believe sizeof("-4") is 4 rather than 3.

Might be a duplicate of 11536, not sure.


Steps to reproduce:

clang -O2 -E bug.c | clang -Werror -x c -


Expected result:

bug.o generated


Actual result:

dummy.c:6:2109: error: array index 3 is past the end of the array (which
contains 3 elements) [-Werror,-Warray-bounds]
  ...> 2 && __result == 0) __result = (__s1[3] - ((__const unsigned char *)
(__const char *) ("-4"))[3]); } } __result; }))) : __...
                                                                               
              ^      ~
1 error generated.


Version info:
clang version 3.5.0 (<a href="http://llvm.org/git/clang.git">http://llvm.org/git/clang.git</a>
db5f8b25707a23dd5852a35539775f7e8cf8896e) (<a href="http://llvm.org/git/llvm.git">http://llvm.org/git/llvm.git</a>
0263debd04a3a827ac0e11968082d1c6fe0a9902)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation:
/opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/4.8.2
Selected GCC installation:
/opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/4.8.2
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

on CentOS.
Also tested with 3.4 release.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>