Bug 87387 - trunk/gcc/builtins.c:585:7: warning: -Wself-assign problem
Summary: trunk/gcc/builtins.c:585:7: warning: -Wself-assign problem
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: ---
Assignee: Jeffrey A. Law
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2018-09-21 19:54 UTC by David Binderman
Modified: 2019-03-28 06:58 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Binderman 2018-09-21 19:54:34 UTC
Source code is

     if (code == ADDR_EXPR
          && TREE_CODE (TREE_OPERAND (rhs1, 0)) == ARRAY_REF)
        rhs1 = rhs1;

svn blame says

264328        law       if (code == ADDR_EXPR
264328        law         && TREE_CODE (TREE_OPERAND (rhs1, 0)) == ARRAY_REF)
264328        law       rhs1 = rhs1;
Comment 1 David Binderman 2018-09-23 10:42:42 UTC
I found this bug by compiling gcc with the new clang 7.0

It seems that gcc can't be encouraged to warn about self-assignment.

For example:

$cat sep23a.cc
// -Wself-assign. clang has it. gcc doesn't.

extern void g( int);

void f(int n)
{
	int m = 2 * n;

	m = m;

	g( m);
}

$ ~/gcc/results/bin/gcc -c -O2 -Wall -Wextra sep23a.cc
$ 

Given that this warning finds bugs in gcc itself, would this
-Wself-assign warning be worth implementing in gcc ?

I'll have a go at compiling the rest of the world with clang-7.0
and see what it finds.
Comment 2 David Binderman 2018-09-23 10:48:25 UTC
Looks like an old implementation:

https://gcc.gnu.org/ml/gcc-patches/2010-06/msg02390.html

It might be worth using this as a starting point.
Comment 3 Eric Gallager 2018-09-23 18:38:09 UTC
(In reply to David Binderman from comment #1)
> I found this bug by compiling gcc with the new clang 7.0
> 
> It seems that gcc can't be encouraged to warn about self-assignment.
> 
> For example:
> 
> $cat sep23a.cc
> // -Wself-assign. clang has it. gcc doesn't.
> 
> extern void g( int);
> 
> void f(int n)
> {
> 	int m = 2 * n;
> 
> 	m = m;
> 
> 	g( m);
> }
> 
> $ ~/gcc/results/bin/gcc -c -O2 -Wall -Wextra sep23a.cc
> $ 
> 
> Given that this warning finds bugs in gcc itself, would this
> -Wself-assign warning be worth implementing in gcc ?

That's bug 53129.

> 
> I'll have a go at compiling the rest of the world with clang-7.0
> and see what it finds.
Comment 4 Jeffrey A. Law 2018-09-25 22:18:17 UTC
Author: law
Date: Tue Sep 25 22:17:45 2018
New Revision: 264585

URL: https://gcc.gnu.org/viewcvs?rev=264585&root=gcc&view=rev
Log:
	PR c/87387
        * builtins.c (unterminated_array): Simplify.
	* expr.c (string_constant): Handle SSA_NAME.  Add more exceptions
	where pointer arithmetic is safe.

	* gcc.dg/warn-stpcpy-no-nul.c: Drop unnecessary xfails.
	* gcc.dg/warn-stplen-no-nul.c: Likewise.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/builtins.c
    trunk/gcc/expr.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/warn-stpcpy-no-nul.c
    trunk/gcc/testsuite/gcc.dg/warn-strlen-no-nul.c
Comment 5 Jeffrey A. Law 2018-09-25 22:18:31 UTC
Fixed on the trunk.
Comment 6 jamespharvey20 2018-10-21 07:18:33 UTC
This fix introduces bug 87672.