mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Jens Gustedt <jens.gustedt@inria.fr>
To: musl@lists.openwall.com
Subject: Re: [PATCH 1/4] the CMPLX macros must be usable in initializations of static variables
Date: Tue, 02 Dec 2014 23:00:12 +0100	[thread overview]
Message-ID: <1417557612.4936.1138.camel@eris.loria.fr> (raw)
In-Reply-To: <20141202194210.GF29621@brightrain.aerifal.cx>

[-- Attachment #1: Type: text/plain, Size: 6194 bytes --]

Am Dienstag, den 02.12.2014, 14:42 -0500 schrieb Rich Felker:
> On Tue, Dec 02, 2014 at 08:10:32PM +0100, Jens Gustedt wrote:
> > > Does clang not support the GCC builtin?
> > 
> > no, and I don't have the impression they will. They invented their own
> > internals for this, as you can see here.
> 
> Yes, but their form is a bug that needs to be removed, so they'll have
> to add something in its place, and __builtin_complex is the natural
> choice. For what it's worth, glibc only supports __builtin_complex and
> just does not define these macros at all if it's not supported.

you mean it is a bug because the two-value-initializer is a constraint
violation? It only is a bug that has to be diagnosed if user code is
using it. Internals as long they are not visible to the user isn't
covered by this, I think. And this is exactly the reason why the
macros have been introduced in C11, to hide such cruft from the user's
eye :)

> > > My preference would be if we could just define CMPLX either in terms
> > > of __builtin_complex,
> > 
> > not possible, I think
> 
> Well, it's what glibc does. That's not to say it's a good choice, but
> it suggests there could be pressure to get other compilers to support
> it.

and that's then one of the points where they aren't C11 conforming
when compiled with other compilers

> > > and only exposing it in C11 mode.
> > 
> > this is already the case. (Or is it C1x that bothers you?)
> 
> I did find the 201000L comparison a bit odd (is that the "C1x" thing?)

yes

> but my comment here wasn't in reference to your proposal being
> different from the ideal I'd like to have, just a statement of the
> latter.

ok

> > > _Imaginary_I
> > > is not supported yet at all and would require further changes to this
> > > header to add anyway (this header is responsible for defining it), so
> > > conditioning on its definition is not meaningful.
> > 
> > I am not sure of that. It could also come directly from the compiler
> > just as it defines some __SOMETHING__ macros before any include
> 
> I don't think so. Consider:
> 
> #undef _Imaginary_I
> #include <complex.h>
> 
> Perhaps this is non-conforming for technical reasons,

it is non-conforming

> but the standard
> is fairly direct in saying that complex.h defines the _Imaginary_I
> macro rather than just having it predefined.

but it also says

 » Implementations that define the macro __STDC_NO_COMPLEX__ need not provide
 » this header nor support any of its facilities.

so any of the facilities *may* be provided anyhow. (and since
_Imaginary_I is reserved it is allowed to do that in any case.)

But if you want to avoid that branch, I understand. _Imaginary_I would
be *the* way to solve all of this easily, sigh.

> > > And pre-4.7 versions
> > > of GCC don't support C11 anyway (and even 4.7 and 4.8 are highly
> > > incomplete) so I don't think much is lost if a C11 feature fails to
> > > work on older compilers.
> > 
> > as said, there is no intention to support it for older compilers. So I
> > read it that you want me to pull the definition of the __CMPLX
> > versions into the C1x conditional?
> 
> I'm not sure I follow what you're saying here. The text you quoted was
> in regards to my hope of just having a single definition, not a
> specific request for any particular changes to your proposed patch.
> 
> > > The big question is how this fares for clang
> > > compatibility though. I expect pcc and cparser/firm will provide a
> > > compatible __builtin_complex (if they don't already) as they improve
> > > C11 support.
> > > 
> > > > diff --git a/src/internal/libm.h b/src/internal/libm.h
> > > > index ebcd784..f916e2e 100644
> > > > --- a/src/internal/libm.h
> > > > +++ b/src/internal/libm.h
> > > > @@ -155,4 +155,12 @@ long double __tanl(long double, long double, int);
> > > >  long double __polevll(long double, const long double *, int);
> > > >  long double __p1evll(long double, const long double *, int);
> > > >  
> > > > +/* complex */
> > > > +
> > > > +#ifndef CMPLX
> > > > +#define CMPLX(x, y) __CMPLX_NC(x, y, double)
> > > > +#define CMPLXF(x, y) __CMPLX_NC(x, y, float)
> > > > +#define CMPLXL(x, y) __CMPLX_NC(x, y, long double)
> > > > +#endif
> > > > +
> > > >  #endif
> > > 
> > > This should probably use the unions unconditionally, after including
> > > complex.h and #undef'ing CMPLX[FL], since musl does not require a C11
> > > compiler to build it. Depending on whether a fallback is provided for
> > > old compilers or not, I think your approach could lead to musl being
> > > miscompiled. It probably doesn't happen since CMPLX is no longer
> > > exposed except in C11 mode, and musl is compiled with -std=c99, but
> > > this looks fragile and could cause breakage to go unnoticed if we
> > > switch to preferring -std=c11 some time later. (There's been talk of
> > > preferring -std=c11 if it works.)
> > 
> > Hm, clearly not my preference. I think we should use the right tool
> > (which is __builtin_complex for gcc or the bogus initializer for
> > clang) as soon as we have it.
> > 
> > This is why I wanted to have the detection of the features as early as
> > possible where it belongs to my opinion, complex.h.
> > 
> > They have more chances to optimize things correctly without
> > temporaries even when compiled without optimization.
> 
> As stated in another thread, my preference is highly towards not
> having multiple versions of the same code, especially when one or more
> are unlikely to get good testing. The "more chance to optimize"
> argument does not apply unless there really are compilers which
> compile the unions poorly (not counting intentional non-optimizing
> modes) and I'm not aware of any.

ok, I'll prepare a new version according to that

Jens

-- 
:: INRIA Nancy Grand Est ::: AlGorille ::: ICube/ICPS :::
:: ::::::::::::::: office Strasbourg : +33 368854536   ::
:: :::::::::::::::::::::: gsm France : +33 651400183   ::
:: ::::::::::::::: gsm international : +49 15737185122 ::
:: http://icube-icps.unistra.fr/index.php/Jens_Gustedt ::



[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

  reply	other threads:[~2014-12-02 22:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-26 13:07 Jens Gustedt
2014-12-02 17:49 ` Rich Felker
2014-12-02 19:10   ` Jens Gustedt
2014-12-02 19:42     ` Rich Felker
2014-12-02 22:00       ` Jens Gustedt [this message]
2014-12-02 22:47         ` Rich Felker
2014-12-03  9:18           ` Jens Gustedt
2014-12-03 14:38             ` Rich Felker
2014-12-03 15:12               ` Jens Gustedt
  -- strict thread matches above, loose matches on Subject: below --
2014-11-25 14:49 Jens Gustedt
2014-11-25 15:25 ` Szabolcs Nagy
2014-11-25 19:21   ` Szabolcs Nagy
2014-11-25 21:23     ` Jens Gustedt
2014-11-25 23:19       ` Szabolcs Nagy
2014-11-26  7:45         ` Jens Gustedt
2014-11-25 20:08   ` Jens Gustedt

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=1417557612.4936.1138.camel@eris.loria.fr \
    --to=jens.gustedt@inria.fr \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).