This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/14197] New: Wrong code for bcopy/memmove (string-asm-2.c)


string-asm-2.c from the gcc-testsuite fails on at least tree-ssa on
sparc-sun-solaris. The code generated for some bcopy-calls with -O is
wrong because it doesn't take overlapping memory into account.

The code in question essentially is this (see the testsuite for a full
example):

    char y[64] = "sometext";
    bcopy (y+1, y+2, 6);

The bcopy-call is rewritten by tree-ssa as

    bcopy (&y[1], &y[2], 6)

This triggers an optimization in the expander that tries to use
memcpy instead of memmove if the second operand of bcopy points
to read-only memory. This test is done like this by readonly_data_expr
in builtins.c:

    if (TREE_CODE (exp) == ADDR_EXPR)
      return decl_readonly_section (TREE_OPERAND (exp, 0), 0);
    else
      return false;

This is fine for an ADDR_EXPR that references a decl or a string constant
but what we actually have is an ADDR_EXPR that references an ARRAY_REF.
decl_readonly_section isn't prepared to deal with such a tree and
wrongly returns true (readonly) here.

I'll attach a patch that should fix this.

    regards  Christian

-- 
           Summary: Wrong code for bcopy/memmove (string-asm-2.c)
           Product: gcc
           Version: tree-ssa
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: critical
          Priority: P1
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ehrhardt at mathematik dot uni-ulm dot de
                CC: gcc-bugs at gcc dot gnu dot org


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]