[llvm-bugs] [Bug 51034] New: Unable to call K&R declared function with float arguments in debugger after 6c9559b67b91966bfeff9e17808a3e84a92e64a0
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Jul 8 17:23:03 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=51034
Bug ID: 51034
Summary: Unable to call K&R declared function with float
arguments in debugger after
6c9559b67b91966bfeff9e17808a3e84a92e64a0
Product: new-bugs
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: douglas_yung at playstation.sony.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org
Internally we run the GDB test suite and a couple of tests in there started
failing recently which I bisected to commit
6c9559b67b91966bfeff9e17808a3e84a92e64a0. The root of the problem seems to be
that after 6c9559b67, when trying to invoke a function from a debugging session
in gdb, if the function was declared in a K&R style, it does not seem to pass
float arguments to the function being called.
For example, consider the following code:
/* test.c */
#include <stdio.h>
#define DELTA (0.001)
float float_val1 = 3.14159;
float float_val2 = -2.3765;
int t_float_values (float_arg1, float_arg2)
float float_arg1, float_arg2;
{
printf("float_arg1 = %f, float_arg2 = %f\n", float_arg1, float_arg2);
return ((float_arg1 - float_val1) < DELTA
&& (float_arg1 - float_val1) > -DELTA
&& (float_arg2 - float_val2) < DELTA
&& (float_arg2 - float_val2) > -DELTA);
}
int foo1() {
return t_float_values(3.14159,-2.3765);
}
int main(int argc, char *argv[]) {
return foo1();
}
/* test.c */
If you compile that code with debug information and then debug the binary using
gdb with the following commands, you can see the problem:
1. b main
2. r
3. p foo1()
4. p t_float_values(3.14159,-2.3765)
The return value of the commands in 3 and 4 should be the same. When test.c is
compiled with a compiler prior to 6c9559b67, that is indeed the case. But if
compiled with a compiler that includes 6c9559b67, the return value of 4 is 0
instead of 1 like it should be. Additionally, from the printf() statement, you
can see that the values of float_arg1 and float_arg2 are not being passed into
the function when it is invoked in 4.
GDB session using binary built by a "good" compiler:
Reading symbols from test.good.elf...
(gdb) b main
Breakpoint 1 at 0x401266: file test.c, line 23.
(gdb) r
Starting program: /home/dyung/sandbox/gdb/test.good.elf
Breakpoint 1, main (argc=1, argv=0x7fffffffe458) at test.c:23
23 return foo1();
(gdb) p foo1()
float_arg1 = 3.141590, float_arg2 = -2.376500
$1 = 1
(gdb) p t_float_values(3.14159,-2.3765)
float_arg1 = 3.141590, float_arg2 = -2.376500
$2 = 1
GDB session using binary built by a "bad" compiler:
Reading symbols from test.bad.elf...
(gdb) b main
Breakpoint 1 at 0x401266: file test.c, line 23.
(gdb) r
Starting program: /home/dyung/sandbox/gdb/test.bad.elf
Breakpoint 1, main (argc=1, argv=0x7fffffffe458) at test.c:23
23 return foo1();
(gdb) p foo1()
float_arg1 = 3.141590, float_arg2 = -2.376500
$1 = 1
(gdb) p t_float_values(3.14159,-2.3765)
float_arg1 = 0.000000, float_arg2 = 0.000000
$2 = 0
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210709/f78c5975/attachment.html>
More information about the llvm-bugs
mailing list