Bug 40485 - definitions of __builtin_abs() and abs() function in one module not diagnosed
Summary: definitions of __builtin_abs() and abs() function in one module not diagnosed
Status: RESOLVED DUPLICATE of bug 32455
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2009-06-18 09:20 UTC by Ivan Glushkov
Modified: 2009-06-21 22:45 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-06-18 09:35:53


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ivan Glushkov 2009-06-18 09:20:34 UTC
Hello.

gcc always replaces the name of the defined "__builtin_abs()" with "abs()". And it might cause the error if we also wants to define "abs()" function:

$ cat t.c
int abs(int a) {return 0;}
int __builtin_abs(int a) {return 0;}
int main(void)
{
    return (abs(-3) + __builtin_abs(-3));
}

$ gcc t.c -c
/tmp/ccdecizd.s: Assembler messages:
/tmp/ccdecizd.s:14: Error: symbol `abs' is already defined



In the case of "static" functions it's OK:

$ cat t.c
static int abs(int a) {return 0;}
static int __builtin_abs(int a) {return 0;}
int main(void)
{
    return (abs(-3) + __builtin_abs(-3));
}

$ gcc t.c -c ; echo $?
0

In this case we use unchanged names for the functions' call:

$ gcc t.c -S && grep call t.s
        call    abs
        call    __builtin_abs


This issue doesn't occur only on abs but also with the others builtins.

$ ~/programs/gcc-4.4.0/bin/gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ./configure --prefix=/home/glushkov/programs/gcc-4.4.0 --enable-languages=c,c++
Thread model: posix
gcc version 4.4.0 (GCC)

$ uname -a
Linux expert 2.6.23-gentoo-r9-c2-uni1 #1 SMP Thu Jun 5 13:00:21 MSD 2008 i686 Intel(R) Pentium(R) 4 CPU 3.40GHz GenuineIntel GNU/Linux
Comment 1 Richard Biener 2009-06-18 09:35:53 UTC
This is really invalid code, but we should diagnose it.
Comment 2 Ivan Glushkov 2009-06-18 09:48:07 UTC
Why invalid? And why non-static is not invalid?
Can you please give me reference to documentation where it's described?
Comment 3 Richard Biener 2009-06-18 13:48:13 UTC
The __builtin_ namespace is reserved by GCC.  There may be documentation
missing for this fact.
Comment 4 Andrew Pinski 2009-06-18 14:51:19 UTC
All of __* namespace s reserved for the implementor.
Comment 5 jsm-csl@polyomino.org.uk 2009-06-18 21:08:52 UTC
Subject: Re:  definitions of __builtin_abs() and abs() function
 in one module not diagnosed

What happened to the patch for PR 32455 to disallow __builtin_* 
declarations?  That PR indicates it was approved for 4.5.

Comment 6 Andrew Pinski 2009-06-21 22:45:40 UTC

*** This bug has been marked as a duplicate of 32455 ***