public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug debug/102442] New: Incorrect debug info for C89-style function parameter
@ 2021-09-22 6:37 liyd2021 at gmail dot com
2021-09-24 13:37 ` [Bug debug/102442] " josephcsible at gmail dot com
2021-09-25 1:34 ` egallager at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: liyd2021 at gmail dot com @ 2021-09-22 6:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102442
Bug ID: 102442
Summary: Incorrect debug info for C89-style function parameter
Product: gcc
Version: 11.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: debug
Assignee: unassigned at gcc dot gnu.org
Reporter: liyd2021 at gmail dot com
Target Milestone: ---
Affected versions: gcc 11.1.0 with gdb (Ubuntu 20.04.2)
(terminal) $ cat simple.c && gcc -g -Og simple.c
#include <assert.h>
// float fx(float x)
float fx(x) float x;
{
return x + 1.0;
}
float inita() { return 3.0; }
int main()
{
float a = inita();
assert(fx(a) == 4.0);
}
--------------------
(terminal) $ cat run.gdb
b fx
r
(terminal) $ gdb -x run.gdb a.out
Breakpoint 1, fx (x=0) at simple.c:5 <- **BUG** <- x should be 3.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug debug/102442] Incorrect debug info for C89-style function parameter
2021-09-22 6:37 [Bug debug/102442] New: Incorrect debug info for C89-style function parameter liyd2021 at gmail dot com
@ 2021-09-24 13:37 ` josephcsible at gmail dot com
2021-09-25 1:34 ` egallager at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: josephcsible at gmail dot com @ 2021-09-24 13:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102442
Joseph C. Sible <josephcsible at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |josephcsible at gmail dot com
--- Comment #1 from Joseph C. Sible <josephcsible at gmail dot com> ---
I wonder if this is related to fx actually being a float(double) and not a
float(float) as it appears to be.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug debug/102442] Incorrect debug info for C89-style function parameter
2021-09-22 6:37 [Bug debug/102442] New: Incorrect debug info for C89-style function parameter liyd2021 at gmail dot com
2021-09-24 13:37 ` [Bug debug/102442] " josephcsible at gmail dot com
@ 2021-09-25 1:34 ` egallager at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: egallager at gcc dot gnu.org @ 2021-09-25 1:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102442
Eric Gallager <egallager at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |egallager at gcc dot gnu.org
--- Comment #2 from Eric Gallager <egallager at gcc dot gnu.org> ---
That's not a C89 function parameter, that's a K&R-style parameter, which was
outdated even in C89. GCC warns about it:
$ /usr/local/bin/gcc -c -Wall -Wextra -Wstrict-prototypes -Wimplicit
-Wold-style-definition -Wold-style-declaration -Wmissing-prototypes
-Wmissing-declarations -pedantic -Wconversion -Wdouble-promotion
-Wtraditional-conversion 102442.c
102442.c:4:7: warning: function declaration isn't a prototype
[-Wstrict-prototypes]
4 | float fx(x) float x;
| ^~
102442.c: In function 'fx':
102442.c:4:7: warning: old-style function definition [-Wold-style-definition]
102442.c:6:14: warning: implicit conversion from 'float' to 'double' to match
other operand of binary expression [-Wdouble-promotion]
6 | return x + 1.0;
| ^
102442.c:6:14: warning: conversion from 'double' to 'float' may change value
[-Wfloat-conversion]
6 | return x + 1.0;
| ~~^~~~~
102442.c: At top level:
102442.c:9:7: warning: function declaration isn't a prototype
[-Wstrict-prototypes]
9 | float inita() { return 3.0; }
| ^~~~~
102442.c: In function 'inita':
102442.c:9:7: warning: old-style function definition [-Wold-style-definition]
102442.c: At top level:
102442.c:11:5: warning: function declaration isn't a prototype
[-Wstrict-prototypes]
11 | int main()
| ^~~~
102442.c: In function 'main':
102442.c:11:5: warning: old-style function definition [-Wold-style-definition]
In file included from 102442.c:1:
102442.c:14:15: warning: implicit conversion from 'float' to 'double' when
passing argument to function [-Wdouble-promotion]
14 | assert(fx(a) == 4.0);
| ^
102442.c:14:18: warning: implicit conversion from 'float' to 'double' to match
other operand of binary expression [-Wdouble-promotion]
14 | assert(fx(a) == 4.0);
| ^~
102442.c:14:5: warning: passing argument 1 of '__builtin_expect' with different
width due to prototype [-Wtraditional-conversion]
14 | assert(fx(a) == 4.0);
| ^~~~~~
102442.c:14:5: warning: passing argument 2 of '__builtin_expect' with different
width due to prototype [-Wtraditional-conversion]
$
As does clang:
$ clang -c -Weverything 102442.c
warning: include location '/usr/local/include' is unsafe for cross-compilation
[-Wpoison-system-directories]
102442.c:6:14: warning: implicit conversion loses floating-point precision:
'double' to 'float' [-Wimplicit-float-conversion]
return x + 1.0;
~~~~~~ ~~^~~~~
102442.c:6:12: warning: implicit conversion increases floating-point precision:
'float' to 'double' [-Wdouble-promotion]
return x + 1.0;
^ ~
102442.c:4:7: warning: no previous prototype for function 'fx'
[-Wmissing-prototypes]
float fx(x) float x;
^
102442.c:4:1: note: declare 'static' if the function is not intended to be used
outside of this translation unit
float fx(x) float x;
^
static
102442.c:4:9: warning: this old-style function definition is not preceded by a
prototype [-Wstrict-prototypes]
float fx(x) float x;
^
102442.c:9:7: warning: no previous prototype for function 'inita'
[-Wmissing-prototypes]
float inita() { return 3.0; }
^
102442.c:9:1: note: declare 'static' if the function is not intended to be used
outside of this translation unit
float inita() { return 3.0; }
^
static
102442.c:9:12: warning: this old-style function definition is not preceded by a
prototype [-Wstrict-prototypes]
float inita() { return 3.0; }
^
102442.c:14:12: warning: implicit conversion increases floating-point
precision: 'float' to 'double' [-Wdouble-promotion]
assert(fx(a) == 4.0);
^~~~~ ~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/assert.h:93:25:
note: expanded from macro 'assert'
(__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __FILE__, __LINE__, #e)
: (void)0)
^
102442.c:14:15: warning: implicit conversion increases floating-point
precision: 'float' to 'double' [-Wdouble-promotion]
assert(fx(a) == 4.0);
~~ ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/assert.h:93:25:
note: expanded from macro 'assert'
(__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __FILE__, __LINE__, #e)
: (void)0)
^
9 warnings generated.
$
I think the warnings make it pretty clear that code like this needs to be
updated.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-09-25 1:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-22 6:37 [Bug debug/102442] New: Incorrect debug info for C89-style function parameter liyd2021 at gmail dot com
2021-09-24 13:37 ` [Bug debug/102442] " josephcsible at gmail dot com
2021-09-25 1:34 ` egallager at gcc dot gnu.org
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).