[PATCH] D67658: Revert "[SLC] Preserve attrs for strncpy(x, "", y) -> memset(align 1 x, '\0', y)"

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 17 08:43:03 PDT 2019


xbolva00 added a comment.

>> so for "strncat(to - 1, from, 0)" we eliminate strncat call and return "to - 1" ptr. (patch does not change the behaviour here).

No.

char *foo(char *s, char *p) {

  return strncat(s, p, 0);

}

GCC 
foo(char*, char*):

  movq    %rdi, %rax
  ret

Clang before  https://reviews.llvm.org/rL372091
_Z3fooPcS_:                             # @_Z3fooPcS_
	.cfi_startproc

%bb.0:
======

xorl	%edx, %edx
	jmp	strncat                 # TAILCALL

Clang after
_Z3fooPcS_:
.LFB27:
	.cfi_startproc
	movq	%rdi, %rax
ret

But Clang already had pattern for that!

  // Handle the simple, do-nothing cases:
  // strncat(x, "", c) -> x
  // strncat(x,  c, 0) -> x
  if (SrcLen == 0 || Len == 0)
    return Dst;

But somehow it wasn't working.

@krasimir for "strncat(s, p, 0);" there is no libcall and probably this is reason why test failed. Could you please fix test for new behaviour? (well, either remove it or change to 1), please?

I am sorry for late investigation, I was out of PC..


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67658/new/

https://reviews.llvm.org/D67658





More information about the llvm-commits mailing list