From 142f9e99018a85105cee570133c111a52f2053ec Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 4 Feb 2011 00:01:24 +0000 Subject: [PATCH] -fapple-kext cannot have 'weak' visibility in this abi. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124834 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticDriverKinds.td | 2 + lib/CodeGen/CodeGenModule.cpp | 47 +++++++++++++------- lib/Frontend/CompilerInvocation.cpp | 9 +++- test/CodeGenCXX/apple-kext-linkage.C | 25 +++++++++++ 4 files changed, 66 insertions(+), 17 deletions(-) create mode 100644 test/CodeGenCXX/apple-kext-linkage.C diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index 24a0291ba6..ef1c9e7d8b 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -77,6 +77,8 @@ def err_drv_cc_print_options_failure : Error< def err_drv_preamble_format : Error< "incorrect format for -preamble-bytes=N,END">; +def warn_c_kext : Warning< + "ignoring -fapple-kext which is valid for c++ and objective-c++ only">; def warn_drv_unsupported_option_argument : Warning< "ignoring unsupported argument '%1' to option '%0'">; def warn_drv_input_file_unused : Warning< diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index b8f91b464d..ec3a8bf658 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -374,7 +374,9 @@ CodeGenModule::getFunctionLinkage(const FunctionDecl *D) { // In C99 mode, 'inline' functions are guaranteed to have a strong // definition somewhere else, so we can use available_externally linkage. if (Linkage == GVA_C99Inline) - return llvm::Function::AvailableExternallyLinkage; + return !Context.getLangOptions().AppleKext + ? llvm::Function::AvailableExternallyLinkage + : llvm::Function::InternalLinkage; // In C++, the compiler has to emit a definition in every translation unit // that references the function. We should use linkonce_odr because @@ -383,14 +385,18 @@ CodeGenModule::getFunctionLinkage(const FunctionDecl *D) { // merged with other definitions. c) C++ has the ODR, so we know the // definition is dependable. if (Linkage == GVA_CXXInline || Linkage == GVA_TemplateInstantiation) - return llvm::Function::LinkOnceODRLinkage; + return !Context.getLangOptions().AppleKext + ? llvm::Function::LinkOnceODRLinkage + : llvm::Function::InternalLinkage; // An explicit instantiation of a template has weak linkage, since // explicit instantiations can occur in multiple translation units // and must all be equivalent. However, we are not allowed to // throw away these explicit instantiations. if (Linkage == GVA_ExplicitTemplateInstantiation) - return llvm::Function::WeakODRLinkage; + return !Context.getLangOptions().AppleKext + ? llvm::Function::WeakODRLinkage + : llvm::Function::InternalLinkage; // Otherwise, we have strong external linkage. assert(Linkage == GVA_StrongExternal); @@ -1089,21 +1095,29 @@ CodeGenModule::getVTableLinkage(const CXXRecordDecl *RD) { return llvm::GlobalVariable::AvailableExternallyLinkage; if (KeyFunction->isInlined()) - return llvm::GlobalVariable::LinkOnceODRLinkage; + return !Context.getLangOptions().AppleKext ? + llvm::GlobalVariable::LinkOnceODRLinkage : + llvm::Function::InternalLinkage; return llvm::GlobalVariable::ExternalLinkage; case TSK_ImplicitInstantiation: - return llvm::GlobalVariable::LinkOnceODRLinkage; + return !Context.getLangOptions().AppleKext ? + llvm::GlobalVariable::LinkOnceODRLinkage : + llvm::Function::InternalLinkage; case TSK_ExplicitInstantiationDefinition: - return llvm::GlobalVariable::WeakODRLinkage; + return !Context.getLangOptions().AppleKext ? + llvm::GlobalVariable::WeakODRLinkage : + llvm::Function::InternalLinkage; case TSK_ExplicitInstantiationDeclaration: // FIXME: Use available_externally linkage. However, this currently // breaks LLVM's build due to undefined symbols. // return llvm::GlobalVariable::AvailableExternallyLinkage; - return llvm::GlobalVariable::LinkOnceODRLinkage; + return !Context.getLangOptions().AppleKext ? + llvm::GlobalVariable::LinkOnceODRLinkage : + llvm::Function::InternalLinkage; } } @@ -1111,20 +1125,23 @@ CodeGenModule::getVTableLinkage(const CXXRecordDecl *RD) { case TSK_Undeclared: case TSK_ExplicitSpecialization: case TSK_ImplicitInstantiation: - return llvm::GlobalVariable::LinkOnceODRLinkage; - - case TSK_ExplicitInstantiationDefinition: - return llvm::GlobalVariable::WeakODRLinkage; - - case TSK_ExplicitInstantiationDeclaration: // FIXME: Use available_externally linkage. However, this currently // breaks LLVM's build due to undefined symbols. // return llvm::GlobalVariable::AvailableExternallyLinkage; - return llvm::GlobalVariable::LinkOnceODRLinkage; + case TSK_ExplicitInstantiationDeclaration: + break; + + case TSK_ExplicitInstantiationDefinition: + return !Context.getLangOptions().AppleKext ? + llvm::GlobalVariable::WeakODRLinkage : + llvm::Function::InternalLinkage; + } // Silence GCC warning. - return llvm::GlobalVariable::LinkOnceODRLinkage; + return !Context.getLangOptions().AppleKext ? + llvm::GlobalVariable::LinkOnceODRLinkage : + llvm::Function::InternalLinkage; } CharUnits CodeGenModule::GetTargetTypeStoreSize(const llvm::Type *Ty) const { diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index c2fe7d3f4d..e90cf8ddd2 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -1384,8 +1384,13 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, else if (Args.hasArg(OPT_fobjc_gc)) Opts.setGCMode(LangOptions::HybridGC); - if (Args.hasArg(OPT_fapple_kext)) - Opts.AppleKext = 1; + if (Args.hasArg(OPT_fapple_kext)) { + if (!Opts.CPlusPlus) + Diags.Report(diag::warn_c_kext); + else + Opts.AppleKext = 1; + } + if (Args.hasArg(OPT_print_ivar_layout)) Opts.ObjCGCBitmapPrint = 1; if (Args.hasArg(OPT_fno_constant_cfstrings)) diff --git a/test/CodeGenCXX/apple-kext-linkage.C b/test/CodeGenCXX/apple-kext-linkage.C new file mode 100644 index 0000000000..9df1151176 --- /dev/null +++ b/test/CodeGenCXX/apple-kext-linkage.C @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fapple-kext -emit-llvm -o - %s | FileCheck %s + +struct Base { + virtual ~Base(); +} ; + +struct Derived : Base { + void operator delete(void *) { } + Derived(); +}; + +void foo() { + Derived d1; // ok +} + +inline unsigned f(unsigned n) { return n == 0 ? 0 : n + f(n-1); } + +unsigned g(unsigned n) { return f(n); } + + +template X ident(X x) { return x; } +int foo(int n) { return ident(n); } + +// CHECK-NOT: define linkonce_odr +// CHECK 5 : define internal -- 2.40.0