public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/46526] New: VTable Problem?
@ 2010-11-17 21:38 nate.knight at numerica dot us
  2010-11-17 22:39 ` [Bug c++/46526] " redi at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: nate.knight at numerica dot us @ 2010-11-17 21:38 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: VTable Problem?
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: nate.knight@numerica.us


Created attachment 22435
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22435
Preprocessed output

Both asserts should pass, but one fails.

Command: g++-mp-4.6 -std=c++0x -v -g3 -save-temps -Wall expose_bug.cpp -o
expose_bug

Command output:

Using built-in specs.
COLLECT_GCC=g++-mp-4.6
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin10/4.6.0/lto-wrapper
Target: x86_64-apple-darwin10
Configured with: ../gcc-4.6-20101113/configure --prefix=/opt/local
--build=x86_64-apple-darwin10 --enable-languages=c,c++,objc,obj-c++
--libdir=/opt/local/lib/gcc46 --includedir=/opt/local/include/gcc46
--infodir=/opt/local/share/info --mandir=/opt/local/share/man
--datarootdir=/opt/local/share/gcc-4.6 --with-local-prefix=/opt/local
--with-system-zlib --disable-nls --program-suffix=-mp-4.6
--with-gxx-include-dir=/opt/local/include/gcc46/c++/ --with-gmp=/opt/local
--with-mpfr=/opt/local --with-mpc=/opt/local --enable-stage1-checking
--disable-multilib --enable-fully-dynamic-string
Thread model: posix
gcc version 4.6.0 20101113 (experimental) (GCC) 
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.6.5' '-std=c++0x' '-v' '-g3'
'-save-temps' '-Wall' '-o' 'expose_bug' '-shared-libgcc' '-mtune=generic'
 /opt/local/libexec/gcc/x86_64-apple-darwin10/4.6.0/cc1plus -E -quiet -v -dD
-D__DYNAMIC__ expose_bug.cpp -fPIC -mmacosx-version-min=10.6.5 -mtune=generic
-std=c++0x -Wall -g3 -fworking-directory -fpch-preprocess -o expose_bug.ii
ignoring nonexistent directory
"/opt/local/lib/gcc46/gcc/x86_64-apple-darwin10/4.6.0/../../../../../x86_64-apple-darwin10/include"
#include "..." search starts here:
#include <...> search starts here:
 /opt/local/include/gcc46/c++/
 /opt/local/include/gcc46/c++//x86_64-apple-darwin10
 /opt/local/include/gcc46/c++//backward
 /opt/local/lib/gcc46/gcc/x86_64-apple-darwin10/4.6.0/include
 /opt/local/include
 /opt/local/lib/gcc46/gcc/x86_64-apple-darwin10/4.6.0/include-fixed
 /usr/include
 /System/Library/Frameworks
 /Library/Frameworks
End of search list.
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.6.5' '-std=c++0x' '-v' '-g3'
'-save-temps' '-Wall' '-o' 'expose_bug' '-shared-libgcc' '-mtune=generic'
 /opt/local/libexec/gcc/x86_64-apple-darwin10/4.6.0/cc1plus -fpreprocessed
expose_bug.ii -fPIC -quiet -dumpbase expose_bug.cpp -mmacosx-version-min=10.6.5
-mtune=generic -auxbase expose_bug -g3 -Wall -std=c++0x -version -o
expose_bug.s
GNU C++ (GCC) version 4.6.0 20101113 (experimental) (x86_64-apple-darwin10)
    compiled by GNU C version 4.6.0 20101113 (experimental), GMP version 5.0.1,
MPFR version 3.0.0-p8, MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
GNU C++ (GCC) version 4.6.0 20101113 (experimental) (x86_64-apple-darwin10)
    compiled by GNU C version 4.6.0 20101113 (experimental), GMP version 5.0.1,
MPFR version 3.0.0-p8, MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 4b970d796b9f2164104727f632078674
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.6.5' '-std=c++0x' '-v' '-g3'
'-save-temps' '-Wall' '-o' 'expose_bug' '-shared-libgcc' '-mtune=generic'
 as -arch x86_64 -force_cpusubtype_ALL -o expose_bug.o expose_bug.s
COMPILER_PATH=/opt/local/libexec/gcc/x86_64-apple-darwin10/4.6.0/:/opt/local/libexec/gcc/x86_64-apple-darwin10/4.6.0/:/opt/local/libexec/gcc/x86_64-apple-darwin10/:/opt/local/lib/gcc46/gcc/x86_64-apple-darwin10/4.6.0/:/opt/local/lib/gcc46/gcc/x86_64-apple-darwin10/
LIBRARY_PATH=/opt/local/lib/gcc46/gcc/x86_64-apple-darwin10/4.6.0/:/opt/local/lib/gcc46/gcc/x86_64-apple-darwin10/4.6.0/../../../:/usr/lib/
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.6.5' '-std=c++0x' '-v' '-g3'
'-save-temps' '-Wall' '-o' 'expose_bug' '-shared-libgcc' '-mtune=generic'
 /opt/local/libexec/gcc/x86_64-apple-darwin10/4.6.0/collect2 -dynamic -arch
x86_64 -macosx_version_min 10.6.5 -weak_reference_mismatches non-weak -o
expose_bug -lcrt1.10.5.o -L/opt/local/lib/gcc46/gcc/x86_64-apple-darwin10/4.6.0
-L/opt/local/lib/gcc46/gcc/x86_64-apple-darwin10/4.6.0/../../.. expose_bug.o
-lstdc++ -lgcc_ext.10.5 -lgcc -no_compact_unwind -lSystem
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.6.5' '-std=c++0x' '-v' '-g3'
'-save-temps' '-Wall' '-o' 'expose_bug' '-shared-libgcc' '-mtune=generic'


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

* [Bug c++/46526] VTable Problem?
  2010-11-17 21:38 [Bug c++/46526] New: VTable Problem? nate.knight at numerica dot us
@ 2010-11-17 22:39 ` redi at gcc dot gnu.org
  2010-11-18 10:09 ` [Bug c++/46526] [4.6 Regression] " rguenth at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2010-11-17 22:39 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2010.11.17 22:22:55
     Ever Confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-11-17 22:22:55 UTC ---
struct Base
{
    virtual int getid() = 0;
};


struct A : public Base
{
    virtual int getid() { return 1; }
};

struct B : public Base
{
    virtual int getid() { throw "here"; }
};

int main()
{
    A a;
    B b;

    Base& ar = a;

    ar.getid();  // throws
}

Only fails with 4.6.0 and -std=c++0x


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

* [Bug c++/46526] [4.6 Regression] VTable Problem?
  2010-11-17 21:38 [Bug c++/46526] New: VTable Problem? nate.knight at numerica dot us
  2010-11-17 22:39 ` [Bug c++/46526] " redi at gcc dot gnu.org
@ 2010-11-18 10:09 ` rguenth at gcc dot gnu.org
  2010-11-18 14:29 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2010-11-18 10:09 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
      Known to work|                            |4.5.1
   Target Milestone|---                         |4.6.0
            Summary|VTable Problem?             |[4.6 Regression] VTable
                   |                            |Problem?

--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2010-11-18 10:06:57 UTC ---
Confirmed.


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

* [Bug c++/46526] [4.6 Regression] VTable Problem?
  2010-11-17 21:38 [Bug c++/46526] New: VTable Problem? nate.knight at numerica dot us
  2010-11-17 22:39 ` [Bug c++/46526] " redi at gcc dot gnu.org
  2010-11-18 10:09 ` [Bug c++/46526] [4.6 Regression] " rguenth at gcc dot gnu.org
@ 2010-11-18 14:29 ` redi at gcc dot gnu.org
  2010-11-19  8:58 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2010-11-18 14:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-11-18 14:23:52 UTC ---
4.6.0 20100925 was OK


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

* [Bug c++/46526] [4.6 Regression] VTable Problem?
  2010-11-17 21:38 [Bug c++/46526] New: VTable Problem? nate.knight at numerica dot us
                   ` (2 preceding siblings ...)
  2010-11-18 14:29 ` redi at gcc dot gnu.org
@ 2010-11-19  8:58 ` jakub at gcc dot gnu.org
  2010-11-19  9:47 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2010-11-19  8:58 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> 2010-11-19 08:56:05 UTC ---
Looks to me like a tree sharing problem in the FE, will debug it.

int
main ()
{
  B b;
  A a;
}

is in *.original as:
    struct B b;
  <<cleanup_point <<< Unknown tree: expr_stmt
  (void) (b = TARGET_EXPR <D.1439, {.D.1372={._vptr.Base=&_ZTV1A + 16}}>)
>>>>>;
    struct A a;
  <<cleanup_point <<< Unknown tree: expr_stmt
  (void) (a = TARGET_EXPR <D.1468, {.D.1363={._vptr.Base=&_ZTV1A + 16}}>)
>>>>>;
while
int
main ()
{
  A a;
  B b;
}
as:
    struct A a;
  <<cleanup_point <<< Unknown tree: expr_stmt
  (void) (a = TARGET_EXPR <D.1439, {.D.1363={._vptr.Base=&_ZTV1B + 16}}>)
>>>>>;
    struct B b;
  <<cleanup_point <<< Unknown tree: expr_stmt
  (void) (b = TARGET_EXPR <D.1468, {.D.1372={._vptr.Base=&_ZTV1B + 16}}>)
>>>>>;
One would expect a being initialized with _ZTV1A + 16 and b with _ZTV1B + 16 in
both cases...


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

* [Bug c++/46526] [4.6 Regression] VTable Problem?
  2010-11-17 21:38 [Bug c++/46526] New: VTable Problem? nate.knight at numerica dot us
                   ` (3 preceding siblings ...)
  2010-11-19  8:58 ` jakub at gcc dot gnu.org
@ 2010-11-19  9:47 ` jakub at gcc dot gnu.org
  2010-11-19  9:59 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2010-11-19  9:47 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> 2010-11-19 09:04:14 UTC ---
Indeed, a tree sharing issue in C++ FE.

    arg 1 <target_expr 0x7ffff18cac60 type <record_type 0x7ffff18d17e0 A>
        side-effects constant
        arg 0 <var_decl 0x7ffff19f1e60 D.1439 type <record_type 0x7ffff18d17e0
A>
            ignored BLK file PQ.C line 19 col 5 size <integer_cst
0x7ffff19cf7a8 64> unit size <integer_cst 0x7ffff19cf7d0 8>
            align 64 context <function_decl 0x7ffff18d0700 main>>
        arg 1 <constructor 0x7ffff18dcaa0 type <record_type 0x7ffff18d17e0 A>
            constant lngt 1 idx <field_decl 0x7ffff18d7390 D.1363>
            val <constructor 0x7ffff18dca20 type <record_type 0x7ffff18d10a8
Base>
                constant lngt 1 idx <field_decl 0x7ffff18d71c8 _vptr.Base>
                val <pointer_plus_expr 0x7ffff7ffc3f0 type <pointer_type
0x7ffff18c8000>
                    readonly constant
                    arg 0 <addr_expr 0x7ffff18e6c00 type <pointer_type
0x7ffff18c8000>
                        readonly constant arg 0 <var_decl 0x7ffff19f13c0
_ZTV1A>>
                    arg 1 <integer_cst 0x7ffff19cf960 constant 16>>>>>>

and

    arg 1 <target_expr 0x7ffff18cae10 type <record_type 0x7ffff18d1f18 B>
        side-effects constant
        arg 0 <var_decl 0x7ffff18f1140 D.1468 type <record_type 0x7ffff18d1f18
B>
            ignored BLK file PQ.C line 20 col 5 size <integer_cst
0x7ffff19cf7a8 64> unit size <integer_cst 0x7ffff19cf7d0 8>
            align 64 context <function_decl 0x7ffff18d0700 main>>
        arg 1 <constructor 0x7ffff18dcc20 type <record_type 0x7ffff18d1f18 B>
            constant lngt 1 idx <field_decl 0x7ffff18d75f0 D.1372>
            val <constructor 0x7ffff18dca20 type <record_type 0x7ffff18d10a8
Base>
                constant lngt 1 idx <field_decl 0x7ffff18d71c8 _vptr.Base>
                val <pointer_plus_expr 0x7ffff7ffc578 type <pointer_type
0x7ffff18c8000>
                    readonly constant
                    arg 0 <addr_expr 0x7ffff18ed870 type <pointer_type
0x7ffff18c8000>
                        readonly constant arg 0 <var_decl 0x7ffff19f15a0
_ZTV1B>>
                    arg 1 <integer_cst 0x7ffff19cf960 constant 16>>>>>>

CONSTRUCTOR 0x7ffff18dca20 is shared in between those two expressions.


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

* [Bug c++/46526] [4.6 Regression] VTable Problem?
  2010-11-17 21:38 [Bug c++/46526] New: VTable Problem? nate.knight at numerica dot us
                   ` (4 preceding siblings ...)
  2010-11-19  9:47 ` jakub at gcc dot gnu.org
@ 2010-11-19  9:59 ` jakub at gcc dot gnu.org
  2010-11-19 10:02 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2010-11-19  9:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> 2010-11-19 09:55:10 UTC ---
Created attachment 22454
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22454
gcc46-pr46526.patch

Possible fix.  Not sure how often C++ FE tries to modify something within
expressions returned by cxx_eval_constant_expression.  This patch is
conservative, perhaps might create too much garbage.  On the other side,
looking at what is done in other parts of cxx_eval_constant_expression, it
usually just creates new trees and thus has the unsharing semantics in it.
If cxx_eval_bare_aggregate's:
          /* Push our vtable pointer down into the base where it belongs.  */
          tree vptr_base = DECL_CONTEXT (ce->index);
          tree base_ctor;
          gcc_assert (ce->index == TYPE_VFIELD (type));
          for (base_ctor = VEC_index (constructor_elt, n, 0)->value; ;
               base_ctor = CONSTRUCTOR_ELT (base_ctor, 0)->value)
            if (TREE_TYPE (base_ctor) == vptr_base)
              { 
                constructor_elt *p = CONSTRUCTOR_ELT (base_ctor, 0);
                gcc_assert (p->index == ce->index);
                p->value = elt;
                break;
              }
is the only spot that actually tries to modify cxx_eval_constant_expression in
place, one could instead unshare it before starting to dive into the arguments,
but that could very well unshare twice e.g. all CONSTRUCTORS that went through
cxx_eval_bare_aggregate which created a new tree.

So this patch looks preferrable to me, but of course this is Jason's call what
to do.


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

* [Bug c++/46526] [4.6 Regression] VTable Problem?
  2010-11-17 21:38 [Bug c++/46526] New: VTable Problem? nate.knight at numerica dot us
                   ` (5 preceding siblings ...)
  2010-11-19  9:59 ` jakub at gcc dot gnu.org
@ 2010-11-19 10:02 ` jakub at gcc dot gnu.org
  2010-11-19 23:53 ` jakub at gcc dot gnu.org
  2010-11-20  0:05 ` jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2010-11-19 10:02 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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


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

* [Bug c++/46526] [4.6 Regression] VTable Problem?
  2010-11-17 21:38 [Bug c++/46526] New: VTable Problem? nate.knight at numerica dot us
                   ` (6 preceding siblings ...)
  2010-11-19 10:02 ` jakub at gcc dot gnu.org
@ 2010-11-19 23:53 ` jakub at gcc dot gnu.org
  2010-11-20  0:05 ` jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2010-11-19 23:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> 2010-11-19 23:50:26 UTC ---
Author: jakub
Date: Fri Nov 19 23:50:21 2010
New Revision: 166967

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=166967
Log:
    PR c++/46526
    * semantics.c (cxx_eval_call_expression): Unshare the result.

    * g++.dg/cpp0x/constexpr-base3.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-base3.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/46526] [4.6 Regression] VTable Problem?
  2010-11-17 21:38 [Bug c++/46526] New: VTable Problem? nate.knight at numerica dot us
                   ` (7 preceding siblings ...)
  2010-11-19 23:53 ` jakub at gcc dot gnu.org
@ 2010-11-20  0:05 ` jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2010-11-20  0:05 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
         AssignedTo|unassigned at gcc dot       |jakub at gcc dot gnu.org
                   |gnu.org                     |

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> 2010-11-19 23:53:46 UTC ---
Fixed.


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

end of thread, other threads:[~2010-11-19 23:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-17 21:38 [Bug c++/46526] New: VTable Problem? nate.knight at numerica dot us
2010-11-17 22:39 ` [Bug c++/46526] " redi at gcc dot gnu.org
2010-11-18 10:09 ` [Bug c++/46526] [4.6 Regression] " rguenth at gcc dot gnu.org
2010-11-18 14:29 ` redi at gcc dot gnu.org
2010-11-19  8:58 ` jakub at gcc dot gnu.org
2010-11-19  9:47 ` jakub at gcc dot gnu.org
2010-11-19  9:59 ` jakub at gcc dot gnu.org
2010-11-19 10:02 ` jakub at gcc dot gnu.org
2010-11-19 23:53 ` jakub at gcc dot gnu.org
2010-11-20  0:05 ` jakub at gcc dot gnu.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).