This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RE: [PATCH, RFC, C] Add -fno-float to forbid floating point data types
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Thomas Preud'homme <thomas dot preudhomme at arm dot com>
- Cc: <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 13 Nov 2014 21:01:42 +0000
- Subject: RE: [PATCH, RFC, C] Add -fno-float to forbid floating point data types
- Authentication-results: sourceware.org; auth=none
- References: <001201cffe95$c768cc70$563a6550$ at arm dot com> <alpine dot DEB dot 2 dot 10 dot 1411122148290 dot 31875 at digraph dot polyomino dot org dot uk> <001501cfff1f$59e14bc0$0da3e340$ at arm dot com>
On Thu, 13 Nov 2014, Thomas Preud'homme wrote:
> > From: Joseph Myers [mailto:joseph@codesourcery.com]
> > Sent: Wednesday, November 12, 2014 10:11 PM
> > >
> > > This patch modifies the C parser to give an error if:
> > > - any variable or function parameter is declared with a float type or
> > > a type containing a float (prototype are ignored)
> >
> > But if you ignore prototypes at the time of declaration, don't you need to
> > diagnose if a function with a floating-point parameter or return type gets
> > called? I don't see anything to do that. (This includes the
> > __builtin_sqrt case from the previous discussion.)
>
> It would work by transitivity. To call a function with a float you'd have to
> either declare a float variable or pass it a float literal.
Or pass in an integer value, which gets implicitly converted to floating
point because of the prototype. Detecting that case requires checking
calls.
> Thanks a lot for the review. Except on the patch itself, what do you think of
> the general approach? Do you think doing this in the frontend is the right
> approach?
If you want to define a language subset, where it is predictable what is
accepted, then doing it in the front end is right.
If you want to accept as much code as possible and only give errors if
floating-point code would actually be generated - for example, if you want
to be able to #include <stdlib.h> with glibc (where it defines an inline
version of atof) - then you need to look at GIMPLE after optimization,
taking into account which functions will actually be output so as to
ignore unused inline functions.
--
Joseph S. Myers
joseph@codesourcery.com