public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/16000] New: for h8 targets variadic functions are not working properly
@ 2004-06-15 14:05 manishas at kpitcummins dot com
2004-06-15 14:08 ` [Bug target/16000] " pinskia at gcc dot gnu dot org
` (5 more replies)
0 siblings, 6 replies; 8+ messages in thread
From: manishas at kpitcummins dot com @ 2004-06-15 14:05 UTC (permalink / raw)
To: gcc-bugs
Consider the attached test case for H8 target in which variadic function is
declared to take variable number of arguments but in the definition fixed
number of arguments are used. This is allowed in gcc as per document in
http://www.gnu.org/software/libc/manual/html_node/Why-Variadic.html#Why%
20Variadic
Following code does not pass arguments properly to the function. The variadic
function gives
wrong results because parameters are passed on stack and the function is
expects parameters in registers. Which can be observed from the following
assembly code
mov.w #3,r2
mov.l er2, @-er7 // push arg3 on stack
sub.l er2,er2
add.b #2,r2l
mov.l er2, @-er7 // push arg2 on stack
mov.w #1,r0 // move arg1 in er0
jsr @_variadic_test// call variadic_test function.
The register er7 is the stack pointer. So the arguments 2 and 3 are pushed onto
stack and argument1 is in register r0.And this is the assembler code in the
function variadic_test immediately after the jsr instruction above is executed:
mov.l er6, @-er7 // save frame pointer
mov.l er7,er6
.
.
mov.w r0,@(-2,er6) // get arg 1 from r0
mov.l er1,@(-8,er6) // get arg 2 from er1
mov.l er2,@(-12,er6) // get arg 3 from er2
The function sets up the stack and then copies the function arguments from the
registers r0, er1 and er2 onto the stack. But because of the different function
declaration the registers r0, er1 and er2 do not contain the expected values.
command line for assembly code:
h8300-elf-gcc -S -ms variadic.c main.c
command line for output file:
h8300-elf-gcc -o main.out variadic.c main.c
------------variadic.c------------------------------------
int variadic_test(int arg1, unsigned long arg2, unsigned long arg3)
{
int ret;
ret = arg1 + arg2 + arg3;
return ret;
}
----------------------------------------------------------------
------------------ main.c ----------------------------------------------
int variadic_test (int, unsigned long, ...);
int main (void)
{
int result_varfunc;
int result_local;
result_local = 1 + 2 + 3;
result_varfunc = variadic_test(1, 2, 3);
if (result_local != result_varfunc)
{
//printf("error");
return 0;
}
else
{
return 1;
}
}
--
Summary: for h8 targets variadic functions are not working
properly
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: manishas at kpitcummins dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: windows 2000
GCC target triplet: h8
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16000
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug target/16000] for h8 targets variadic functions are not working properly
2004-06-15 14:05 [Bug c/16000] New: for h8 targets variadic functions are not working properly manishas at kpitcummins dot com
@ 2004-06-15 14:08 ` pinskia at gcc dot gnu dot org
2004-06-15 14:12 ` manishas at kpitcummins dot com
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-15 14:08 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-06-15 14:08 -------
What version are you using?
--
What |Removed |Added
----------------------------------------------------------------------------
Component|c |target
Keywords| |wrong-code
Summary| for h8 targets variadic |for h8 targets variadic
|functions are not working |functions are not working
|properly |properly
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16000
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug target/16000] for h8 targets variadic functions are not working properly
2004-06-15 14:05 [Bug c/16000] New: for h8 targets variadic functions are not working properly manishas at kpitcummins dot com
2004-06-15 14:08 ` [Bug target/16000] " pinskia at gcc dot gnu dot org
@ 2004-06-15 14:12 ` manishas at kpitcummins dot com
2004-06-15 14:27 ` Graham Stott
2004-06-15 14:27 ` graham dot stott at btinternet dot com
` (3 subsequent siblings)
5 siblings, 1 reply; 8+ messages in thread
From: manishas at kpitcummins dot com @ 2004-06-15 14:12 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From manishas at kpitcummins dot com 2004-06-15 14:12 -------
Subject: RE: for h8 targets variadic functions are not working properly
gcc-3.4.0
-----Original Message-----
From: pinskia at gcc dot gnu dot org [mailto:gcc-bugzilla@gcc.gnu.org]
Sent: Tuesday, June 15, 2004 7:39 PM
To: Manisha V. Sagare
Subject: [Bug target/16000] for h8 targets variadic functions are not
working properly
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-06-15 14:08 -------
What version are you using?
--
What |Removed |Added
----------------------------------------------------------------------------
Component|c |target
Keywords| |wrong-code
Summary| for h8 targets variadic |for h8 targets variadic
|functions are not working |functions are not working
|properly |properly
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16000
------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16000
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug target/16000] for h8 targets variadic functions are not working properly
2004-06-15 14:05 [Bug c/16000] New: for h8 targets variadic functions are not working properly manishas at kpitcummins dot com
2004-06-15 14:08 ` [Bug target/16000] " pinskia at gcc dot gnu dot org
2004-06-15 14:12 ` manishas at kpitcummins dot com
@ 2004-06-15 14:27 ` graham dot stott at btinternet dot com
2004-06-15 15:26 ` bonzini at gnu dot org
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: graham dot stott at btinternet dot com @ 2004-06-15 14:27 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From graham dot stott at btinternet dot com 2004-06-15 14:27 -------
Subject: Re: for h8 targets variadic functions are not working properly
>Consider the attached test case for H8 target in which variadic function is
>declared to take variable number of arguments but in the definition fixed
>number of arguments are used. This is allowed in gcc as per document in
>http://www.gnu.org/software/libc/manual/html_node/Why-Variadic.html#Why%
>20Variadic
I think the statments made in the above link regarding variadic functions
are plainly wrong. It may work for sometimes for some targets but definately
not for all targets. The reason is the compiler may and can pass arguments
differently depending on the prototype and especially for varadic functions.
Both the declaration and definition should agree mixing them isn't going to
work.
Graham
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16000
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Bug target/16000] for h8 targets variadic functions are not working properly
2004-06-15 14:12 ` manishas at kpitcummins dot com
@ 2004-06-15 14:27 ` Graham Stott
0 siblings, 0 replies; 8+ messages in thread
From: Graham Stott @ 2004-06-15 14:27 UTC (permalink / raw)
To: gcc-bugzilla, gcc-bugs
>Consider the attached test case for H8 target in which variadic function is
>declared to take variable number of arguments but in the definition fixed
>number of arguments are used. This is allowed in gcc as per document in
>http://www.gnu.org/software/libc/manual/html_node/Why-Variadic.html#Why%
>20Variadic
I think the statments made in the above link regarding variadic functions
are plainly wrong. It may work for sometimes for some targets but definately
not for all targets. The reason is the compiler may and can pass arguments
differently depending on the prototype and especially for varadic functions.
Both the declaration and definition should agree mixing them isn't going to
work.
Graham
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug target/16000] for h8 targets variadic functions are not working properly
2004-06-15 14:05 [Bug c/16000] New: for h8 targets variadic functions are not working properly manishas at kpitcummins dot com
` (2 preceding siblings ...)
2004-06-15 14:27 ` graham dot stott at btinternet dot com
@ 2004-06-15 15:26 ` bonzini at gnu dot org
2004-06-15 15:27 ` bonzini at gnu dot org
2004-08-16 7:17 ` [Bug other/16000] " kazu at cs dot umass dot edu
5 siblings, 0 replies; 8+ messages in thread
From: bonzini at gnu dot org @ 2004-06-15 15:26 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bonzini at gnu dot org 2004-06-15 15:26 -------
Graham is right. This is a problem in user code, unless this fails as well...
int variadic_test (int, unsigned long, unsigned long);
int main (void)
{
int result_varfunc;
int result_local;
result_local = 1 + 2 + 3;
result_varfunc = variadic_test(1, 2, 3);
if (result_local != result_varfunc) {
//printf("error");
return 0;
} else
return 1;
}
Paolo
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16000
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug target/16000] for h8 targets variadic functions are not working properly
2004-06-15 14:05 [Bug c/16000] New: for h8 targets variadic functions are not working properly manishas at kpitcummins dot com
` (3 preceding siblings ...)
2004-06-15 15:26 ` bonzini at gnu dot org
@ 2004-06-15 15:27 ` bonzini at gnu dot org
2004-08-16 7:17 ` [Bug other/16000] " kazu at cs dot umass dot edu
5 siblings, 0 replies; 8+ messages in thread
From: bonzini at gnu dot org @ 2004-06-15 15:27 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bonzini at gnu dot org 2004-06-15 15:27 -------
This means that the error is in the documentation.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16000
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug other/16000] for h8 targets variadic functions are not working properly
2004-06-15 14:05 [Bug c/16000] New: for h8 targets variadic functions are not working properly manishas at kpitcummins dot com
` (4 preceding siblings ...)
2004-06-15 15:27 ` bonzini at gnu dot org
@ 2004-08-16 7:17 ` kazu at cs dot umass dot edu
5 siblings, 0 replies; 8+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-08-16 7:17 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From kazu at cs dot umass dot edu 2004-08-16 07:16 -------
The documentation in question is not GCC's.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Component|target |other
Keywords|wrong-code |documentation
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16000
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2004-08-16 7:17 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-15 14:05 [Bug c/16000] New: for h8 targets variadic functions are not working properly manishas at kpitcummins dot com
2004-06-15 14:08 ` [Bug target/16000] " pinskia at gcc dot gnu dot org
2004-06-15 14:12 ` manishas at kpitcummins dot com
2004-06-15 14:27 ` Graham Stott
2004-06-15 14:27 ` graham dot stott at btinternet dot com
2004-06-15 15:26 ` bonzini at gnu dot org
2004-06-15 15:27 ` bonzini at gnu dot org
2004-08-16 7:17 ` [Bug other/16000] " kazu at cs dot umass dot edu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).