Author: dim
Date: Tue Feb 13 17:05:50 2018
New Revision: 329223

  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
    This avoids creating functions whose DeclContext is a struct or
  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
--- 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
_______________________________________________ mailing list
To unsubscribe, send any mail to ""

Reply via email to