<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 16 May 2018 at 06:57, Erich Keane via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: erichkeane<br>
Date: Wed May 16 06:57:17 2018<br>
New Revision: 332470<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=332470&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=332470&view=rev</a><br>
Log:<br>
Add support for __declspec(code_seg("segname")<wbr>)<br>
<br>
Add support for __declspec(code_seg("segname")<wbr>)<br>
<br>
This patch is built on the existing support for #pragma code_seg. The code_seg<br>
declspec is allowed on functions and classes. The attribute enables the<br>
placement of code into separate named segments, including compiler-generated<br>
members and template instantiations.<br>
<br>
For more information, please see the following:<br>
<a href="https://msdn.microsoft.com/en-us/library/dn636922.aspx" rel="noreferrer" target="_blank">https://msdn.microsoft.com/en-<wbr>us/library/dn636922.aspx</a><br>
<br>
A new CodeSeg attribute is used instead of adding a new spelling to the existing<br>
Section attribute since they don’t apply to the same Subjects. Section<br>
attributes are also added for the code_seg declspec since they are used for<br>
#pragma code_seg. No CodeSeg attributes are added to the AST.<br></blockquote><div><br></div><div>This approach really doesn't work. You're incorrectly applying the __declspec(code_seg) restrictions to __attribute__((section)), regressing our support for the latter. Also, code_seg has fundamentally different semantics from the section attribute -- the former exists in part to support paged addressing (which is why it has the virtual function restriction) and the latter exists merely to control properties of the object file. This approach also violates our policy of maintaining source fidelity.</div><div><br></div><div>I'm going to revert this for now to fix the regression; when it comes back, I think you should just use CodeSegAttr to represent __declspec(code_seg) rather than trying to treat it as -- effectively -- a different spelling of SectionAttr.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The patch is written to match with the Microsoft compiler’s behavior even where<br>
that behavior is a little complicated (see <a href="https://reviews.llvm.org/D22931" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D22931</a>, the<br>
Microsoft feedback page is no longer available since MS has removed the page).<br>
That code is in getImplicitSectionAttrFromClas<wbr>s routine.<br>
<br>
Diagnostics messages are added to match with the Microsoft compiler for code-seg<br>
attribute mismatches on base and derived classes and virtual overrides.<br>
<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D43352" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D43352</a><br>
<br>
Modified:<br>
    cfe/trunk/include/clang/Basic/<wbr>Attr.td<br>
    cfe/trunk/include/clang/Basic/<wbr>AttrDocs.td<br>
    cfe/trunk/include/clang/Basic/<wbr>DiagnosticSemaKinds.td<br>
    cfe/trunk/include/clang/Sema/<wbr>Sema.h<br>
    cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp<br>
    cfe/trunk/lib/Sema/<wbr>SemaDeclAttr.cpp<br>
    cfe/trunk/lib/Sema/<wbr>SemaDeclCXX.cpp<br>
    cfe/trunk/lib/Sema/SemaLambda.<wbr>cpp<br>
<br>
Modified: cfe/trunk/include/clang/Basic/<wbr>Attr.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=332470&r1=332469&r2=332470&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/Basic/Attr.td?rev=<wbr>332470&r1=332469&r2=332470&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/Basic/<wbr>Attr.td (original)<br>
+++ cfe/trunk/include/clang/Basic/<wbr>Attr.td Wed May 16 06:57:17 2018<br>
@@ -1769,6 +1769,13 @@ def Section : InheritableAttr {<br>
   let Documentation = [SectionDocs];<br>
 }<br>
<br>
+def CodeSeg : InheritableAttr {<br>
+  let Spellings = [Declspec<"code_seg">];<br>
+  let Args = [StringArgument<"Name">];<br>
+  let Subjects = SubjectList<[Function, CXXRecord], ErrorDiag>;<br>
+  let Documentation = [CodeSegDocs];<br>
+}<br>
+<br>
 def PragmaClangBSSSection : InheritableAttr {<br>
   // This attribute has no spellings as it is only ever created implicitly.<br>
   let Spellings = [];<br>
<br>
Modified: cfe/trunk/include/clang/Basic/<wbr>AttrDocs.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=332470&r1=332469&r2=332470&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/Basic/AttrDocs.td?rev=<wbr>332470&r1=332469&r2=332470&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/Basic/<wbr>AttrDocs.td (original)<br>
+++ cfe/trunk/include/clang/Basic/<wbr>AttrDocs.td Wed May 16 06:57:17 2018<br>
@@ -306,6 +306,18 @@ An example of how to use ``alloc_size``<br>
   }];<br>
 }<br>
<br>
+def CodeSegDocs : Documentation {<br>
+  let Category = DocCatFunction;<br>
+  let Content = [{<br>
+The ``__declspec(code_seg)`` attribute enables the placement of code into separate<br>
+named segments that can be paged or locked in memory individually. This attribute<br>
+is used to control the placement of instantiated templates and compiler-generated<br>
+code. See the documentation for `__declspec(code_seg)`_ on MSDN.<br>
+<br>
+.. _`__declspec(code_seg)`: <a href="http://msdn.microsoft.com/en-us/library/dn636922.aspx" rel="noreferrer" target="_blank">http://msdn.microsoft.com/en-<wbr>us/library/dn636922.aspx</a><br>
+  }];<br>
+}<br>
+<br>
 def AllocAlignDocs : Documentation {<br>
   let Category = DocCatFunction;<br>
   let Content = [{<br>
<br>
Modified: cfe/trunk/include/clang/Basic/<wbr>DiagnosticSemaKinds.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=332470&r1=332469&r2=332470&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/Basic/<wbr>DiagnosticSemaKinds.td?rev=<wbr>332470&r1=332469&r2=332470&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/Basic/<wbr>DiagnosticSemaKinds.td (original)<br>
+++ cfe/trunk/include/clang/Basic/<wbr>DiagnosticSemaKinds.td Wed May 16 06:57:17 2018<br>
@@ -2668,6 +2668,14 @@ def warn_mismatched_section : Warning<<br>
 def warn_attribute_section_on_<wbr>redeclaration : Warning<<br>
   "section attribute is specified on redeclared variable">, InGroup<Section>;<br>
<br>
+def err_mismatched_code_seg_base : Error<<br>
+  "derived class must specify the same code segment as its base classes">;<br>
+def err_mismatched_code_seg_<wbr>override : Error<<br>
+  "overriding virtual function must specify the same code segment as its overridden function">;<br>
+def err_conflicting_codeseg_<wbr>attribute : Error<<br>
+  "conflicting code segment specifiers">;<br>
+def warn_duplicate_codeseg_<wbr>attribute : Warning<<br>
+  "duplicate code segment specifiers">, InGroup<Section>;<br>
 def err_anonymous_property: Error<<br>
   "anonymous property is not supported">;<br>
 def err_property_is_variably_<wbr>modified : Error<<br>
<br>
Modified: cfe/trunk/include/clang/Sema/<wbr>Sema.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=332470&r1=332469&r2=332470&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/Sema/Sema.h?rev=332470&<wbr>r1=332469&r2=332470&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/Sema/<wbr>Sema.h (original)<br>
+++ cfe/trunk/include/clang/Sema/<wbr>Sema.h Wed May 16 06:57:17 2018<br>
@@ -1934,6 +1934,7 @@ public:<br>
   bool shouldLinkDependentDeclWithPre<wbr>vious(Decl *D, Decl *OldDecl);<br>
   void CheckMain(FunctionDecl *FD, const DeclSpec &D);<br>
   void CheckMSVCRTEntryPoint(<wbr>FunctionDecl *FD);<br>
+  Attr *<wbr>getImplicitSectionAttrForFunct<wbr>ion(const FunctionDecl *FD, bool IsDefinition = true);<br>
   Decl *ActOnParamDeclarator(Scope *S, Declarator &D);<br>
   ParmVarDecl *BuildParmVarDeclForTypedef(<wbr>DeclContext *DC,<br>
                                           SourceLocation Loc,<br>
@@ -5836,6 +5837,7 @@ public:<br>
   /// ensure that referenceDLLExportedClassMetho<wbr>ds is called some point later<br>
   /// when all outer classes of Class are complete.<br>
   void checkClassLevelDLLAttribute(<wbr>CXXRecordDecl *Class);<br>
+  void checkClassLevelSectionAttribut<wbr>e(CXXRecordDecl *Class);<br>
<br>
   void referenceDLLExportedClassMetho<wbr>ds();<br>
<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=332470&r1=332469&r2=332470&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaDecl.cpp?rev=332470&r1=<wbr>332469&r2=332470&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp Wed May 16 06:57:17 2018<br>
@@ -2667,9 +2667,14 @@ void Sema::mergeDeclAttributes(<wbr>NamedDecl<br>
         Diag(New->getLocation(), diag::warn_attribute_section_<wbr>on_redeclaration);<br>
         Diag(Old->getLocation(), diag::note_previous_<wbr>declaration);<br>
       }<br>
+    } else if (isa<CXXMethodDecl>(New)) {<br>
+      const auto *NewSA = New->getAttr<SectionAttr>();<br>
+      if (!NewSA->isImplicit()) {<br>
+        Diag(New->getLocation(), diag::warn_mismatched_section)<wbr>;<br>
+        Diag(Old->getLocation(), diag::note_previous_<wbr>declaration);<br>
+      }<br></blockquote><div><br></div><div>This, in particular, results in bogus warnings for __attribute__((section)).</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
     }<br>
   }<br>
-<br>
   if (!Old->hasAttrs())<br>
     return;<br>
<br>
@@ -8716,18 +8721,18 @@ Sema::ActOnFunctionDeclarator(<wbr>Scope *S,<br>
                                                  PragmaClangTextSection.<wbr>PragmaLocation));<br>
   }<br>
<br>
-  // Apply an implicit SectionAttr if #pragma code_seg is active.<br>
-  if (CodeSegStack.CurrentValue && D.isFunctionDefinition() &&<br>
-      !NewFD->hasAttr<SectionAttr>()<wbr>) {<br>
-    NewFD->addAttr(<br>
-        SectionAttr::CreateImplicit(<wbr>Context, SectionAttr::Declspec_<wbr>allocate,<br>
-                                    CodeSegStack.CurrentValue-><wbr>getString(),<br>
-                                    CodeSegStack.<wbr>CurrentPragmaLocation));<br>
-    if (UnifySection(CodeSegStack.<wbr>CurrentValue->getString(),<br>
-                     ASTContext::PSF_Implicit | ASTContext::PSF_Execute |<br>
-                         ASTContext::PSF_Read,<br>
-                     NewFD))<br>
-      NewFD->dropAttr<SectionAttr>()<wbr>;<br>
+  // Apply an implicit SectionAttr from class declspec or from<br>
+  // #pragma code_seg if active.<br>
+  if (!NewFD->hasAttr<SectionAttr>(<wbr>)) {<br>
+    if (Attr *SAttr = getImplicitSectionAttrForFunct<wbr>ion(NewFD,<br>
+                                                        D.isFunctionDefinition())) {<br>
+      NewFD->addAttr(SAttr);<br>
+      if (UnifySection(cast<<wbr>SectionAttr>(SAttr)->getName()<wbr>,<br>
+                       ASTContext::PSF_Implicit | ASTContext::PSF_Execute |<br>
+                       ASTContext::PSF_Read,<br>
+                       NewFD))<br>
+        NewFD->dropAttr<SectionAttr>()<wbr>;<br>
+    }<br>
   }<br>
<br>
   // Handle attributes.<br>
@@ -9177,6 +9182,64 @@ Sema::ActOnFunctionDeclarator(<wbr>Scope *S,<br>
   return NewFD;<br>
 }<br>
<br>
+/// Return a SectionAttr from a containing class.  The Microsoft docs say<br>
+/// when __declspec(code_seg) "is applied to a class, all member functions of<br>
+/// the class and nested classes -- this includes compiler-generated special<br>
+/// member functions -- are put in the specified segment."<br>
+/// The actual behavior is a little more complicated. The Microsoft compiler<br>
+/// won't check outer classes if there is an active value from #pragma code_seg.<br>
+/// The section is always applied from the direct parent but only from outer<br>
+/// classes when the #pragma code_seg stack is empty. See:<br>
+/// <a href="https://reviews.llvm.org/D22931" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D22931</a>, the Microsoft feedback page is no longer<br>
+/// available since MS has removed the page.<br>
+static Attr *<wbr>getImplicitSectionAttrFromClas<wbr>s(Sema &S, const FunctionDecl *FD) {<br>
+  const auto *Method = dyn_cast<CXXMethodDecl>(FD);<br>
+  if (!Method)<br>
+    return nullptr;<br>
+  const CXXRecordDecl *Parent = Method->getParent();<br>
+  if (const auto *SAttr = Parent->getAttr<SectionAttr>()<wbr>) {<br>
+    Attr *NewAttr = SAttr->clone(S.getASTContext()<wbr>);<br>
+    NewAttr->setImplicit(true);<br>
+    return NewAttr;<br>
+  }<br>
+<br>
+  // The Microsoft compiler won't check outer classes for the section<br>
+  // when the #pragma code_seg stack is active.<br>
+  if (S.CodeSegStack.CurrentValue)<br>
+    return nullptr;<br>
+<br>
+  while ((Parent = dyn_cast<CXXRecordDecl>(<wbr>Parent->getParent()))) {<br>
+    if (const auto *SAttr = Parent->getAttr<SectionAttr>()<wbr>) {<br>
+      Attr *NewAttr = SAttr->clone(S.getASTContext()<wbr>);<br>
+      NewAttr->setImplicit(true);<br>
+      return NewAttr;<br>
+    }<br>
+  }<br>
+  return nullptr;<br>
+}<br>
+<br>
+/// \brief Returns an implicit SectionAttr for a function.<br>
+///<br>
+/// \param FD Function being declared.<br>
+/// \param IsDefinition Whether it is a definition or just a declarartion.<br>
+/// \returns A SectionAttr to apply to the function or nullptr if no<br>
+///          attribute should be added.<br>
+///<br>
+/// First tries to find a SectionAttr on a containing class (from<br>
+/// a __declspec(code_seg)).  If not found on the class, and if the function is<br>
+/// also a definition it will use the current #pragma code_seg value.<br>
+Attr *Sema::<wbr>getImplicitSectionAttrForFunct<wbr>ion(const FunctionDecl *FD, bool IsDefinition) {<br>
+  if (Attr *A = getImplicitSectionAttrFromClas<wbr>s(*this, FD))<br>
+    return A;<br>
+  if (IsDefinition && CodeSegStack.CurrentValue) {<br>
+    return SectionAttr::CreateImplicit(<wbr>getASTContext(),<br>
+                                       SectionAttr::Declspec_<wbr>allocate,<br>
+                                       CodeSegStack.CurrentValue-><wbr>getString(),<br>
+                                       CodeSegStack.<wbr>CurrentPragmaLocation);<br>
+  }<br>
+  return nullptr;<br>
+}<br>
+<br>
 /// Checks if the new declaration declared in dependent context must be<br>
 /// put in the same redeclaration chain as the specified declaration.<br>
 ///<br>
<br>
Modified: cfe/trunk/lib/Sema/<wbr>SemaDeclAttr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=332470&r1=332469&r2=332470&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaDeclAttr.cpp?rev=332470&<wbr>r1=332469&r2=332470&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/<wbr>SemaDeclAttr.cpp (original)<br>
+++ cfe/trunk/lib/Sema/<wbr>SemaDeclAttr.cpp Wed May 16 06:57:17 2018<br>
@@ -2853,6 +2853,13 @@ static void handleVecTypeHint(Sema &S, D<br>
 SectionAttr *Sema::mergeSectionAttr(Decl *D, SourceRange Range,<br>
                                     StringRef Name,<br>
                                     unsigned AttrSpellingListIndex) {<br>
+  // Explicit or partial specializations do not inherit<br>
+  // the code_seg attribute from the primary template.<br>
+  if (const auto *FD = dyn_cast<FunctionDecl>(D)){<br>
+    if (FD-><wbr>isFunctionTemplateSpecializati<wbr>on())<br>
+      return nullptr;<br>
+  }<br>
+<br>
   if (SectionAttr *ExistingAttr = D->getAttr<SectionAttr>()) {<br>
     if (ExistingAttr->getName() == Name)<br>
       return nullptr;<br>
@@ -2942,6 +2949,27 @@ static void handleTargetAttr(Sema &S, De<br>
   D->addAttr(NewAttr);<br>
 }<br>
<br>
+static void handleCodeSegAttr(Sema &S, Decl *D, const AttributeList &AL) {<br>
+  StringRef Str;<br>
+  SourceLocation LiteralLoc;<br>
+  if (!S.<wbr>checkStringLiteralArgumentAttr<wbr>(AL, 0, Str, &LiteralLoc))<br>
+    return;<br>
+  if (!S.checkSectionName(<wbr>LiteralLoc, Str))<br>
+    return;<br>
+  if (const auto *ExistingAttr = D->getAttr<SectionAttr>()) {<br>
+    if (!ExistingAttr->isImplicit()) {<br>
+      S.Diag(AL.getLoc(), <br>
+             ExistingAttr->getName() == Str <br>
+             ? diag::warn_duplicate_codeseg_<wbr>attribute<br>
+             : diag::err_conflicting_codeseg_<wbr>attribute);           <br>
+      return;<br>
+    }<br>
+    D->dropAttr<SectionAttr>();<br>
+  }<br>
+  D->addAttr(::new (S.Context) SectionAttr(<br>
+      AL.getRange(), S.Context, Str, AL.<wbr>getAttributeSpellingListIndex(<wbr>)));<br>
+}<br>
+<br>
 static void handleCleanupAttr(Sema &S, Decl *D, const AttributeList &AL) {<br>
   Expr *E = AL.getArgAsExpr(0);<br>
   SourceLocation Loc = E->getExprLoc();<br>
@@ -6297,6 +6325,9 @@ static void ProcessDeclAttribute(Sema &S<br>
   case AttributeList::AT_Uuid:<br>
     handleUuidAttr(S, D, AL);<br>
     break;<br>
+  case AttributeList::AT_CodeSeg:<br>
+    handleCodeSegAttr(S, D, AL);<br>
+    break;<br>
   case AttributeList::AT_<wbr>MSInheritance:<br>
     handleMSInheritanceAttr(S, D, AL);<br>
     break;<br>
<br>
Modified: cfe/trunk/lib/Sema/<wbr>SemaDeclCXX.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=332470&r1=332469&r2=332470&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaDeclCXX.cpp?rev=332470&r1=<wbr>332469&r2=332470&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/<wbr>SemaDeclCXX.cpp (original)<br>
+++ cfe/trunk/lib/Sema/<wbr>SemaDeclCXX.cpp Wed May 16 06:57:17 2018<br>
@@ -2231,6 +2231,20 @@ Sema::CheckBaseSpecifier(<wbr>CXXRecordDecl *<br>
   CXXRecordDecl *CXXBaseDecl = cast<CXXRecordDecl>(BaseDecl);<br>
   assert(CXXBaseDecl && "Base type is not a C++ type");<br>
<br>
+  // Microsoft docs say:<br>
+  // "If a base-class has a code_seg attribute, derived classes must have the<br>
+  // same attribute."<br>
+   const auto *BaseSA = CXXBaseDecl->getAttr<<wbr>SectionAttr>();<br>
+   const auto *DerivedSA = Class->getAttr<SectionAttr>();<br>
+   if (BaseSA || DerivedSA) {<br>
+     if (!BaseSA || !DerivedSA || BaseSA->getName() != DerivedSA->getName()) {<br>
+       Diag(Class->getLocation(), diag::err_mismatched_code_seg_<wbr>base);<br>
+       Diag(CXXBaseDecl->getLocation(<wbr>), diag::note_base_class_<wbr>specified_here)<br>
+         << CXXBaseDecl;<br>
+       return nullptr;<br>
+     }<br>
+   }<br>
+<br>
   // A class which contains a flexible array member is not suitable for use as a<br>
   // base class:<br>
   //   - If the layout determines that a base comes before another base,<br>
@@ -5576,6 +5590,16 @@ static void checkForMultipleExportedDefa<br>
   }<br>
 }<br>
<br>
+void Sema::<wbr>checkClassLevelSectionAttribut<wbr>e(CXXRecordDecl *Class) {<br>
+  // Mark any compiler-generated routines with the implicit Section attribute.<br>
+  for (auto *Method : Class->methods()) {<br>
+    if (Method->isUserProvided())<br>
+      continue;<br>
+    if (Attr *A = getImplicitSectionAttrForFunct<wbr>ion(Method))<br>
+      Method->addAttr(A);<br>
+  }<br>
+}<br>
+<br>
 /// Check class-level dllimport/dllexport attribute.<br>
 void Sema::<wbr>checkClassLevelDLLAttribute(<wbr>CXXRecordDecl *Class) {<br>
   Attr *ClassAttr = getDLLAttr(Class);<br>
@@ -6079,6 +6103,7 @@ void Sema::CheckCompletedCXXClass(<wbr>CXXRec<br>
   }<br>
<br>
   checkClassLevelDLLAttribute(<wbr>Record);<br>
+  checkClassLevelSectionAttribut<wbr>e(Record);<br>
<br>
   bool ClangABICompat4 =<br>
       Context.getLangOpts().<wbr>getClangABICompat() <= LangOptions::ClangABI::Ver4;<br>
@@ -14531,6 +14556,16 @@ bool Sema::<wbr>CheckOverridingFunctionAttrib<br>
              diag::note_overridden_marked_<wbr>noescape);<br>
       }<br>
   }<br>
+  // Virtual overrides must have the same code_seg.<br>
+  const auto *OldSA = Old->getAttr<SectionAttr>();<br>
+  const auto *NewSA = New->getAttr<SectionAttr>();<br>
+  if (OldSA || NewSA) {<br>
+    if (!OldSA || !NewSA || NewSA->getName() != OldSA->getName()) {<br>
+      Diag(New->getLocation(), diag::err_mismatched_code_seg_<wbr>override);<br>
+      Diag(Old->getLocation(), diag::note_previous_<wbr>declaration);<br>
+      return true;<br>
+    }<br>
+  }<br>
<br>
   CallingConv NewCC = NewFT->getCallConv(), OldCC = OldFT->getCallConv();<br>
<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaLambda.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLambda.cpp?rev=332470&r1=332469&r2=332470&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaLambda.cpp?rev=332470&r1=<wbr>332469&r2=332470&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/SemaLambda.<wbr>cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaLambda.<wbr>cpp Wed May 16 06:57:17 2018<br>
@@ -910,6 +910,10 @@ void Sema::<wbr>ActOnStartOfLambdaDefinition(<br>
   AddRangeBasedOptnone(Method);<br>
<br>
   // Attributes on the lambda apply to the method.  <br>
+  if (Attr *A = getImplicitSectionAttrForFunct<wbr>ion(Method))<br>
+    Method->addAttr(A);<br>
+  <br>
+  // Attributes on the lambda apply to the method.<br>
   ProcessDeclAttributes(<wbr>CurScope, Method, ParamInfo);<br>
<br>
   // CUDA lambdas get implicit attributes based on the scope in which they're<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>