diff options
Diffstat (limited to 'clang/lib/AST')
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 12 | ||||
-rw-r--r-- | clang/lib/AST/Decl.cpp | 40 |
2 files changed, 48 insertions, 4 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 5aa4beeb292..3ed2a9ff1cd 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -7732,7 +7732,7 @@ QualType ASTContext::GetBuiltinType(unsigned Id, return getFunctionType(ResType, ArgTypes, EPI); } -GVALinkage ASTContext::GetGVALinkageForFunction(const FunctionDecl *FD) { +GVALinkage ASTContext::GetGVALinkageForFunction(const FunctionDecl *FD) const { if (!FD->isExternallyVisible()) return GVA_Internal; @@ -7744,7 +7744,7 @@ GVALinkage ASTContext::GetGVALinkageForFunction(const FunctionDecl *FD) { break; case TSK_ExplicitInstantiationDefinition: - return GVA_ExplicitTemplateInstantiation; + return GVA_StrongODR; case TSK_ExplicitInstantiationDeclaration: case TSK_ImplicitInstantiation: @@ -7776,6 +7776,12 @@ GVALinkage ASTContext::GetGVALinkageForFunction(const FunctionDecl *FD) { == TSK_ExplicitInstantiationDeclaration) return GVA_C99Inline; + // Functions specified with extern and inline in -fms-compatibility mode + // forcibly get emitted. While the body of the function cannot be later + // replaced, the function definition cannot be discarded. + if (FD->getMostRecentDecl()->isMSExternInline()) + return GVA_StrongODR; + return GVA_CXXInline; } @@ -7793,7 +7799,7 @@ GVALinkage ASTContext::GetGVALinkageForVariable(const VarDecl *VD) { // Fall through to treat this like any other instantiation. case TSK_ExplicitInstantiationDefinition: - return GVA_ExplicitTemplateInstantiation; + return GVA_StrongODR; case TSK_ImplicitInstantiation: return GVA_TemplateInstantiation; diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 83cbb44f7f9..13681ddf559 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -2546,6 +2546,37 @@ unsigned FunctionDecl::getMinRequiredArguments() const { return NumRequiredArgs; } +/// \brief The combination of the extern and inline keywords under MSVC forces +/// the function to be required. +/// +/// Note: This function assumes that we will only get called when isInlined() +/// would return true for this FunctionDecl. +bool FunctionDecl::isMSExternInline() const { + assert(isInlined() && "expected to get called on an inlined function!"); + + const ASTContext &Context = getASTContext(); + if (!Context.getLangOpts().MSVCCompat) + return false; + + for (const FunctionDecl *FD = this; FD; FD = FD->getPreviousDecl()) + if (FD->getStorageClass() == SC_Extern) + return true; + + return false; +} + +static bool redeclForcesDefMSVC(const FunctionDecl *Redecl) { + if (Redecl->getStorageClass() != SC_Extern) + return false; + + for (const FunctionDecl *FD = Redecl->getPreviousDecl(); FD; + FD = FD->getPreviousDecl()) + if (FD->getStorageClass() == SC_Extern) + return false; + + return true; +} + static bool RedeclForcesDefC99(const FunctionDecl *Redecl) { // Only consider file-scope declarations in this test. if (!Redecl->getLexicalDeclContext()->isTranslationUnit()) @@ -2565,7 +2596,7 @@ static bool RedeclForcesDefC99(const FunctionDecl *Redecl) { /// \brief For a function declaration in C or C++, determine whether this /// declaration causes the definition to be externally visible. /// -/// Specifically, this determines if adding the current declaration to the set +/// For instance, this determines if adding the current declaration to the set /// of redeclarations of the given functions causes /// isInlineDefinitionExternallyVisible to change from false to true. bool FunctionDecl::doesDeclarationForceExternallyVisibleDefinition() const { @@ -2574,6 +2605,13 @@ bool FunctionDecl::doesDeclarationForceExternallyVisibleDefinition() const { ASTContext &Context = getASTContext(); + if (Context.getLangOpts().MSVCCompat) { + const FunctionDecl *Definition; + if (hasBody(Definition) && Definition->isInlined() && + redeclForcesDefMSVC(this)) + return true; + } + if (Context.getLangOpts().GNUInline || hasAttr<GNUInlineAttr>()) { // With GNU inlining, a declaration with 'inline' but not 'extern', forces // an externally visible definition. |