http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60456

            Bug ID: 60456
           Summary: Uninitialized read in copy_rtx
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eugeni.stepanov at gmail dot com

Created attachment 32301
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32301&action=edit
proof

==26761== WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7f2c4996caa9 in copy_rtx(rtx_def*)
build-msan/gcc/../../gcc/rtl.c:263:42
    #1 0x7f2c49992513 in process_rtx(rtx_def*, int)
build-msan/gcc/../../gcc/gensupport.c:535
    #2 0x7f2c49992513 in rtx_handle_directive(int, char const*)
build-msan/gcc/../../gcc/gensupport.c:2243
    #3 0x7f2c499c4540 in handle_file(void (*)(int, char const*))
build-msan/gcc/../../gcc/read-md.c:984
    #4 0x7f2c499c39bd in handle_toplevel_file(void (*)(int, char const*))
build-msan/gcc/../../gcc/read-md.c:1010
    #5 0x7f2c499c2176 in read_md_files(int, char**, bool (*)(char const*), void
(*)(int, char const*)) build-msan/gcc/../../gcc/read-md.c:1138
    #6 0x7f2c4998a397 in init_rtx_reader_args_cb(int, char**, bool (*)(char
const*)) build-msan/gcc/../../gcc/gensupport.c:2504
    #7 0x7f2c4996017c in main build-msan/gcc/../../gcc/genpreds.c:1369

  Uninitialized value was created by a heap allocation
    #0 0x7f2c4990579d in malloc
/code/llvm/build0/../projects/compiler-rt/lib/msan/msan_interceptors.cc:781
    #1 0x7f2c499d4d80 in xmalloc
build-msan/build-x86_64-unknown-linux-gnu/libiberty/../../../libiberty/xmalloc.c:147
    #2 0x7f2c499878e9 in ggc_internal_alloc_stat(unsigned long)
build-msan/gcc/../../gcc/ggc-none.c:46
    #3 0x7f2c4996b469 in ggc_alloc_rtx_def_stat(unsigned long)
build-msan/gcc/../../gcc/ggc.h:257
    #4 0x7f2c4996afdc in rtx_alloc_stat(rtx_code)
build-msan/gcc/../../gcc/rtl.c:195:12
    #5 0x7f2c49980e84 in read_rtx_code(char const*)
build-msan/gcc/../../gcc/read-rtl.c:1127
    #6 0x7f2c49984c52 in read_nested_rtx()
build-msan/gcc/../../gcc/read-rtl.c:1351
    #7 0x7f2c499814fe in read_rtx_code(char const*)
build-msan/gcc/../../gcc/read-rtl.c:1156
    #8 0x7f2c49984c52 in read_nested_rtx()
build-msan/gcc/../../gcc/read-rtl.c:1351
    #9 0x7f2c49982c7b in read_rtx_code(char const*)
build-msan/gcc/../../gcc/read-rtl.c:1190
    #10 0x7f2c4997c44d in read_rtx(char const*, rtx_def**)
build-msan/gcc/../../gcc/read-rtl.c:1084
    #11 0x7f2c49991d39 in rtx_handle_directive(int, char const*)
build-msan/gcc/../../gcc/gensupport.c:2241
    #12 0x7f2c499c4540 in handle_file(void (*)(int, char const*))
build-msan/gcc/../../gcc/read-md.c:984
    #13 0x7f2c499c39bd in handle_toplevel_file(void (*)(int, char const*))
build-msan/gcc/../../gcc/read-md.c:1010
    #14 0x7f2c499c2176 in read_md_files(int, char**, bool (*)(char const*),
void (*)(int, char const*)) build-msan/gcc/../../gcc/read-md.c:1138
    #15 0x7f2c4998a397 in init_rtx_reader_args_cb(int, char**, bool (*)(char
const*)) build-msan/gcc/../../gcc/gensupport.c:2504
    #16 0x7f2c4996017c in main build-msan/gcc/../../gcc/genpreds.c:1369


Uninitialized memory comes from this expression on line 263:
  ORIGINAL_REGNO (XEXP (orig, 0))

To verify, apply the attached patch, go the build directory and run
./gcc/build/genpreds -h ../gcc/config/i386/i386.md

The patch fills malloc()-ed memory with a specific pattern and then finds that
pattern at the line above.

Reply via email to