[LLVMbugs] [Bug 20144] New: Preprocessor generates bad code

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jun 27 01:12:16 PDT 2014


            Bug ID: 20144
           Summary: Preprocessor generates bad code
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: pelle at morth.org
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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) {
    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 (http://llvm.org/git/clang.git
db5f8b25707a23dd5852a35539775f7e8cf8896e) (http://llvm.org/git/llvm.git
Target: x86_64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation:
Selected GCC installation:
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

on CentOS.
Also tested with 3.4 release.

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/20140627/76d5d3e9/attachment.html>

More information about the llvm-bugs mailing list