-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clang emits U symbol while gcc emits W one #6725
Comments
testcase |
looks like the problem is that ~_Rb_tree() is {Ptr = 0} when CodeGenModule::GetOrCreateLLVMFunction is deciding if it should be emitted. As a consequence FD->isThisDeclarationADefinition() returns false and the destructor is not emitted. This is true even if there is some real code in ~_Rb_tree(). |
Looking a bit more it looks like the problem is with the template instantiation. Sema::ActOnFinishFunctionBody is being called on the template of the destructor, but never on the instantiated one. That is why setBody is never called. |
Going one level up, the issue is that Sema::MarkDeclarationReferenced is never called on ~_Rb_tree |
OK, looks like this needs bigger changes to clang than I can get done tonight. If anyone else is interested in fixing this bug, go for it. I might try again next weekend. This is what is happening: We have special code for handing emitting implicit destructors in CodeGenModule::GetOrCreateLLVMFunction. The problem happens when a implicit destructor references an explicit one that is defined in a template. In the testcase the implicit destructor is ~BlockFunction() and the explicit one is ~_Rb_tree(). The problem is that since the special case is on codegen, that is too late to call Sema::MarkDeclarationReferenced. Normally this method is the one that would add the destructor to the PendingImplicitInstantiations list. Being on that list eventually causes InstantiateFunctionDefinition to be called on it and that finally calls setBody. This is not a problem for non-templates since the body is set early on (no instantiation is required). Looks like what we need is to replicated the existing logic from CodeGen into Sema. Template instantiation is a form of code gen anyway :-) Using the attached test as an example, the calls that have to happen are:
Another option is to add a ActOnImplicitConstructorOrDestructor. I don't have enough experience on clang to know which one is better. |
This seems like a good place to assert() that Sema did its job and marked the implicit destructor as being used.
Right.
Much of this logic already exists in Sema; we're probably just missing a MarkDeclarationReferenced call where we're implicitly using a destructor.
|
patch |
One testcase that fails the new assert struct box { struct pile_box : public box { pile_box::pile_box(box *pp)
|
patch |
Overall looks good; those are great asserts in codegen, thank you. Please name "needsVtable" "ShouldEmitVtableForCall" or something like that, and have it take a Sema& instead of an ASTContext&, just in case. Also, conventionally the Sema/Context argument comes first, although we're not terribly consistent about that. |
The following code still fails the new asserts: class Option { |
patch |
New reduced testcase that fails with the new asserts: struct allocator { |
patch |
And the new reduced testcase is: struct TypedInit { |
patch The problem with Sema::BuildBaseInitializer is that is is never called in code like struct TypedInit { |
the last patch breaks libstdc++ build with: /data/home/rdivacky/clangbsd/gnu/lib/libstdc++/../../../contrib/libstdc++/include/ext/stdio_sync_filebuf.h:258:34: error: I can provide testcase in the evening |
patch |
Reduced testcase: class Option { |
Super-important for 2.7 |
patch extension extern template class opt; |
This testcase was fixed by revision 97589: $ clang++ -c test.cpp |
Trying to mark as fixed .... |
Trying again... |
Extended Description
when compiling the attached test case I am getting:
pes delta$ clang++ -O0 -c foo.cpp && nm foo.o | grep Rb_tree
pes delta$ g++ -O0 -c foo.cpp && nm foo.o | grep Rb_tree
0000000000000000 W _ZN8_Rb_treeIPK4Decl4pairIKS2_9CharUnitsE10_Select1stIS6_E4lessIS2_E9allocatorIS6_EED1Ev
The text was updated successfully, but these errors were encountered: