[LLVMbugs] [Bug 13547] New: clang optimizes away null terminator

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Aug 7 13:57:52 PDT 2012


             Bug #: 13547
           Summary: clang optimizes away null terminator
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: other
            Status: NEW
          Severity: normal
          Priority: P
         Component: Driver
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: dhill at mindcry.org
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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

        char buf[1024], *c;
        int i;

        for (i = 0; i < 100; i++)
                buf[i] = '/';
        buf[i] = '\0';

        c = strdup(buf);
        printf("%s\n", c);

        return (0);

when compiled with -O0, the above code works normally.  With any optimization
enabled, the "buf[i] = '\0'" is discarded.

(dhill at olive ~/code)$ clang -O0 -o test test.c
(dhill at olive ~/code)$ ./test

(dhill at olive ~/code)$ clang -O1 -o test test.c 
(dhill at olive ~/code)$ ./test                   

Can anyone reproduce this with the current trunk?

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