public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug optimization/14511] New: "pure virtual method called" error when calling a method on a static_casted object
@ 2004-03-10  7:03 bryner at brianryner dot com
  2004-03-10  7:04 ` [Bug optimization/14511] " bryner at brianryner dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: bryner at brianryner dot com @ 2004-03-10  7:03 UTC (permalink / raw)
  To: gcc-bugs

On a tree-ssa build pulled today, I get "pure virtual method called" (and
execution aborts) if I attempt to call a method on a static_casted pointer.  I
believe this regressed within the past few weeks.  The error occurs with -O2,
but not with -O.  gcc build details:

$ c++ -v
Reading specs from /usr/gcc-ssa/lib/gcc/i686-pc-linux-gnu/3.5-tree-ssa/specs
Configured with: ../gcc/configure --prefix=/usr/gcc-ssa --enable-shared
--enable-threads=posix --with-system-zlib --enable-__cxa_atexit
--host=i686-pc-linux-gnu --enable-languages=c,c++ --disable-checking
Thread model: posix
gcc version 3.5-tree-ssa 20040309 (merged 20040307)

-- 
           Summary: "pure virtual method called" error when calling a method
                    on a static_casted object
           Product: gcc
           Version: tree-ssa
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bryner at brianryner dot com
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i686-pc-linux-gnu


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


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

* [Bug optimization/14511] "pure virtual method called" error when calling a method on a static_casted object
  2004-03-10  7:03 [Bug optimization/14511] New: "pure virtual method called" error when calling a method on a static_casted object bryner at brianryner dot com
@ 2004-03-10  7:04 ` bryner at brianryner dot com
  2004-03-10  7:10 ` bryner at brianryner dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: bryner at brianryner dot com @ 2004-03-10  7:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bryner at brianryner dot com  2004-03-10 07:04 -------
Created an attachment (id=5891)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=5891&action=view)
testcase

testcase output:

$ c++ -O2 -o test_virt_cast test_virt_cast.cpp
$ ./test_virt_cast
pure virtual method called
terminate called without an active exception
Aborted


-- 


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


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

* [Bug optimization/14511] "pure virtual method called" error when calling a method on a static_casted object
  2004-03-10  7:03 [Bug optimization/14511] New: "pure virtual method called" error when calling a method on a static_casted object bryner at brianryner dot com
  2004-03-10  7:04 ` [Bug optimization/14511] " bryner at brianryner dot com
@ 2004-03-10  7:10 ` bryner at brianryner dot com
  2004-03-10 14:38 ` [Bug optimization/14511] [tree-ssa] " pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: bryner at brianryner dot com @ 2004-03-10  7:10 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code


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


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

* [Bug optimization/14511] [tree-ssa] "pure virtual method called" error when calling a method on a static_casted object
  2004-03-10  7:03 [Bug optimization/14511] New: "pure virtual method called" error when calling a method on a static_casted object bryner at brianryner dot com
  2004-03-10  7:04 ` [Bug optimization/14511] " bryner at brianryner dot com
  2004-03-10  7:10 ` bryner at brianryner dot com
@ 2004-03-10 14:38 ` pinskia at gcc dot gnu dot org
  2004-03-10 17:24 ` dnovillo at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-03-10 14:38 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-03-10 14:37 -------
Confirmed, this is an aliasing problem (I think caused by the C++ front-end).

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2004-03-10 14:37:59
               date|                            |
            Summary|"pure virtual method called"|[tree-ssa] "pure virtual
                   |error when calling a method |method called" error when
                   |on a static_casted object   |calling a method on a
                   |                            |static_casted object
   Target Milestone|---                         |tree-ssa


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


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

* [Bug optimization/14511] [tree-ssa] "pure virtual method called" error when calling a method on a static_casted object
  2004-03-10  7:03 [Bug optimization/14511] New: "pure virtual method called" error when calling a method on a static_casted object bryner at brianryner dot com
                   ` (2 preceding siblings ...)
  2004-03-10 14:38 ` [Bug optimization/14511] [tree-ssa] " pinskia at gcc dot gnu dot org
@ 2004-03-10 17:24 ` dnovillo at gcc dot gnu dot org
  2004-03-10 19:01 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dnovillo at gcc dot gnu dot org @ 2004-03-10 17:24 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |dnovillo at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED


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


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

* [Bug optimization/14511] [tree-ssa] "pure virtual method called" error when calling a method on a static_casted object
  2004-03-10  7:03 [Bug optimization/14511] New: "pure virtual method called" error when calling a method on a static_casted object bryner at brianryner dot com
                   ` (3 preceding siblings ...)
  2004-03-10 17:24 ` dnovillo at gcc dot gnu dot org
@ 2004-03-10 19:01 ` pinskia at gcc dot gnu dot org
  2004-03-15 21:36 ` dnovillo at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-03-10 19:01 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-03-10 19:01 -------
The issue I think is that the structs are not marked as they can alias each other.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2004-03-10 14:37:59         |2004-03-10 19:01:17
               date|                            |


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


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

* [Bug optimization/14511] [tree-ssa] "pure virtual method called" error when calling a method on a static_casted object
  2004-03-10  7:03 [Bug optimization/14511] New: "pure virtual method called" error when calling a method on a static_casted object bryner at brianryner dot com
                   ` (4 preceding siblings ...)
  2004-03-10 19:01 ` pinskia at gcc dot gnu dot org
@ 2004-03-15 21:36 ` dnovillo at gcc dot gnu dot org
  2004-03-17 19:28 ` dnovillo at redhat dot com
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dnovillo at gcc dot gnu dot org @ 2004-03-15 21:36 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dnovillo at gcc dot gnu dot org  2004-03-15 21:36 -------
dammit!  Bugzilla tricked me again and I attached a patch to the wrong case.  
Please disregard

-- 


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


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

* [Bug optimization/14511] [tree-ssa] "pure virtual method called" error when calling a method on a static_casted object
  2004-03-10  7:03 [Bug optimization/14511] New: "pure virtual method called" error when calling a method on a static_casted object bryner at brianryner dot com
                   ` (5 preceding siblings ...)
  2004-03-15 21:36 ` dnovillo at gcc dot gnu dot org
@ 2004-03-17 19:28 ` dnovillo at redhat dot com
  2004-03-17 19:44 ` cvs-commit at gcc dot gnu dot org
  2004-03-17 19:45 ` dnovillo at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: dnovillo at redhat dot com @ 2004-03-17 19:28 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dnovillo at redhat dot com  2004-03-17 19:28 -------
Subject: Re:  [tree-ssa] "pure virtual method
	called" error when calling a method on a static_casted object

On Wed, 2004-03-10 at 14:01, pinskia at gcc dot gnu dot org wrote:
> ------- Additional Comments From pinskia at gcc dot gnu dot org  2004-03-10 19:01 -------
> The issue I think is that the structs are not marked as they can alias each other.
>
Indeed.  The problem occurs when we replace the RHS of (3) with
&_ZTV4IFoo<D1485>[2]

     1.   this<D1553>_6->_vptr.IFoo<D1483> = &_ZTV4IFoo<D1485>[2];
     2.   this<D1550>_4->_vptr.IFoo<D1511> = &_ZTV3Bar<D1512>[2];
     3.   T.3<D1532>_10 = this<D1553>_6->_vptr.IFoo<D1483>;
     4.   T.4<D1533>_11 = *T.3<D1532>_10;
     5.   #   VUSE <_ZTV4IFoo_1>;
     6.   #   VUSE <_ZTV3Bar_2>;
     7.   T.4_11 (this<D1553>_6);

The alias pass was not computing type aliases properly for this<D1553>
and this<D1550> for two reasons:

      * Variables _ZTV4IFoo<D1485> and _ZTV3Bar<D1512 are read-only, so
        they were being ignored.  However, ignoring them meant that the
        alias sets for this<D1553> and this<D1550> were not being
        populated, therefore the two memory tags were not found to
        conflict, allowing DOM to propagate (1) into (3).
      * The sub-type checking in may_alias_p was not computing the right
        pointer-to type for ARRAY_TYPEs.

Bootstrapped and tested on x86, x86-64 and ia64.


Diego.


	* tree-ssa-alias.c (compute_flow_insensitive_aliasing): Do not
	ignore read-only variables.
	(may_alias_p): Fix pointer-to-var calculation when 'var' is an
	array.

testsuite/ChangeLog.tree-ssa:

	* g++.dg/tree-ssa/20040317-1.C: New test.

Index: tree-ssa-alias.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-alias.c,v
retrieving revision 1.1.2.12
diff -d -c -p -d -u -p -r1.1.2.12 tree-ssa-alias.c
--- tree-ssa-alias.c	16 Mar 2004 22:31:55 -0000	1.1.2.12
+++ tree-ssa-alias.c	17 Mar 2004 19:17:31 -0000
@@ -797,10 +797,6 @@ compute_flow_insensitive_aliasing (struc
 	  if (!tag_stored_p && !var_stored_p)
 	    continue;
 	     
-	  /* Skip memory tags which are written if the variable is readonly.  */
-	  if (tag_stored_p && TREE_READONLY (var))
-	    continue;
-
 	  if (may_alias_p (p_map->var, p_map->set, var, v_map->set))
 	    {
 	      size_t num_tag_refs = ai->num_references[tag_ann->uid];
@@ -1337,7 +1333,12 @@ may_alias_p (tree ptr, HOST_WIDE_INT mem
       if (AGGREGATE_TYPE_P (TREE_TYPE (mem))
 	  || AGGREGATE_TYPE_P (TREE_TYPE (var)))
 	{
-	  tree ptr_to_var = TYPE_POINTER_TO (TREE_TYPE (var));
+	  tree ptr_to_var;
+	  
+	  if (TREE_CODE (TREE_TYPE (var)) == ARRAY_TYPE)
+	    ptr_to_var = TYPE_POINTER_TO (TREE_TYPE (TREE_TYPE (var)));
+	  else
+	    ptr_to_var = TYPE_POINTER_TO (TREE_TYPE (var));
 
 	  /* If no pointer-to VAR exists, then MEM can't alias VAR.  */
 	  if (ptr_to_var == NULL_TREE)
Index: testsuite/g++.dg/tree-ssa/20040317-1.C
===================================================================
RCS file: testsuite/g++.dg/tree-ssa/20040317-1.C
diff -N testsuite/g++.dg/tree-ssa/20040317-1.C
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/g++.dg/tree-ssa/20040317-1.C	17 Mar 2004 19:17:31 -0000
@@ -0,0 +1,38 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+/* Test provided by Brian Ryner in PR 14511.  The alias analyzer was
+   not handling structures containing arrays properly.  In this case,
+   the static cast was introducing two assignments of the form
+
+	  this_6->_vptr.IFoo = &_ZTV4IFoo[2];
+	  this_4->_vptr.IFoo = &_ZTV3Bar[2];
+
+   which were not considered to alias each other because the alias
+   analyzer was not computing a proper pointer to array elements.
+   Another related bug was the type based alias analyzer not computing
+   alias relations to _ZTV4IFoo and _ZTV3Bar.  Since those variables
+   are read-only, it was disregarding alias information for them.
+   So, the memory tags for the two 'this' variables were not being
+   marked as aliased with these variables.  Resulting in the two
+   assignments not aliasing each other.
+
+   This was causing the optimizers to generate a call to the virtual
+   method Foo() instead of the overloaded version.  */
+
+struct IFoo
+{
+  virtual void Foo() = 0;
+};
+
+struct Bar : IFoo
+{
+  void Foo() { }
+};
+
+int main(int argc, char **argv)
+{
+  Bar* b = new Bar();
+  static_cast<IFoo*>(b)->Foo();
+  return 0;
+}



-- 


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


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

* [Bug optimization/14511] [tree-ssa] "pure virtual method called" error when calling a method on a static_casted object
  2004-03-10  7:03 [Bug optimization/14511] New: "pure virtual method called" error when calling a method on a static_casted object bryner at brianryner dot com
                   ` (6 preceding siblings ...)
  2004-03-17 19:28 ` dnovillo at redhat dot com
@ 2004-03-17 19:44 ` cvs-commit at gcc dot gnu dot org
  2004-03-17 19:45 ` dnovillo at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-03-17 19:44 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-03-17 19:44 -------
Subject: Bug 14511

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	tree-ssa-20020619-branch
Changes by:	dnovillo@gcc.gnu.org	2004-03-17 19:44:36

Modified files:
	gcc            : ChangeLog.tree-ssa tree-ssa-alias.c 
	gcc/testsuite  : ChangeLog.tree-ssa 
	gcc/testsuite/g++.dg: README 
Added files:
	gcc/testsuite/g++.dg/tree-ssa: 20040317-1.C 

Log message:
	PR optimization/14511
	* tree-ssa-alias.c (compute_flow_insensitive_aliasing): Do not
	ignore read-only variables.
	(may_alias_p): Fix pointer-to-var calculation when 'var' is an
	array.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.tree-ssa.diff?cvsroot=gcc&only_with_tag=tree-ssa-20020619-branch&r1=1.1.2.1278&r2=1.1.2.1279
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-ssa-alias.c.diff?cvsroot=gcc&only_with_tag=tree-ssa-20020619-branch&r1=1.1.2.12&r2=1.1.2.13
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.tree-ssa.diff?cvsroot=gcc&only_with_tag=tree-ssa-20020619-branch&r1=1.1.2.190&r2=1.1.2.191
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/README.diff?cvsroot=gcc&only_with_tag=tree-ssa-20020619-branch&r1=1.2.14.4&r2=1.2.14.5
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/tree-ssa/20040317-1.C.diff?cvsroot=gcc&only_with_tag=tree-ssa-20020619-branch&r1=NONE&r2=1.1.2.1



-- 


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


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

* [Bug optimization/14511] [tree-ssa] "pure virtual method called" error when calling a method on a static_casted object
  2004-03-10  7:03 [Bug optimization/14511] New: "pure virtual method called" error when calling a method on a static_casted object bryner at brianryner dot com
                   ` (7 preceding siblings ...)
  2004-03-17 19:44 ` cvs-commit at gcc dot gnu dot org
@ 2004-03-17 19:45 ` dnovillo at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: dnovillo at gcc dot gnu dot org @ 2004-03-17 19:45 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dnovillo at gcc dot gnu dot org  2004-03-17 19:45 -------

Fixed.

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


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


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

end of thread, other threads:[~2004-03-17 19:45 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-10  7:03 [Bug optimization/14511] New: "pure virtual method called" error when calling a method on a static_casted object bryner at brianryner dot com
2004-03-10  7:04 ` [Bug optimization/14511] " bryner at brianryner dot com
2004-03-10  7:10 ` bryner at brianryner dot com
2004-03-10 14:38 ` [Bug optimization/14511] [tree-ssa] " pinskia at gcc dot gnu dot org
2004-03-10 17:24 ` dnovillo at gcc dot gnu dot org
2004-03-10 19:01 ` pinskia at gcc dot gnu dot org
2004-03-15 21:36 ` dnovillo at gcc dot gnu dot org
2004-03-17 19:28 ` dnovillo at redhat dot com
2004-03-17 19:44 ` cvs-commit at gcc dot gnu dot org
2004-03-17 19:45 ` dnovillo 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).