Bug 25022 - failure to transform the unlocked stdio calls
Summary: failure to transform the unlocked stdio calls
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: 3.4.6
Assignee: Kaveh Ghazi
URL:
Keywords: missed-optimization
Depends on:
Blocks: 24729
  Show dependency treegraph
 
Reported: 2005-11-24 16:47 UTC by Kaveh Ghazi
Modified: 2005-12-04 01:54 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 3.4.5 4.0.3 4.1.0 4.2.0
Known to fail:
Last reconfirmed: 2005-11-24 16:51:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kaveh Ghazi 2005-11-24 16:47:10 UTC
Given the following program:

#define _GNU_SOURCE
#include <stdio.h>

int main ()
{
  fputs_unlocked("\n", stdout);
  return 0;
}

GCC fails to turn fputs_unlocked into fputc_unlocked.  This fails in all GCC versions as of 3.4 through mainline, but works in gcc-3.3 so it's a regression.  The regular "locked" stdio transformation fputs->fputc works.
Comment 1 Kaveh Ghazi 2005-11-24 16:51:00 UTC
This happens because the replacement functions are obtained in builtins.c from the array implicit_built_in_decls.  This array is initialized to null when the replacement function is an "extension" builtin, as are all _unlocked stdio calls.  Therefore, no _unlocked calls will ever be replaced with another _unlocked call.

I'm testing a patch.

Comment 2 Kaveh Ghazi 2005-11-26 01:25:26 UTC
Subject: Bug 25022

Author: ghazi
Date: Sat Nov 26 01:25:20 2005
New Revision: 107535

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107535
Log:
	PR middle-end/25022
	* builtins.c (expand_builtin_printf, expand_builtin_fprintf,
	fold_builtin_fputs, fold_builtin_printf, fold_builtin_fprintf):
	Lookup the explicit replacement functions for any unlocked
	stdio builtin transformations.

testsuite:
	* gcc.c-torture/execute/builtins/fprintf.c,
	gcc.c-torture/execute/builtins/fputs-lib.c,
	gcc.c-torture/execute/builtins/fputs.c,
	gcc.c-torture/execute/builtins/lib/fprintf.c,
	gcc.c-torture/execute/builtins/lib/printf.c,
	gcc.c-torture/execute/builtins/printf.c: Test the unlocked style.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/builtins.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.c-torture/execute/builtins/fprintf.c
    trunk/gcc/testsuite/gcc.c-torture/execute/builtins/fputs-lib.c
    trunk/gcc/testsuite/gcc.c-torture/execute/builtins/fputs.c
    trunk/gcc/testsuite/gcc.c-torture/execute/builtins/lib/fprintf.c
    trunk/gcc/testsuite/gcc.c-torture/execute/builtins/lib/printf.c
    trunk/gcc/testsuite/gcc.c-torture/execute/builtins/printf.c

Comment 3 Kaveh Ghazi 2005-11-26 01:31:58 UTC
Subject: Bug 25022

Author: ghazi
Date: Sat Nov 26 01:31:54 2005
New Revision: 107536

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107536
Log:
	PR middle-end/25022
	* builtins.c (expand_builtin_printf, expand_builtin_fprintf,
	fold_builtin_fputs, fold_builtin_printf, fold_builtin_fprintf):
	Lookup the explicit replacement functions for any unlocked
	stdio builtin transformations.

testsuite:
	* gcc.c-torture/execute/builtins/fprintf.c,
	gcc.c-torture/execute/builtins/fputs-lib.c,
	gcc.c-torture/execute/builtins/fputs.c,
	gcc.c-torture/execute/builtins/lib/fprintf.c,
	gcc.c-torture/execute/builtins/lib/printf.c,
	gcc.c-torture/execute/builtins/printf.c: Test the unlocked style.


Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/builtins.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_1-branch/gcc/testsuite/gcc.c-torture/execute/builtins/fprintf.c
    branches/gcc-4_1-branch/gcc/testsuite/gcc.c-torture/execute/builtins/fputs-lib.c
    branches/gcc-4_1-branch/gcc/testsuite/gcc.c-torture/execute/builtins/fputs.c
    branches/gcc-4_1-branch/gcc/testsuite/gcc.c-torture/execute/builtins/lib/fprintf.c
    branches/gcc-4_1-branch/gcc/testsuite/gcc.c-torture/execute/builtins/lib/printf.c
    branches/gcc-4_1-branch/gcc/testsuite/gcc.c-torture/execute/builtins/printf.c

Comment 4 Andrew Pinski 2005-11-26 03:27:31 UTC
Fixed at least on the 4.1 branch and the mainline.
Comment 5 Kaveh Ghazi 2005-11-27 14:47:26 UTC
4.0 patch here:
http://gcc.gnu.org/ml/gcc-patches/2005-11/msg01845.html
Comment 6 Kaveh Ghazi 2005-12-01 22:45:40 UTC
Updated 4.0 patch here:
http://gcc.gnu.org/ml/gcc-patches/2005-12/msg00089.html
Comment 7 Kaveh Ghazi 2005-12-02 14:05:15 UTC
Subject: Bug 25022

Author: ghazi
Date: Fri Dec  2 14:05:09 2005
New Revision: 107891

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107891
Log:
2005-11-30  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	PR middle-end/25022
	* builtins.c (expand_builtin_printf, expand_builtin_fprintf,
	fold_builtin_fputs): Lookup the explicit replacement functions
	for any unlocked stdio builtin transformations.

	PR middle-end/25158
	* builtins.c (fold_builtin_fputs): Defer check for missing
	replacement functions.

testsuite:
	* gcc.c-torture/execute/builtins/fprintf.c,
	gcc.c-torture/execute/builtins/fputs-lib.c,
	gcc.c-torture/execute/builtins/fputs.c,
	gcc.c-torture/execute/builtins/lib/fprintf.c,
	gcc.c-torture/execute/builtins/lib/printf.c,
	gcc.c-torture/execute/builtins/printf.c: Test the unlocked style.


Modified:
    branches/gcc-4_0-branch/gcc/ChangeLog
    branches/gcc-4_0-branch/gcc/builtins.c
    branches/gcc-4_0-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_0-branch/gcc/testsuite/gcc.c-torture/execute/builtins/fprintf.c
    branches/gcc-4_0-branch/gcc/testsuite/gcc.c-torture/execute/builtins/fputs-lib.c
    branches/gcc-4_0-branch/gcc/testsuite/gcc.c-torture/execute/builtins/fputs.c
    branches/gcc-4_0-branch/gcc/testsuite/gcc.c-torture/execute/builtins/lib/fprintf.c
    branches/gcc-4_0-branch/gcc/testsuite/gcc.c-torture/execute/builtins/lib/printf.c
    branches/gcc-4_0-branch/gcc/testsuite/gcc.c-torture/execute/builtins/printf.c

Comment 8 Kaveh Ghazi 2005-12-03 23:32:06 UTC
3.4 patch here:
http://gcc.gnu.org/ml/gcc-patches/2005-12/msg00284.html
Comment 9 Kaveh Ghazi 2005-12-04 01:37:26 UTC
Subject: Bug 25022

Author: ghazi
Date: Sun Dec  4 01:37:23 2005
New Revision: 108010

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=108010
Log:
2005-12-03  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	PR middle-end/25022
	* builtins.c (expand_builtin_fputs, expand_builtin_printf,
	expand_builtin_fprintf): Lookup the explicit replacement functions
	for any unlocked stdio builtin transformations.

	* builtins.c (expand_builtin_fputs): Defer check for missing
	replacement functions.

testsuite:
	* gcc.c-torture/execute/stdio-opt-1.c,
	gcc.c-torture/execute/stdio-opt-2.c,
	gcc.c-torture/execute/stdio-opt-3.c: Test the unlocked style.


Modified:
    branches/gcc-3_4-branch/gcc/ChangeLog
    branches/gcc-3_4-branch/gcc/builtins.c
    branches/gcc-3_4-branch/gcc/testsuite/ChangeLog
    branches/gcc-3_4-branch/gcc/testsuite/gcc.c-torture/execute/stdio-opt-1.c
    branches/gcc-3_4-branch/gcc/testsuite/gcc.c-torture/execute/stdio-opt-2.c
    branches/gcc-3_4-branch/gcc/testsuite/gcc.c-torture/execute/stdio-opt-3.c

Comment 10 Kaveh Ghazi 2005-12-04 01:54:41 UTC
Fixed on all active branches