[llvm-branch-commits] [cfe-branch] r324215 - Merging r323935:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Feb 5 01:29:08 PST 2018


Author: hans
Date: Mon Feb  5 01:29:08 2018
New Revision: 324215

URL: http://llvm.org/viewvc/llvm-project?rev=324215&view=rev
Log:
Merging r323935:
------------------------------------------------------------------------
r323935 | rsmith | 2018-02-01 01:28:36 +0100 (Thu, 01 Feb 2018) | 5 lines

PR36181: Teach CodeGen to properly ignore requests to emit dependent entities.

Previously, friend function definitions within class templates slipped through
the gaps and caused the MS mangler to assert.

------------------------------------------------------------------------

Added:
    cfe/branches/release_60/test/CodeGenCXX/microsoft-abi-emit-dependent.cpp
      - copied unchanged from r323935, cfe/trunk/test/CodeGenCXX/microsoft-abi-emit-dependent.cpp
Modified:
    cfe/branches/release_60/   (props changed)
    cfe/branches/release_60/include/clang/AST/DeclBase.h
    cfe/branches/release_60/lib/AST/DeclBase.cpp
    cfe/branches/release_60/lib/CodeGen/CodeGenModule.cpp

Propchange: cfe/branches/release_60/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Feb  5 01:29:08 2018
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:321754,321771,321777,321779,321933,322018,322236,322245-322246,322350,322390,322405,322420,322518,322593,322813,322901,322904,322984,323008,323123,323155,323360,323485,324134
+/cfe/trunk:321754,321771,321777,321779,321933,322018,322236,322245-322246,322350,322390,322405,322420,322518,322593,322813,322901,322904,322984,323008,323123,323155,323360,323485,323935,324134
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_60/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_60/include/clang/AST/DeclBase.h?rev=324215&r1=324214&r2=324215&view=diff
==============================================================================
--- cfe/branches/release_60/include/clang/AST/DeclBase.h (original)
+++ cfe/branches/release_60/include/clang/AST/DeclBase.h Mon Feb  5 01:29:08 2018
@@ -836,6 +836,10 @@ public:
 
   void setLexicalDeclContext(DeclContext *DC);
 
+  /// Determine whether this declaration is a templated entity (whether it is
+  // within the scope of a template parameter).
+  bool isTemplated() const;
+
   /// isDefinedOutsideFunctionOrMethod - This predicate returns true if this
   /// scoped decl is defined outside the current function or method.  This is
   /// roughly global variables and functions, but also handles enums (which

Modified: cfe/branches/release_60/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_60/lib/AST/DeclBase.cpp?rev=324215&r1=324214&r2=324215&view=diff
==============================================================================
--- cfe/branches/release_60/lib/AST/DeclBase.cpp (original)
+++ cfe/branches/release_60/lib/AST/DeclBase.cpp Mon Feb  5 01:29:08 2018
@@ -236,10 +236,23 @@ TemplateDecl *Decl::getDescribedTemplate
     return RD->getDescribedClassTemplate();
   else if (auto *VD = dyn_cast<VarDecl>(this))
     return VD->getDescribedVarTemplate();
+  else if (auto *AD = dyn_cast<TypeAliasDecl>(this))
+    return AD->getDescribedAliasTemplate();
 
   return nullptr;
 }
 
+bool Decl::isTemplated() const {
+  // A declaration is dependent if it is a template or a template pattern, or
+  // is within (lexcially for a friend, semantically otherwise) a dependent
+  // context.
+  // FIXME: Should local extern declarations be treated like friends?
+  if (auto *AsDC = dyn_cast<DeclContext>(this))
+    return AsDC->isDependentContext();
+  auto *DC = getFriendObjectKind() ? getLexicalDeclContext() : getDeclContext();
+  return DC->isDependentContext() || isTemplateDecl() || getDescribedTemplate();
+}
+
 const DeclContext *Decl::getParentFunctionOrMethod() const {
   for (const DeclContext *DC = getDeclContext();
        DC && !DC->isTranslationUnit() && !DC->isNamespace(); 

Modified: cfe/branches/release_60/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_60/lib/CodeGen/CodeGenModule.cpp?rev=324215&r1=324214&r2=324215&view=diff
==============================================================================
--- cfe/branches/release_60/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/branches/release_60/lib/CodeGen/CodeGenModule.cpp Mon Feb  5 01:29:08 2018
@@ -4000,18 +4000,13 @@ void CodeGenModule::EmitDeclContext(cons
 /// EmitTopLevelDecl - Emit code for a single top level declaration.
 void CodeGenModule::EmitTopLevelDecl(Decl *D) {
   // Ignore dependent declarations.
-  if (D->getDeclContext() && D->getDeclContext()->isDependentContext())
+  if (D->isTemplated())
     return;
 
   switch (D->getKind()) {
   case Decl::CXXConversion:
   case Decl::CXXMethod:
   case Decl::Function:
-    // Skip function templates
-    if (cast<FunctionDecl>(D)->getDescribedFunctionTemplate() ||
-        cast<FunctionDecl>(D)->isLateTemplateParsed())
-      return;
-
     EmitGlobal(cast<FunctionDecl>(D));
     // Always provide some coverage mapping
     // even for the functions that aren't emitted.
@@ -4024,10 +4019,6 @@ void CodeGenModule::EmitTopLevelDecl(Dec
 
   case Decl::Var:
   case Decl::Decomposition:
-    // Skip variable templates
-    if (cast<VarDecl>(D)->getDescribedVarTemplate())
-      return;
-    LLVM_FALLTHROUGH;
   case Decl::VarTemplateSpecialization:
     EmitGlobal(cast<VarDecl>(D));
     if (auto *DD = dyn_cast<DecompositionDecl>(D))
@@ -4086,16 +4077,9 @@ void CodeGenModule::EmitTopLevelDecl(Dec
       DI->EmitUsingDirective(cast<UsingDirectiveDecl>(*D));
     return;
   case Decl::CXXConstructor:
-    // Skip function templates
-    if (cast<FunctionDecl>(D)->getDescribedFunctionTemplate() ||
-        cast<FunctionDecl>(D)->isLateTemplateParsed())
-      return;
-
     getCXXABI().EmitCXXConstructors(cast<CXXConstructorDecl>(D));
     break;
   case Decl::CXXDestructor:
-    if (cast<FunctionDecl>(D)->isLateTemplateParsed())
-      return;
     getCXXABI().EmitCXXDestructors(cast<CXXDestructorDecl>(D));
     break;
 




More information about the llvm-branch-commits mailing list