public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/38007]  New: g++ instantiate same operator twice due to bitfield in -O0 mode, causing symbol already defined assembler error
@ 2008-11-03 19:24 jengliang at gmail dot com
  2008-11-03 20:08 ` [Bug c++/38007] [4.2/4.3/4.4 Regression] " pinskia at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: jengliang at gmail dot com @ 2008-11-03 19:24 UTC (permalink / raw)
  To: gcc-bugs

Following code produces symbol already defined assembler error when compiled
with g++ 4.2.4 with -O0 flag.  It can compile without problem with g++ 4.1.1.

=== foo.hpp ===
class foo {
    public:
        template <typename T> operator T ();
};

template <typename T>
    inline foo::operator T () {
        return (T)0;
    }

=== foo.cpp ===
#include "foo.hpp"

struct bar {
    unsigned int _bar : 24;
};

int main() {
    foo a;
    unsigned int b = a;
    bar c;
    c._bar = a;
    return 1;
}

====
compile with g++ -O0 foo.cpp

Regards,
Jeng-Liang


-- 
           Summary: g++ instantiate same operator twice due to bitfield in -
                    O0 mode, causing symbol already defined assembler error
           Product: gcc
           Version: 4.2.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jengliang at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38007


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/38007] [4.2/4.3/4.4 Regression] g++ instantiate same operator twice due to bitfield in -O0 mode, causing symbol already defined assembler error
  2008-11-03 19:24 [Bug c++/38007] New: g++ instantiate same operator twice due to bitfield in -O0 mode, causing symbol already defined assembler error jengliang at gmail dot com
@ 2008-11-03 20:08 ` pinskia at gcc dot gnu dot org
  2008-11-04 10:41 ` rguenth at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-11-03 20:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2008-11-03 20:07 -------
Confirmed, a regression from GCC 4.1.1.
Here is a self contained example :):
class foo {
    public:
        template <typename T> operator T ();
};

template <typename T>
    inline foo::operator T () {
        return (T)0;
    }

struct bar {
    unsigned int _bar : 24;
};

int main() {
    foo a;
    unsigned int b = a;
    bar c;
    c._bar = a;
    return 1;
}


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu dot
                   |                            |org
           Severity|normal                      |critical
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |assemble-failure
      Known to fail|                            |4.3.0 4.4.0
      Known to work|                            |4.1.1
   Last reconfirmed|0000-00-00 00:00:00         |2008-11-03 20:07:32
               date|                            |
            Summary|g++ instantiate same        |[4.2/4.3/4.4 Regression] g++
                   |operator twice due to       |instantiate same operator
                   |bitfield in -O0 mode,       |twice due to bitfield in -O0
                   |causing symbol already      |mode, causing symbol already
                   |defined assembler error     |defined assembler error
   Target Milestone|---                         |4.2.5


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38007


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/38007] [4.2/4.3/4.4 Regression] g++ instantiate same operator twice due to bitfield in -O0 mode, causing symbol already defined assembler error
  2008-11-03 19:24 [Bug c++/38007] New: g++ instantiate same operator twice due to bitfield in -O0 mode, causing symbol already defined assembler error jengliang at gmail dot com
  2008-11-03 20:08 ` [Bug c++/38007] [4.2/4.3/4.4 Regression] " pinskia at gcc dot gnu dot org
@ 2008-11-04 10:41 ` rguenth at gcc dot gnu dot org
  2008-11-06 15:16 ` jakub at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-11-04 10:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2008-11-04 10:39 -------
The following also fails the same way with optimization:

class foo {
public:
    template <typename T> __attribute__((noinline))
    operator T () { return (T)0; }
};

struct bar {
    unsigned int _bar : 24;
};

int main()
{
    foo a;
    unsigned int b = a;
    bar c;
    c._bar = a;
    return 0;
}


we instantiate the operator for unsigned int and unsigned int : 24

what we probably should do is treat

  c._bar = a;

as

  c._bar = (unsigned int : 24)(unsigned int)a;

instead.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P1


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38007


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/38007] [4.2/4.3/4.4 Regression] g++ instantiate same operator twice due to bitfield in -O0 mode, causing symbol already defined assembler error
  2008-11-03 19:24 [Bug c++/38007] New: g++ instantiate same operator twice due to bitfield in -O0 mode, causing symbol already defined assembler error jengliang at gmail dot com
  2008-11-03 20:08 ` [Bug c++/38007] [4.2/4.3/4.4 Regression] " pinskia at gcc dot gnu dot org
  2008-11-04 10:41 ` rguenth at gcc dot gnu dot org
@ 2008-11-06 15:16 ` jakub at gcc dot gnu dot org
  2008-11-07 22:25 ` jason at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu dot org @ 2008-11-06 15:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jakub at gcc dot gnu dot org  2008-11-06 15:15 -------
And for:
struct A
{
  template <typename T> __attribute__((noinline)) operator T ()
  {
    return (T) 0;
  }
};

struct B
{
  unsigned int b : 8;
};

int
main ()
{
  A u;
  unsigned int v = u;
  B w;
  w.b = u;
}

we instantiate both
A::operator unsigned int<unsigned int>()
A::operator unsigned char<unsigned char>()
Shouldn't it use unsigned int conversion in both cases as well, or is it
allowed (or required) to use the lowered type?  I see 3.4 through 4.4 all use
unsigned char, if RHS' type isn't MAYBE_CLASS_TYPE_P, then I understand it, but
for
class RHS it is an important difference.

I believe the place which needs to be revisited is cp_build_modify_expr, if
is_bitfield_expr_with_lowered_type use the type returned by that in
convert_for_assignment.  But I'm e.g. confused by:

  /* If storing into a structure or union member, it has probably been
     given type `int'.  Compute the type that would go with the actual
     amount of storage the member occupies.  */

  if (TREE_CODE (lhs) == COMPONENT_REF
      && (TREE_CODE (lhstype) == INTEGER_TYPE
          || TREE_CODE (lhstype) == REAL_TYPE
          || TREE_CODE (lhstype) == ENUMERAL_TYPE))
    {
      lhstype = TREE_TYPE (get_unwidened (lhs, 0));
...
    }

That seems like a remnant from the past, as get_unwidened for COMPONENT_REF
does
nothing but return the passed object.  See
http://gcc.gnu.org/ml/gcc-patches/2008-03/msg01621.html


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mmitchel at gcc dot gnu dot
                   |                            |org, dodji at gcc dot gnu
                   |                            |dot org, jason at gcc dot
                   |                            |gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38007


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/38007] [4.2/4.3/4.4 Regression] g++ instantiate same operator twice due to bitfield in -O0 mode, causing symbol already defined assembler error
  2008-11-03 19:24 [Bug c++/38007] New: g++ instantiate same operator twice due to bitfield in -O0 mode, causing symbol already defined assembler error jengliang at gmail dot com
                   ` (2 preceding siblings ...)
  2008-11-06 15:16 ` jakub at gcc dot gnu dot org
@ 2008-11-07 22:25 ` jason at gcc dot gnu dot org
  2008-11-12 20:53 ` jason at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu dot org @ 2008-11-07 22:25 UTC (permalink / raw)
  To: gcc-bugs



-- 

jason at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jason at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2008-11-03 20:07:32         |2008-11-07 22:24:09
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38007


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/38007] [4.2/4.3/4.4 Regression] g++ instantiate same operator twice due to bitfield in -O0 mode, causing symbol already defined assembler error
  2008-11-03 19:24 [Bug c++/38007] New: g++ instantiate same operator twice due to bitfield in -O0 mode, causing symbol already defined assembler error jengliang at gmail dot com
                   ` (3 preceding siblings ...)
  2008-11-07 22:25 ` jason at gcc dot gnu dot org
@ 2008-11-12 20:53 ` jason at gcc dot gnu dot org
  2008-11-12 22:11 ` [Bug c++/38007] [4.2/4.3 " jason at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu dot org @ 2008-11-12 20:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from jason at gcc dot gnu dot org  2008-11-12 20:52 -------
Subject: Bug 38007

Author: jason
Date: Wed Nov 12 20:50:45 2008
New Revision: 141800

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141800
Log:
        PR c++/38007                                                            
gcc/cp/                                                                         
        * typeck.c (cp_build_modify_expr): Update bitfield handling.            
gcc/                                                                            
        * c-common.c (c_common_signed_or_unsigned_type): Remove C++             
        special casing.                                                         
gcc/testsuite/                                                                  
        * g++.dg/conversion/bitfield10.C: New test.                             
        * g++.dg/warn/pr35635.C (func1): Accept additional warning.             
        * g++.old-deja/g++.mike/enum1.C: Expect warn about assignment.          
        * g++.dg/expr/bitfield9.C: Pass -Wno-overflow.                          

Added:
    trunk/gcc/testsuite/g++.dg/conversion/bitfield10.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-common.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/expr/bitfield9.C
    trunk/gcc/testsuite/g++.dg/warn/pr35635.C
    trunk/gcc/testsuite/g++.old-deja/g++.mike/enum1.C


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38007


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/38007] [4.2/4.3 Regression] g++ instantiate same operator twice due to bitfield in -O0 mode, causing symbol already defined assembler error
  2008-11-03 19:24 [Bug c++/38007] New: g++ instantiate same operator twice due to bitfield in -O0 mode, causing symbol already defined assembler error jengliang at gmail dot com
                   ` (4 preceding siblings ...)
  2008-11-12 20:53 ` jason at gcc dot gnu dot org
@ 2008-11-12 22:11 ` jason at gcc dot gnu dot org
  2008-11-12 22:16 ` jason at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu dot org @ 2008-11-12 22:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jason at gcc dot gnu dot org  2008-11-12 22:09 -------
Subject: Bug 38007

Author: jason
Date: Wed Nov 12 22:08:01 2008
New Revision: 141808

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141808
Log:
        PR c++/38007                                                            
gcc/cp/                                                                         
        * typeck.c (cp_build_modify_expr): Update bitfield handling.            
gcc/                                                                            
        * c-common.c (c_common_signed_or_unsigned_type): Remove C++             
        special casing.                                                         
gcc/testsuite/                                                                  
        * g++.dg/conversion/bitfield10.C: New test.                             
        * g++.dg/warn/pr35635.C (func1): Accept additional warning.             
        * g++.old-deja/g++.mike/enum1.C: Expect warn about assignment.          
        * g++.dg/expr/bitfield9.C: Pass -Wno-overflow.                          

Added:
    branches/gcc-4_3-branch/gcc/testsuite/g++.dg/conversion/bitfield10.C
      - copied unchanged from r141800,
trunk/gcc/testsuite/g++.dg/conversion/bitfield10.C
Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/c-common.c
    branches/gcc-4_3-branch/gcc/cp/ChangeLog
    branches/gcc-4_3-branch/gcc/cp/typeck.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_3-branch/gcc/testsuite/g++.dg/expr/bitfield9.C
    branches/gcc-4_3-branch/gcc/testsuite/g++.old-deja/g++.mike/enum1.C


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38007


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/38007] [4.2/4.3 Regression] g++ instantiate same operator twice due to bitfield in -O0 mode, causing symbol already defined assembler error
  2008-11-03 19:24 [Bug c++/38007] New: g++ instantiate same operator twice due to bitfield in -O0 mode, causing symbol already defined assembler error jengliang at gmail dot com
                   ` (5 preceding siblings ...)
  2008-11-12 22:11 ` [Bug c++/38007] [4.2/4.3 " jason at gcc dot gnu dot org
@ 2008-11-12 22:16 ` jason at gcc dot gnu dot org
  2008-11-12 22:17 ` jason at gcc dot gnu dot org
  2009-04-29 15:20 ` pinskia at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu dot org @ 2008-11-12 22:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jason at gcc dot gnu dot org  2008-11-12 22:14 -------
Subject: Bug 38007

Author: jason
Date: Wed Nov 12 22:13:26 2008
New Revision: 141809

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141809
Log:
        PR c++/38007                                                            
gcc/cp/                                                                         
        * typeck.c (cp_build_modify_expr): Update bitfield handling.            
gcc/                                                                            
        * c-common.c (c_common_signed_or_unsigned_type): Remove C++             
        special casing.                                                         
gcc/testsuite/                                                                  
        * g++.dg/conversion/bitfield10.C: New test.                             
        * g++.dg/warn/pr35635.C (func1): Accept additional warning.             
        * g++.old-deja/g++.mike/enum1.C: Expect warn about assignment.          
        * g++.dg/expr/bitfield9.C: Pass -Wno-overflow.                          

Added:
    branches/gcc-4_2-branch/gcc/testsuite/g++.dg/conversion/bitfield10.C
      - copied unchanged from r141800,
trunk/gcc/testsuite/g++.dg/conversion/bitfield10.C
Modified:
    branches/gcc-4_2-branch/gcc/ChangeLog
    branches/gcc-4_2-branch/gcc/c-common.c
    branches/gcc-4_2-branch/gcc/cp/ChangeLog
    branches/gcc-4_2-branch/gcc/cp/typeck.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_2-branch/gcc/testsuite/g++.dg/expr/bitfield9.C
    branches/gcc-4_2-branch/gcc/testsuite/g++.old-deja/g++.mike/enum1.C


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38007


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/38007] [4.2/4.3 Regression] g++ instantiate same operator twice due to bitfield in -O0 mode, causing symbol already defined assembler error
  2008-11-03 19:24 [Bug c++/38007] New: g++ instantiate same operator twice due to bitfield in -O0 mode, causing symbol already defined assembler error jengliang at gmail dot com
                   ` (6 preceding siblings ...)
  2008-11-12 22:16 ` jason at gcc dot gnu dot org
@ 2008-11-12 22:17 ` jason at gcc dot gnu dot org
  2009-04-29 15:20 ` pinskia at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu dot org @ 2008-11-12 22:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from jason at gcc dot gnu dot org  2008-11-12 22:15 -------
Fixed on all open branches.


-- 

jason at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38007


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/38007] [4.2/4.3 Regression] g++ instantiate same operator twice due to bitfield in -O0 mode, causing symbol already defined assembler error
  2008-11-03 19:24 [Bug c++/38007] New: g++ instantiate same operator twice due to bitfield in -O0 mode, causing symbol already defined assembler error jengliang at gmail dot com
                   ` (7 preceding siblings ...)
  2008-11-12 22:17 ` jason at gcc dot gnu dot org
@ 2009-04-29 15:20 ` pinskia at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-04-29 15:20 UTC (permalink / raw)
  To: gcc-bugs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.2.5                       |4.3.3


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38007


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-04-29 15:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-03 19:24 [Bug c++/38007] New: g++ instantiate same operator twice due to bitfield in -O0 mode, causing symbol already defined assembler error jengliang at gmail dot com
2008-11-03 20:08 ` [Bug c++/38007] [4.2/4.3/4.4 Regression] " pinskia at gcc dot gnu dot org
2008-11-04 10:41 ` rguenth at gcc dot gnu dot org
2008-11-06 15:16 ` jakub at gcc dot gnu dot org
2008-11-07 22:25 ` jason at gcc dot gnu dot org
2008-11-12 20:53 ` jason at gcc dot gnu dot org
2008-11-12 22:11 ` [Bug c++/38007] [4.2/4.3 " jason at gcc dot gnu dot org
2008-11-12 22:16 ` jason at gcc dot gnu dot org
2008-11-12 22:17 ` jason at gcc dot gnu dot org
2009-04-29 15:20 ` pinskia at gcc dot gnu dot 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).