Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Feb 2018 17:05:50 +0000 (UTC)
From:      Dimitry Andric <dim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r329223 - head/contrib/llvm/tools/clang/lib/Sema
Message-ID:  <201802131705.w1DH5o6J082178@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dim
Date: Tue Feb 13 17:05:50 2018
New Revision: 329223
URL: https://svnweb.freebsd.org/changeset/base/329223

Log:
  Pull in r323998 from upstream clang trunk (by Richard Smith):
  
    PR36157: When injecting an implicit function declaration in C89, find
    the right DeclContext rather than injecting it wherever we happen to
    be.
  
    This avoids creating functions whose DeclContext is a struct or
    similar.
  
  This fixes assertion failures when parsing certain not-completely-valid
  struct declarations.
  
  Reported by:	ae
  PR:		225862
  MFC after:	3 months
  X-MFC-With:	r327952

Modified:
  head/contrib/llvm/tools/clang/lib/Sema/SemaDecl.cpp

Modified: head/contrib/llvm/tools/clang/lib/Sema/SemaDecl.cpp
==============================================================================
--- head/contrib/llvm/tools/clang/lib/Sema/SemaDecl.cpp	Tue Feb 13 17:04:34 2018	(r329222)
+++ head/contrib/llvm/tools/clang/lib/Sema/SemaDecl.cpp	Tue Feb 13 17:05:50 2018	(r329223)
@@ -12507,9 +12507,19 @@ void Sema::ActOnFinishDelayedAttribute(Scope *S, Decl 
 /// call, forming a call to an implicitly defined function (per C99 6.5.1p2).
 NamedDecl *Sema::ImplicitlyDefineFunction(SourceLocation Loc,
                                           IdentifierInfo &II, Scope *S) {
+  // Find the scope in which the identifier is injected and the corresponding
+  // DeclContext.
+  // FIXME: C89 does not say what happens if there is no enclosing block scope.
+  // In that case, we inject the declaration into the translation unit scope
+  // instead.
   Scope *BlockScope = S;
   while (!BlockScope->isCompoundStmtScope() && BlockScope->getParent())
     BlockScope = BlockScope->getParent();
+
+  Scope *ContextScope = BlockScope;
+  while (!ContextScope->getEntity())
+    ContextScope = ContextScope->getParent();
+  ContextRAII SavedContext(*this, ContextScope->getEntity());
 
   // Before we produce a declaration for an implicitly defined
   // function, see whether there was a locally-scoped declaration of



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802131705.w1DH5o6J082178>