[cfe-dev] Is it a bug? clang doesn't generate "complete object constructor" code when the class contains pure virtual method.

orchidnju-dummy at yahoo.com.cn orchidnju-dummy at yahoo.com.cn
Sun Dec 9 23:35:00 PST 2012


I'm migrating a project from GCC to Clang on OS X, and meet 1 code generation difference by clang/gcc: clang doesn't generate "complete object constructor" (the C1 version) code when the class contains pure virtual method, but gcc does, (and llvm-gcc also does).

I'm not sure whether this is a clang bug, but could anyone tell me whether clang acts properly? Is there any standard that defines whether compiler shouldn't generate C1 version construct when the class has pure virtual method?

Below is the detail information related with the issue I met:

[Summary] clang doesn't generate "complete object constructor" (the C1 version)

code when the class contains pure virtual method. 

[Clang Version] Apple clang version 4.0 (tags/Apple/clang-421.0.60) (based on LLVM 3.1svn)
[Reproduce Steps]
1. create ABISample.cpp to include below code. class A is common class, class B
contains 1 pure virtual method.
===============================
class A
{
public: A();
}; class B
{
public: B(); virtual void Foo() = 0;
}; A::A() {};
B::B() {};
=============================== 2. compile the code with clang++/g++:
- clang++ -c ABISample.cpp -o clang.o
- g++ -c ABISample.cpp -o g++.o 3. use nm to check generated symbols:
$ nm clang.o 
00000000000000e0 s EH_frame0
0000000000000000 T __ZN1AC1Ev
00000000000000f8 S __ZN1AC1Ev.eh
0000000000000020 T __ZN1AC2Ev
0000000000000120 S __ZN1AC2Ev.eh
0000000000000030 T __ZN1BC2Ev
0000000000000148 S __ZN1BC2Ev.eh
0000000000000068 S __ZTI1B
0000000000000078 S __ZTS1B
0000000000000050 S __ZTV1B U __ZTVN10__cxxabiv117__class_type_infoE U ___cxa_pure_virtual $ nm g++.o 
00000000000000a8 s EH_frame0
000000000000000a T __ZN1AC1Ev
00000000000000f0 S __ZN1AC1Ev.eh
0000000000000000 T __ZN1AC2Ev
00000000000000c0 S __ZN1AC2Ev.eh
000000000000003c T __ZN1BC1Ev
0000000000000150 S __ZN1BC1Ev.eh
0000000000000014 T __ZN1BC2Ev
0000000000000120 S __ZN1BC2Ev.eh
0000000000000090 S __ZTI1B
00000000000000a0 S __ZTS1B
0000000000000070 S __ZTV1B U __ZTVN10__cxxabiv117__class_type_infoE U ___cxa_pure_virtual 4. compare two symbol list, you can find class B's C1 constructor are generated
by g++ but not clang++:
000000000000003c T __ZN1BC1Ev
0000000000000150 S __ZN1BC1Ev.eh 5. If I remove "= 0" from Foo() to change it from pure virtual to virtual
method, clang will generate C1 constructor.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121210/d25eb715/attachment.html>


More information about the cfe-dev mailing list