In a couple functions (type_update_when_use_rtti_test and
authorLuis Machado <lgustavo@codesourcery.com>
Tue, 17 Jun 2014 09:42:23 +0000 (10:42 +0100)
committerLuis Machado <lgustavo@codesourcery.com>
Tue, 17 Jun 2014 09:42:23 +0000 (10:42 +0100)
skip_type_update_when_not_use_rtti_test) the testcase assumes an
uninitialized object has a specific type. In particular, 'ptr' and
's'.

In reality the compiler is free to do what it wants with that
uninitialized variable, even initialize it beforehand with the future
assignment's value.  This is exactly what happens on some targets.

ptr should have type 'Base *', but it really has type 'Derived *'
because it is already initialized (earlier) by the compiler. The same
thing happens to 's'.

The following patch addresses this by explicitly initializing those
variables so the compiler doesn't optimize their assignments and GDB
can print their correct values.

2014-06-17  Luis Machado  <lgustavo@codesourcery.com>

* gdb.mi/mi-var-rtti.cc (type_update_when_use_rtti_test):
Initialize ptr and S explicitly.
(skip_type_update_when_not_use_rtti_test): Likewise.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.mi/mi-var-rtti.cc

index cb671f5306a9ef740b8dd8c6e08e646910099e35..a4e4e3ea4c8ac4480ac83324d38cd3211496b741 100644 (file)
@@ -1,3 +1,9 @@
+2014-06-17  Luis Machado  <lgustavo@codesourcery.com>
+
+       * gdb.mi/mi-var-rtti.cc (type_update_when_use_rtti_test):
+       Initialize ptr and S explicitly.
+       (skip_type_update_when_not_use_rtti_test): Likewise.
+
 2014-06-16  Keith Seitz  <keiths@redhat.com>
 
        PR mi/15863
index 94098b2cf928370454c7a50ee21008e7b5be99d4..fe19b881a49b84ce7b7e05ac679becad9922f251 100644 (file)
@@ -241,6 +241,12 @@ void use_rtti_with_multiple_inheritence_test ()
 void type_update_when_use_rtti_test ()
 {
   /*: BEGIN: type_update_when_use_rtti :*/
+       Base *ptr = 0;
+       struct S {
+               Base* ptr;
+               S ( Base* v ) :
+                       ptr ( v ) {}
+       } s ( ptr );
        Derived d;
   /*: 
        set testname type_update_when_use_rtti
@@ -260,12 +266,8 @@ void type_update_when_use_rtti_test ()
        check_derived_children_without_rtti S.public.ptr s.ptr $testname
   :*/
 
-       Base* ptr = &d;
-       struct S {
-               Base* ptr;
-               S ( Base* v ) :
-                       ptr ( v ) {}
-       } s ( &d );
+       ptr = &d;
+       s.ptr = &d;
   /*:
        mi_varobj_update_with_type_change PTR {Derived \*} 2 \
                "update ptr to derived in $testname"
@@ -295,6 +297,12 @@ void type_update_when_use_rtti_test ()
 void skip_type_update_when_not_use_rtti_test ()
 {
   /*: BEGIN: skip_type_update_when_not_use_rtti :*/
+       Base *ptr = 0;
+       struct S {
+               Base* ptr;
+               S ( Base* v ) :
+                       ptr ( v ) {}
+       } s ( ptr );
        Derived d;
   /*: 
        set testname skip_type_update_when_not_use_rtti
@@ -314,12 +322,8 @@ void skip_type_update_when_not_use_rtti_test ()
        check_derived_children_without_rtti S.public.ptr s.ptr $testname
   :*/
 
-       Base* ptr = &d;
-       struct S {
-               Base* ptr;
-               S ( Base* v ) :
-                       ptr ( v ) {}
-       } s ( &d );
+       ptr = &d;
+       s.ptr = &d;
   /*: 
        mi_varobj_update PTR {PTR PTR.public.A} \
                "update ptr to derived type in $testname"
This page took 0.03702 seconds and 4 git commands to generate.