https://bugs.llvm.org/show_bug.cgi?id=37146

            Bug ID: 37146
           Summary: clang-cl emits special functions for non-trivial
                    C-structs ("__destructor_8") introduced for
                    Objective-C
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangb...@nondot.org
          Reporter: stephan.bergmann.second...@googlemail.com
                CC: llvm-bugs@lists.llvm.org

As discussed in the mail thread starting at
<http://lists.llvm.org/pipermail/cfe-dev/2018-April/057532.html> "[cfe-dev]
Multiple-defined __destructor_1, __destructor_8 when building with recent
clang-cl": "After a recent pull of LLVM/Clang trunk, my clang-cl build of
LibreOffice on Windows started to fail to link some DLL because of
__destructor_1 and __destructor_8 symbols defined in multiple objects."

I have now tracked that down to the following reproducer:

> $ cat test.cc
> int & f1();
> struct S1 { void * m; };
> struct S2 { template<typename T> void m(int, T) { m(f1(), S1()); } };
> void f2(S2 & s) { s.m(0, 0); }
> 
> $ clang --driver-mode=cl -fmsc-version=1900 --target=x86_64-pc-windows-mscv 
> -EHs -Fa -Xclang -emit-llvm test.cc
[lots of irrelevant linker errors]
> 
> $ grep __destructor_8 test.asm
>   call void @__destructor_8(i8** %6) #4 [ "funclet"(token %5) ]
>   call void @__destructor_8(i8** %6) #4 [ "funclet"(token %5) ]
> define linkonce_odr hidden void @__destructor_8(i8** %dst) #3 {

There's two calls to GenDestructorFuncName
(clang/lib/CodeGen/CGNonTrivialStruct.cpp) to produce two instances of
"__destructor_8", the first is at

> #0  clang::CodeGen::CodeGenFunction::callCStructDestructor 
> (this=0x7fffffff7180, Dst=...) at clang/lib/CodeGen/CGNonTrivialStruct.cpp:850
> #1  0x00000000045dc98a in (anonymous namespace)::DestroyUnpassedArg::Emit 
> (this=0x7fffffff47e0, CGF=..., flags=...) at clang/lib/CodeGen/CGCall.cpp:3466
> #2  0x000000000460a660 in EmitCleanup (CGF=..., Fn=0x7fffffff47e0, flags=..., 
> ActiveFlag=...) at clang/lib/CodeGen/CGCleanup.cpp:568
> #3  0x000000000460be9f in clang::CodeGen::CodeGenFunction::PopCleanupBlock 
> (this=0x7fffffff7180, FallthroughIsBranchThrough=false) at 
> clang/lib/CodeGen/CGCleanup.cpp:988
> #4  0x000000000460ca86 in 
> clang::CodeGen::CodeGenFunction::DeactivateCleanupBlock (this=0x7fffffff7180, 
> C=..., dominatingIP=0xd1b1210) at clang/lib/CodeGen/CGCleanup.cpp:1241
> #5  0x00000000045daf77 in deactivateArgCleanupsBeforeCall (CGF=..., 
> CallArgs=...) at clang/lib/CodeGen/CGCall.cpp:3147
> #6  0x00000000045e1267 in clang::CodeGen::CodeGenFunction::EmitCall 
> (this=0x7fffffff7180, CallInfo=..., Callee=..., ReturnValue=..., 
> CallArgs=..., callOrInvoke=0x0, Loc=...) at clang/lib/CodeGen/CGCall.cpp:4162
> #7  0x0000000004668c0b in 
> clang::CodeGen::CodeGenFunction::EmitCXXMemberOrOperatorCall 
> (this=0x7fffffff7180, MD=0xd1ae980, Callee=..., ReturnValue=..., 
> This=0xd1aaea8, ImplicitParam=0x0, ImplicitParamTy=..., CE=0xd1aed38, 
> RtlArgs=0x0) at clang/lib/CodeGen/CGExprCXX.cpp:93
> #8  0x000000000466ab98 in 
> clang::CodeGen::CodeGenFunction::EmitCXXMemberOrOperatorMemberCallExpr 
> (this=0x7fffffff7180, CE=0xd1aed38, MD=0xd1ae980, ReturnValue=..., 
> HasQualifier=false, Qualifier=0x0, IsArrow=true, Base=0xd1aea88) at 
> clang/lib/CodeGen/CGExprCXX.cpp:406
> #9  0x000000000466921e in 
> clang::CodeGen::CodeGenFunction::EmitCXXMemberCallExpr (this=0x7fffffff7180, 
> CE=0xd1aed38, ReturnValue=...) at clang/lib/CodeGen/CGExprCXX.cpp:191
> #10 0x0000000004650c88 in clang::CodeGen::CodeGenFunction::EmitCallExpr 
> (this=0x7fffffff7180, E=0xd1aed38, ReturnValue=...) at 
> clang/lib/CodeGen/CGExpr.cpp:4257
> #11 0x00000000046816f2 in (anonymous 
> namespace)::ScalarExprEmitter::VisitCallExpr (this=0x7fffffff6ce0, 
> E=0xd1aed38) at clang/lib/CodeGen/CGExprScalar.cpp:518
> #12 0x0000000004695b33 in clang::StmtVisitorBase<clang::make_ptr, (anonymous 
> namespace)::ScalarExprEmitter, llvm::Value*>::VisitCXXMemberCallExpr 
> (this=0x7fffffff6ce0, S=0xd1aed38) at 
> clang/include/clang/AST/StmtNodes.inc:339
> #13 0x0000000004694905 in clang::StmtVisitorBase<clang::make_ptr, (anonymous 
> namespace)::ScalarExprEmitter, llvm::Value*>::Visit (this=0x7fffffff6ce0, 
> S=0xd1aed38) at clang/include/clang/AST/StmtNodes.inc:339
> #14 0x0000000004680a46 in (anonymous namespace)::ScalarExprEmitter::Visit 
> (this=0x7fffffff6ce0, E=0xd1aed38) at clang/lib/CodeGen/CGExprScalar.cpp:358
> #15 0x0000000004687d87 in (anonymous 
> namespace)::ScalarExprEmitter::VisitExprWithCleanups (this=0x7fffffff6ce0, 
> E=0xd1aedd8) at clang/lib/CodeGen/CGExprScalar.cpp:1841
> #16 0x0000000004694b15 in clang::StmtVisitorBase<clang::make_ptr, (anonymous 
> namespace)::ScalarExprEmitter, llvm::Value*>::Visit (this=0x7fffffff6ce0, 
> S=0xd1aedd8) at clang/include/clang/AST/StmtNodes.inc:507
> #17 0x0000000004680a46 in (anonymous namespace)::ScalarExprEmitter::Visit 
> (this=0x7fffffff6ce0, E=0xd1aedd8) at clang/lib/CodeGen/CGExprScalar.cpp:358
> #18 0x0000000004692ade in clang::CodeGen::CodeGenFunction::EmitScalarExpr 
> (this=0x7fffffff7180, E=0xd1aedd8, IgnoreResultAssign=true) at 
> clang/lib/CodeGen/CGExprScalar.cpp:3834
> #19 0x00000000046394da in clang::CodeGen::CodeGenFunction::EmitAnyExpr 
> (this=0x7fffffff7180, E=0xd1aedd8, aggSlot=..., ignoreResult=true) at 
> clang/lib/CodeGen/CGExpr.cpp:178
> #20 0x0000000004639463 in clang::CodeGen::CodeGenFunction::EmitIgnoredExpr 
> (this=0x7fffffff7180, E=0xd1aedd8) at clang/lib/CodeGen/CGExpr.cpp:163
> #21 0x00000000042eaaaa in clang::CodeGen::CodeGenFunction::EmitStmt 
> (this=0x7fffffff7180, S=0xd1aedd8, Attrs=...) at 
> clang/lib/CodeGen/CGStmt.cpp:116
> #22 0x00000000042eb83a in 
> clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope 
> (this=0x7fffffff7180, S=..., GetLast=false, AggSlot=...) at 
> clang/lib/CodeGen/CGStmt.cpp:390
> #23 0x0000000004361af4 in clang::CodeGen::CodeGenFunction::EmitFunctionBody 
> (this=0x7fffffff7180, Args=..., Body=0xd1aedf0) at 
> clang/lib/CodeGen/CodeGenFunction.cpp:1170
> #24 0x0000000004362672 in clang::CodeGen::CodeGenFunction::GenerateCode 
> (this=0x7fffffff7180, GD=..., Fn=0xd1ab6b8, FnInfo=...) at 
> clang/lib/CodeGen/CodeGenFunction.cpp:1335
> #25 0x0000000004383dea in 
> clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition (this=0xd13d6e0, 
> GD=..., GV=0xd1ab6b8) at clang/lib/CodeGen/CodeGenModule.cpp:3613
> #26 0x000000000437ea06 in clang::CodeGen::CodeGenModule::EmitGlobalDefinition 
> (this=0xd13d6e0, GD=..., GV=0xd1ab6b8) at 
> clang/lib/CodeGen/CodeGenModule.cpp:2273
> #27 0x000000000437c01d in clang::CodeGen::CodeGenModule::EmitDeferred 
> (this=0xd13d6e0) at clang/lib/CodeGen/CodeGenModule.cpp:1695
> #28 0x0000000004374e84 in clang::CodeGen::CodeGenModule::Release 
> (this=0xd13d6e0) at clang/lib/CodeGen/CodeGenModule.cpp:392
> #29 0x0000000004f9e095 in (anonymous 
> namespace)::CodeGeneratorImpl::HandleTranslationUnit (this=0xd13d0e0, 
> Ctx=...) at clang/lib/CodeGen/ModuleBuilder.cpp:265
> #30 0x0000000004f97f84 in clang::BackendConsumer::HandleTranslationUnit 
> (this=0xd13ced0, C=...) at clang/lib/CodeGen/CodeGenAction.cpp:236
> #31 0x0000000005e98d43 in clang::ParseAST (S=..., PrintStats=false, 
> SkipFunctionBodies=false) at clang/lib/Parse/ParseAST.cpp:164
> #32 0x000000000492ef55 in clang::ASTFrontendAction::ExecuteAction 
> (this=0xd11cb00) at clang/lib/Frontend/FrontendAction.cpp:1005
> #33 0x0000000004f96520 in clang::CodeGenAction::ExecuteAction 
> (this=0xd11cb00) at clang/lib/CodeGen/CodeGenAction.cpp:1043
> #34 0x000000000492e97f in clang::FrontendAction::Execute (this=0xd11cb00) at 
> clang/lib/Frontend/FrontendAction.cpp:904
> #35 0x00000000048c202f in clang::CompilerInstance::ExecuteAction 
> (this=0xd110070, Act=...) at clang/lib/Frontend/CompilerInstance.cpp:989
> #36 0x0000000004a75f8a in clang::ExecuteCompilerInvocation (Clang=0xd110070) 
> at clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:255
> #37 0x0000000001e26a5d in cc1_main (Argv=..., Argv0=0x7fffffffe43c 
> "clang-6.0", MainAddr=0x1e19848 <GetExecutablePath[abi:cxx11](char const*, 
> bool)>) at clang/tools/driver/cc1_main.cpp:221
> #38 0x0000000001e1bf51 in ExecuteCC1Tool (argv=..., Tool=...) at 
> clang/tools/driver/driver.cpp:310
> #39 0x0000000001e1cb88 in main (argc_=64, argv_=0x7fffffffdef8) at 
> clang/tools/driver/driver.cpp:390

where in #1 DestroyUnpassedArg::Emit (clang/lib/CodeGen/CGCall.cpp) DtorKind is
DK_none.

The relevant code there (which probably assumes that DtorKind is something like
DK_objc_*_lifetime?) got introduced with <https://reviews.llvm.org/D41228>
"[ObjC] Enable __strong pointers in structs under ARC".

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to