Playing with devirtualization in g++4.9

Robert Matusewicz matekm@gmail.com
Wed Apr 2 16:49:00 GMT 2014


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I found that g++4.9.0 have -fdevirtualize switch and wanted to play with
that feature for a while. I wrote simple, non-trivial program to check
how g++ will behave in obvious case:

==== SOURCE BEGIN ====
#include <iostream>

class B final
{
public:
    virtual void test() { std::cout << "Test" << std::endl;  }
};

int main()
{
    B test;
    test.test();
    return 0;
}
==== SOURCE ENDS ====

I compiled this code with

g++ -std=c++11 -fdevirtualize simple1.cpp

and then objdumped symbols:

objdump -t a.out | c++filt  | grep vtable

and noticed that vtable is present (I would expect it will be removed)
00000000006012c0  w    O .bss	0000000000000058              vtable for
__cxxabiv1::__class_type_info@@CXXABI_1.3
0000000000400b20  w    O .rodata	0000000000000018              vtable for B


I found some examples in testsuite (opt/ and ipa/) but for those
examples I checked, I can "reproduce" devirtualization.

Is there a documentation somewhere to see what is the current status of
devirtualiztion in g++ 4.9? I mean, beside the source code. Or maybe
someone could explain me why this case can't be devirtualized?

Best regards
Robert
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJTPD+dAAoJEATzNIO2M4RN7KUP/RwDVzk+yGdDT9Lhl7bHxCpu
57AFNybReEB0kiqYB0znkagpZZ2pumVF2lKGY9cT48f88fcR20nSq2sy0M6Y+a8D
v+GbH7cuTPg1wfDe3mJogKUMCCuax23FHetsf6PXkRW72V+TI+PROtlEIDLM7iGs
dvezN75dzKCyS6avhJymJg8bIheylBzgp6wnX1VyLOcRiqVoViHPPVQc7JAMaE+s
RW1wupE3pWAWevYGdWpPEgjd02+8/nQgz8OsT9aVCyZw3+txtEpNE+CHgw3S2xNd
aDNpWUlfWIS6d9gmT9hIbk40PkMBrigFktN7eqcOs6glaQhP0dfyaMy69TiKABKs
bGONJQcNQ8x+Vqn2MfHeM+jRjd1XneT+av6nx8AOO/lfjX41vQMMZQ9ZysN3aIj7
zLxnsk/pbuqa8mjVzt/fmO0IXCop7mH16ZKE6W74GHhh9BQDG8urIlCIIYZ04Qbp
mKuQFaGfrUF20OxXpgkvNM0jzhNUT5h5mSrgqeJ3A4LINXksdBC+VhMP+9QUvQ5i
9aNBGpfSQK7svCjeDVezgZhA7TmmLZlZQfT6bYIAhWw8rR7OByXriMrlm+IrxsjG
t6vdgxrn4DTOWYrCTh+okY89cK7BhgzVN4zFLGRE3hE5k8DhroT1RwEoY9v2JaGc
SNEbtSf7FNpBRWRPZjF0
=l2Ey
-----END PGP SIGNATURE-----



More information about the Gcc-help mailing list