Bug 24902 - COMPLEX_ASSIGN is wrong
Summary: COMPLEX_ASSIGN is wrong
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 4.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-16 18:57 UTC by Andrew Pinski
Modified: 2007-01-05 14:06 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2005-11-16 18:57:33 UTC
The defintion of COMPLEX_ASSIGN is wrong, it should be defined as:

#define COMPLEX_ASSIGN(z_, r_, i_) do {z_ = r_ + i_ * 1.0fi} while (0)


This is in reference to PR 23497.
Comment 1 Andrew Pinski 2005-11-16 18:58:45 UTC
I mean:
#define COMPLEX_ASSIGN(z_, r_, i_) do {z_ = (r_) + (i_) * 1.0fi} while (0)
Comment 2 Gabriel Dos Reis 2005-11-16 19:43:22 UTC
Subject: Re:   New: COMPLEX_ASSIGN is wrong

"pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:

| The defintion of COMPLEX_ASSIGN is wrong,

that is wrong according to Andrew.

| This is in reference to PR 23497.

In the reference to that thread, please do note that

    <lhs> = <rhs>

yields an lvalue for built-in "="; in partiaular

    __imag__ z = r

yields an lvalue.  do whatever you want in the *middle end*, but be
sure you don't transmute that basic semantics constraint.

-- Gaby
Comment 3 Andrew Pinski 2005-11-16 19:50:38 UTC
Subject: Re:  COMPLEX_ASSIGN is wrong

> yields an lvalue.  do whatever you want in the *middle end*, but be
> sure you don't transmute that basic semantics constraint.

Gaby, it also prevents a huge amount of optimizations so what is
the difference from saying it is wrong?

The issue comes down to what does
__imag__ a = b; really means.

And since this is an extension it could mean anything.

Gaby if you want to prevent optimizations from happening, fine with
me.  Just don't prevent the optimization from happening with fixed
up code.

Gaby, remember this is an extension and not a standard thing so take
everything for granted.

-- Pinski

Comment 4 Andrew Pinski 2005-11-16 19:53:38 UTC
I should also note that:
http://gcc.gnu.org/onlinedocs/gcc/Complex.html#Complex

recomends against using the extensions anyways.
Comment 5 Gabriel Dos Reis 2005-11-16 20:24:23 UTC
Subject: Re:  COMPLEX_ASSIGN is wrong

"pinskia at physics dot uc dot edu" <gcc-bugzilla@gcc.gnu.org> writes:

| Subject: Re:  COMPLEX_ASSIGN is wrong
| 
| > yields an lvalue.  do whatever you want in the *middle end*, but be
| > sure you don't transmute that basic semantics constraint.
| 
| Gaby, it also prevents a huge amount of optimizations so what is
| the difference from saying it is wrong?

You're putting optimization before semantics; -that- is wrong.  I'm
not interested in the fastest program if it does not meet my needs.
If __imag__ z yields a modifiable lvalue, then it follows, by ordinary
language rules that it can be used on the left hand side of built-in
"=".  In C, the resulting expresion is an rvalue; in C++ it is an
lvalue.  No amount of bizarre extension should break those simple
rules.  

| The issue comes down to what does
| __imag__ a = b; really means.

No, it comes down to what "__imag__ a" means.

-- Gaby
Comment 6 Gabriel Dos Reis 2005-11-16 20:27:15 UTC
Subject: Re:  COMPLEX_ASSIGN is wrong

"pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:

| I should also note that:
| http://gcc.gnu.org/onlinedocs/gcc/Complex.html#Complex
| 
| recomends against using the extensions anyways.

Exactly which sentence says so?

-- Gaby
Comment 7 Andrew Pinski 2005-11-16 20:29:12 UTC
Subject: Re:  COMPLEX_ASSIGN is wrong

> 
> 
> 
> ------- Comment #6 from gdr at integrable-solutions dot net  2005-11-16 20:27 -------
> Subject: Re:  COMPLEX_ASSIGN is wrong
> 
> "pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:
> 
> | I should also note that:
> | http://gcc.gnu.org/onlinedocs/gcc/Complex.html#Complex
> | 
> | recomends against using the extensions anyways.
> 
> Exactly which sentence says so?

"you should use the ISO C99 function" every time it mentions the
extenstions.

-- Pinski

Comment 8 Gabriel Dos Reis 2005-11-16 20:39:36 UTC
Subject: Re:  COMPLEX_ASSIGN is wrong

"pinskia at physics dot uc dot edu" <gcc-bugzilla@gcc.gnu.org> writes:

[...]

| > Subject: Re:  COMPLEX_ASSIGN is wrong
| > 
| > "pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:
| > 
| > | I should also note that:
| > | http://gcc.gnu.org/onlinedocs/gcc/Complex.html#Complex
| > | 
| > | recomends against using the extensions anyways.
| > 
| > Exactly which sentence says so?
| 
| "you should use the ISO C99 function" every time it mentions the
| extenstions.

 (1) that is not the same as recommending against the extension;

 (2) how do you use ISO C99 functions to implement C99 <complex.h>,
     C++98 <complex> that interoperate with C99 _Complex and other
     libraries that predate C99 functions or on plateforms where C99
     functions don't exist but the libraries need to be implemented anyway?

-- Gaby
Comment 9 kargls 2005-11-16 22:45:49 UTC
(In reply to comment #1)
> I mean:
> #define COMPLEX_ASSIGN(z_, r_, i_) do {z_ = (r_) + (i_) * 1.0fi} while (0)
> 

Does this do the right thing in the presence of special cases?
See PR 24581.
Comment 10 Francois-Xavier Coudert 2007-01-05 14:06:06 UTC
This bug has been open for more that one year without any update, without general agreement on wether we have a bug or a testcase exhibiting incorrect or suboptimal behaviour.

Closing.