First Last Prev Next    No search results available      Search page      Enter new bug
Bug#: 27781
Product:  
Component:  
Status: RESOLVED
Resolution: FIXED
Assigned To: Richard Guenther <rguenth@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: Jan Kiszka <jan.kiszka@web.de>
Add CC:
CC:
Remove selected CCs
Build:
URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 27781 depends on: Show dependency tree
Show dependency graph
Bug 27781 blocks:

Additional Comments:






View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: 2006-05-28 14:00 Opened: 2006-05-28 09:38
file-a.c:
---------
void __attribute__((weak)) func(void)
{
    /* no code */
}

main()
{
    func();
}


file-b.c:
---------
void func(void)
{
    printf("func\n");
}


# gcc -c file-a.c file-b.c -O2
# gcc -o program file-a.o file-b.o

The program will not print "func", because the call to func() was optimised out
during the compilation of file-a.c. This happens with -O2, but not when using
-fno-unit-at-a-time. First sighted in 4.1.

------- Comment #1 From Richard Guenther 2006-05-28 12:03 -------
ipa-pure-const thinks that func is const, which is wrong.  Then DCE comes along
and deletes the function call.

------- Comment #2 From Richard Guenther 2006-05-28 14:00 -------
I have a patch.

------- Comment #3 From Andrew Pinski 2006-05-28 15:23 -------
Actually no, you have to use -fPIC to get this not to be optimized, otherwise
func will be bound locally which is not what you want.

------- Comment #4 From Tom Rini 2006-06-01 18:36 -------
(In reply to comment #3)
> Actually no, you have to use -fPIC to get this not to be optimized, otherwise
> func will be bound locally which is not what you want.

Two things.  First, that's a change in behavior from how it used to work and I
don't recall seeing warnings about going-away behavior (the place this problem
is actually manifesting is in code for the Linux Kernel).

Second there is some sort of bug here as if we have:
$ cat file-a.c
void __attribute__((weak)) func(void)
{
        printf("weak\n");
}

main()
{
            func();
}
$ cat file-b.c
void func(void)
{
        printf("func\n");
}
$ gcc-4.1 -c file-a.c file-b.c -O2
file-a.c: In function 'func':
file-a.c:3: warning: incompatible implicit declaration of built-in function
'printf'
file-b.c: In function 'func':
file-b.c:3: warning: incompatible implicit declaration of built-in function
'printf'
$ gcc-4.1 -o program file-a.o file-b.o
$ ./program
func
$ gcc-4.1 -o program file-a.o
$ ./program
weak
$ gcc-4.1 -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,java,fortran,objc,obj-c++,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-awt=gtk --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.1-1.4.2.0/jre --enable-mpfr
--enable-checking=release x86_64-linux-gnu
Thread model: posix
gcc version 4.1.0 (Debian 4.1.0-1)

------- Comment #5 From patchapp@dberlin.org 2006-06-15 15:30 -------
Subject: Bug number PR27781

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is
http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00808.html

------- Comment #6 From Richard Guenther 2006-06-15 17:23 -------
Subject: Bug 27781

Author: rguenth
Date: Thu Jun 15 17:23:41 2006
New Revision: 114681

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114681
Log:
2006-06-16  Richard Guenther  <rguenther@suse.de>

        PR tree-optimization/27781
        * Makefile.in (ipa-pure-const.o): Add $(TARGET_H) dependency.
        * ipa-pure-const.c (target.h): Include.
        (analyze_function): Do not analyze functions that do not
        bind locally.

        * gcc.dg/tree-ssa/pr27781.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr27781.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/Makefile.in
    trunk/gcc/ipa-pure-const.c
    trunk/gcc/testsuite/ChangeLog

------- Comment #7 From Richard Guenther 2006-06-15 17:30 -------
Fixed on the mainline.

------- Comment #8 From Andrew Pinski 2006-06-16 17:50 -------
*** Bug 28055 has been marked as a duplicate of this bug. ***

------- Comment #9 From Richard Guenther 2006-06-21 15:36 -------
Fixed.

------- Comment #10 From Richard Guenther 2006-06-21 15:36 -------
Subject: Bug 27781

Author: rguenth
Date: Wed Jun 21 15:36:10 2006
New Revision: 114852

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114852
Log:
2006-06-21  Richard Guenther  <rguenther@suse.de>

        PR tree-optimization/27781
        * Makefile.in (ipa-pure-const.o): Add $(TARGET_H) dependency.
        * ipa-pure-const.c (target.h): Include.
        (analyze_function): Do not analyze functions that do not
        bind locally.

        * gcc.dg/tree-ssa/pr27781.c: New testcase.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/tree-ssa/pr27781.c
      - copied unchanged from r114681,
trunk/gcc/testsuite/gcc.dg/tree-ssa/pr27781.c
Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/Makefile.in
    branches/gcc-4_1-branch/gcc/ipa-pure-const.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog

First Last Prev Next    No search results available      Search page      Enter new bug