public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: "Willgerodt, Felix" <felix.willgerodt@intel.com>,
	Bruno Larsen <blarsen@redhat.com>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: RE: [PATCH 1/1] gdb, testsuite: Adapt gdb.base/callfuncs.exp for new clang warnings.
Date: Tue, 19 Jul 2022 11:15:46 +0100	[thread overview]
Message-ID: <87ilntqugd.fsf@redhat.com> (raw)
In-Reply-To: <MN2PR11MB45663D90CA2C2E7B277415588E8F9@MN2PR11MB4566.namprd11.prod.outlook.com>

"Willgerodt, Felix via Gdb-patches" <gdb-patches@sourceware.org> writes:

>> -----Original Message-----
>> From: Andrew Burgess <aburgess@redhat.com>
>> Sent: Dienstag, 19. Juli 2022 11:14
>> To: Willgerodt, Felix <felix.willgerodt@intel.com>; Bruno Larsen
>> <blarsen@redhat.com>; gdb-patches@sourceware.org
>> Subject: RE: [PATCH 1/1] gdb, testsuite: Adapt gdb.base/callfuncs.exp for
>> new clang warnings.
>> 
>> "Willgerodt, Felix via Gdb-patches" <gdb-patches@sourceware.org> writes:
>> 
>> >> -----Original Message-----
>> >> From: Andrew Burgess <aburgess@redhat.com>
>> >> Sent: Montag, 18. Juli 2022 15:37
>> >> To: Willgerodt, Felix <felix.willgerodt@intel.com>; Bruno Larsen
>> >> <blarsen@redhat.com>; gdb-patches@sourceware.org
>> >> Subject: RE: [PATCH 1/1] gdb, testsuite: Adapt gdb.base/callfuncs.exp for
>> >> new clang warnings.
>> >>
>> >> "Willgerodt, Felix via Gdb-patches" <gdb-patches@sourceware.org>
>> writes:
>> >>
>> >> >> -----Original Message-----
>> >> >> From: Bruno Larsen <blarsen@redhat.com>
>> >> >> Sent: Mittwoch, 8. Juni 2022 14:59
>> >> >> To: Willgerodt, Felix <felix.willgerodt@intel.com>; gdb-
>> >> >> patches@sourceware.org
>> >> >> Subject: Re: [PATCH 1/1] gdb, testsuite: Adapt gdb.base/callfuncs.exp
>> for
>> >> >> new clang warnings.
>> >> >>
>> >> >>
>> >> >> On 6/8/22 04:17, Felix Willgerodt via Gdb-patches wrote:
>> >> >> > This patch fixes two issues with callfuncs.exp, which are both related
>> >> >> > to new Clang warnings:
>> >> >>
>> >> >> Hi Felix!
>> >> >>
>> >> >> Thanks for this!
>> >> >>
>> >> >> >
>> >> >> > 1) Clang 15.0.0 added a new warning for deprecated non-prototype
>> >> >> functions:
>> >> >> > https://reviews.llvm.org/D122895
>> >> >> > Callfuncs.exp is impacted and won't run due to new warnings:
>> >> >> >
>> >> >> > callfuncs.c:339:5: warning: a function declaration without a prototype
>> is
>> >> >> > deprecated in all versions of C and is not supported in C2x
>> >> >> > [-Wdeprecated-non-prototype]
>> >> >> > int t_float_values (float_arg1, float_arg2)
>> >> >> >
>> >> >> > This patch disables those warnings with -Wno-deprecated-non-
>> >> prototype.
>> >> >> > Removing the test for deprecated syntax would also be an option.
>> But I
>> >> will
>> >> >> > leave that for others to decide.
>> >> >>
>> >> >> I like your solution with -Wno-deprecated-non-prototype.
>> >> >>
>> >> >> I think it is important (at least for now) to keep this test, since we have
>> to
>> >> >> support very old setups.
>> >> >>
>> >> >> >
>> >> >> > 2) The other new warnings are about comparing a define with floats
>> and
>> >> >> doubles:
>> >> >> >
>> >> >> > callfuncs.c:518:1: warning: floating-point comparison is always true;
>> >> >> constant
>> >> >> > cannot be represented exactly in type 'float' [-Wliteral-range]
>> >> >> > DEF_FUNC_VALUES_3(fc, float, crealf, cimagf)
>> >> >> >
>> >> >> > This can be fixed by making the define a float.
>> >> >>
>> >> >> Genuine question, would this not cause a problem for the times where
>> >> the
>> >> >> parameters are doubles and DELTA is a float? If it isn't a problem, I'm
>> fine
>> >> >> with this.
>> >> >>
>> >> >
>> >> > I was wondering about that as well, but it still passes with GCC, clang and
>> >> Intel
>> >> > compilers and there are no compiler warnings about it.
>> >> > I couldn't really figure it out if it would actually a problem somewhere. I
>> >> could only
>> >> > test on linux x86 though. My best guess was, as it is the "smaller
>> precision"
>> >> the
>> >> > compiler will do the right thing.
>> >>
>> >> Indeed, my understanding of type promotion is that the compiler will
>> >> promote the float argument to double or long double as needed.
>> >>
>> >> But then, prior to this patch, when DELTA was just (0.001), and would be
>> >> considered a double, I would have expected, in any comparison between
>> a
>> >> float and DELTA, for the float to be converted to double, so I don't
>> >> really understand that part of the original patch.
>> >>
>> >> Thanks,
>> >> Andrew
>> >
>> > Thanks for your input.
>> > What I didn't quite realize when writing the patch, is that float literals
>> without
>> > suffix are of type double. I double checked the ISO C11 draft and it is
>> mentioned
>> > there as well.
>> >
>> > So to me this is likely a compiler bug. Or did I miss anything?
>> 
>> I did wonder the same, but I don't claim to be an expert on language
>> details.  I don't have immediate access to clang 15, but it might be
>> interesting to try and reduce the test program down to just that
>> error/warning case, and see if the code makes sense.
>> 
>> Thanks,
>> Andrew
>
> I did this experiment:
>
>
> $ cat float.c
> #define DELTA 0.001
>
> int main() {
> float a = 0.3;
>
> if (a == DELTA)
>   return 1;
> else
>   return 0;
> }
> $ clang float.c 
> float.c:7:7: warning: floating-point comparison is always false; constant
> cannot be represented exactly in type 'float' [-Wliteral-range]
> if (a == DELTA)
>     ~ ^  ~~~~~
> 1 warning generated.

Sure, but in gdb.base/callfuncs.c we seem to take great care to ensure
we always check delta like:

  if ( (a - b) < DELTA )

Is there a macro that actually expands to use DELTA with '==' ?

Thanks,
Andrew


  reply	other threads:[~2022-07-19 10:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-08  7:17 Felix Willgerodt
2022-06-08 12:58 ` Bruno Larsen
2022-06-08 15:11   ` Willgerodt, Felix
2022-07-18 13:37     ` Andrew Burgess
2022-07-19  9:06       ` Willgerodt, Felix
2022-07-19  9:14         ` Andrew Burgess
2022-07-19  9:20           ` Willgerodt, Felix
2022-07-19 10:15             ` Andrew Burgess [this message]
2022-07-25 11:17               ` Willgerodt, Felix
2022-07-15 18:40 ` Tom Tromey
2022-07-18  9:41   ` Willgerodt, Felix
2022-07-18 13:28     ` Andrew Burgess
2022-07-18 13:42       ` Willgerodt, Felix

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ilntqugd.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=blarsen@redhat.com \
    --cc=felix.willgerodt@intel.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).