[llvm-branch-commits] [cfe-branch] r311105 - Merging r310776:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Aug 17 10:26:33 PDT 2017


Author: hans
Date: Thu Aug 17 10:26:33 2017
New Revision: 311105

URL: http://llvm.org/viewvc/llvm-project?rev=311105&view=rev
Log:
Merging r310776:
------------------------------------------------------------------------
r310776 | rsmith | 2017-08-11 18:46:03 -0700 (Fri, 11 Aug 2017) | 8 lines

PR34163: Don't cache an incorrect key function for a class if queried between
the class becoming complete and its inline methods being parsed.

This replaces the hack of using the "late parsed template" flag to track member
functions with bodies we've not parsed yet; instead we now use the "will have
body" flag, which carries the desired implication that the function declaration
*is* a definition, and that we've just not parsed its body yet.

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

Added:
    cfe/branches/release_50/test/CodeGenCXX/pr34163.cpp
      - copied unchanged from r310776, cfe/trunk/test/CodeGenCXX/pr34163.cpp
Modified:
    cfe/branches/release_50/   (props changed)
    cfe/branches/release_50/include/clang/AST/Decl.h
    cfe/branches/release_50/lib/AST/DeclCXX.cpp
    cfe/branches/release_50/lib/Parse/ParseCXXInlineMethods.cpp
    cfe/branches/release_50/lib/Sema/SemaDecl.cpp
    cfe/branches/release_50/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/branches/release_50/test/SemaCUDA/function-overload.cu
    cfe/branches/release_50/test/SemaCUDA/no-destructor-overload.cu

Propchange: cfe/branches/release_50/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Aug 17 10:26:33 2017
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:308455,308722,308824,308897,308996,309054,309058,309112-309113,309226,309263,309327,309382-309383,309488,309503,309523,309569,309607,309633,309636,309640,309722,309752,309975,310006,310158,310191,310359,310516,310672,310691-310692,310694,310700,310704,310706,310804,310829
+/cfe/trunk:308455,308722,308824,308897,308996,309054,309058,309112-309113,309226,309263,309327,309382-309383,309488,309503,309523,309569,309607,309633,309636,309640,309722,309752,309975,310006,310158,310191,310359,310516,310672,310691-310692,310694,310700,310704,310706,310776,310804,310829
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_50/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/include/clang/AST/Decl.h?rev=311105&r1=311104&r2=311105&view=diff
==============================================================================
--- cfe/branches/release_50/include/clang/AST/Decl.h (original)
+++ cfe/branches/release_50/include/clang/AST/Decl.h Thu Aug 17 10:26:33 2017
@@ -1666,8 +1666,7 @@ private:
   unsigned HasSkippedBody : 1;
 
   /// Indicates if the function declaration will have a body, once we're done
-  /// parsing it.  (We don't set it to false when we're done parsing, in the
-  /// hopes this is simpler.)
+  /// parsing it.
   unsigned WillHaveBody : 1;
 
   /// \brief End part of this FunctionDecl's source range.

Modified: cfe/branches/release_50/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/lib/AST/DeclCXX.cpp?rev=311105&r1=311104&r2=311105&view=diff
==============================================================================
--- cfe/branches/release_50/lib/AST/DeclCXX.cpp (original)
+++ cfe/branches/release_50/lib/AST/DeclCXX.cpp Thu Aug 17 10:26:33 2017
@@ -1837,9 +1837,10 @@ bool CXXMethodDecl::hasInlineBody() cons
   const FunctionDecl *CheckFn = getTemplateInstantiationPattern();
   if (!CheckFn)
     CheckFn = this;
-  
+
   const FunctionDecl *fn;
-  return CheckFn->hasBody(fn) && !fn->isOutOfLine();
+  return CheckFn->isDefined(fn) && !fn->isOutOfLine() &&
+         (fn->doesThisDeclarationHaveABody() || fn->willHaveBody());
 }
 
 bool CXXMethodDecl::isLambdaStaticInvoker() const {

Modified: cfe/branches/release_50/lib/Parse/ParseCXXInlineMethods.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/lib/Parse/ParseCXXInlineMethods.cpp?rev=311105&r1=311104&r2=311105&view=diff
==============================================================================
--- cfe/branches/release_50/lib/Parse/ParseCXXInlineMethods.cpp (original)
+++ cfe/branches/release_50/lib/Parse/ParseCXXInlineMethods.cpp Thu Aug 17 10:26:33 2017
@@ -166,20 +166,11 @@ NamedDecl *Parser::ParseCXXInlineMethodD
   }
 
   if (FnD) {
-    // If this is a friend function, mark that it's late-parsed so that
-    // it's still known to be a definition even before we attach the
-    // parsed body.  Sema needs to treat friend function definitions
-    // differently during template instantiation, and it's possible for
-    // the containing class to be instantiated before all its member
-    // function definitions are parsed.
-    //
-    // If you remove this, you can remove the code that clears the flag
-    // after parsing the member.
-    if (D.getDeclSpec().isFriendSpecified()) {
-      FunctionDecl *FD = FnD->getAsFunction();
-      Actions.CheckForFunctionRedefinition(FD);
-      FD->setLateTemplateParsed(true);
-    }
+    FunctionDecl *FD = FnD->getAsFunction();
+    // Track that this function will eventually have a body; Sema needs
+    // to know this.
+    Actions.CheckForFunctionRedefinition(FD);
+    FD->setWillHaveBody(true);
   } else {
     // If semantic analysis could not build a function declaration,
     // just throw away the late-parsed declaration.
@@ -558,10 +549,6 @@ void Parser::ParseLexedMethodDef(LexedMe
 
   ParseFunctionStatementBody(LM.D, FnScope);
 
-  // Clear the late-template-parsed bit if we set it before.
-  if (LM.D)
-    LM.D->getAsFunction()->setLateTemplateParsed(false);
-
   while (Tok.isNot(tok::eof))
     ConsumeAnyToken();
 

Modified: cfe/branches/release_50/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/lib/Sema/SemaDecl.cpp?rev=311105&r1=311104&r2=311105&view=diff
==============================================================================
--- cfe/branches/release_50/lib/Sema/SemaDecl.cpp (original)
+++ cfe/branches/release_50/lib/Sema/SemaDecl.cpp Thu Aug 17 10:26:33 2017
@@ -12090,8 +12090,9 @@ Decl *Sema::ActOnStartOfFunctionDef(Scop
     FD->setInvalidDecl();
   }
 
-  // See if this is a redefinition.
-  if (!FD->isLateTemplateParsed()) {
+  // See if this is a redefinition. If 'will have body' is already set, then
+  // these checks were already performed when it was set.
+  if (!FD->willHaveBody() && !FD->isLateTemplateParsed()) {
     CheckForFunctionRedefinition(FD, nullptr, SkipBody);
 
     // If we're skipping the body, we're done. Don't enter the scope.

Modified: cfe/branches/release_50/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=311105&r1=311104&r2=311105&view=diff
==============================================================================
--- cfe/branches/release_50/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/branches/release_50/lib/Sema/SemaTemplateInstantiateDecl.cpp Thu Aug 17 10:26:33 2017
@@ -3771,6 +3771,8 @@ void Sema::InstantiateFunctionDefinition
   if (PatternDef) {
     Pattern = PatternDef->getBody(PatternDef);
     PatternDecl = PatternDef;
+    if (PatternDef->willHaveBody())
+      PatternDef = nullptr;
   }
 
   // FIXME: We need to track the instantiation stack in order to know which

Modified: cfe/branches/release_50/test/SemaCUDA/function-overload.cu
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/test/SemaCUDA/function-overload.cu?rev=311105&r1=311104&r2=311105&view=diff
==============================================================================
--- cfe/branches/release_50/test/SemaCUDA/function-overload.cu (original)
+++ cfe/branches/release_50/test/SemaCUDA/function-overload.cu Thu Aug 17 10:26:33 2017
@@ -222,7 +222,7 @@ GlobalFnPtr fp_g = g;
 // Test overloading of destructors
 // Can't mix H and unattributed destructors
 struct d_h {
-  ~d_h() {} // expected-note {{previous declaration is here}}
+  ~d_h() {} // expected-note {{previous definition is here}}
   __host__ ~d_h() {} // expected-error {{destructor cannot be redeclared}}
 };
 

Modified: cfe/branches/release_50/test/SemaCUDA/no-destructor-overload.cu
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/test/SemaCUDA/no-destructor-overload.cu?rev=311105&r1=311104&r2=311105&view=diff
==============================================================================
--- cfe/branches/release_50/test/SemaCUDA/no-destructor-overload.cu (original)
+++ cfe/branches/release_50/test/SemaCUDA/no-destructor-overload.cu Thu Aug 17 10:26:33 2017
@@ -7,27 +7,27 @@
 // giant change to clang, and the use cases seem quite limited.
 
 struct A {
-  ~A() {} // expected-note {{previous declaration is here}}
+  ~A() {} // expected-note {{previous definition is here}}
   __device__ ~A() {} // expected-error {{destructor cannot be redeclared}}
 };
 
 struct B {
-  __host__ ~B() {} // expected-note {{previous declaration is here}}
+  __host__ ~B() {} // expected-note {{previous definition is here}}
   __host__ __device__ ~B() {} // expected-error {{destructor cannot be redeclared}}
 };
 
 struct C {
-  __host__ __device__ ~C() {} // expected-note {{previous declaration is here}}
+  __host__ __device__ ~C() {} // expected-note {{previous definition is here}}
   __host__ ~C() {} // expected-error {{destructor cannot be redeclared}}
 };
 
 struct D {
-  __device__ ~D() {} // expected-note {{previous declaration is here}}
+  __device__ ~D() {} // expected-note {{previous definition is here}}
   __host__ __device__ ~D() {} // expected-error {{destructor cannot be redeclared}}
 };
 
 struct E {
-  __host__ __device__ ~E() {} // expected-note {{previous declaration is here}}
+  __host__ __device__ ~E() {} // expected-note {{previous definition is here}}
   __device__ ~E() {} // expected-error {{destructor cannot be redeclared}}
 };
 




More information about the llvm-branch-commits mailing list