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
This commit is contained in:
Dimitry Andric 2018-02-13 17:05:50 +00:00
parent 33ec1ccbae
commit fc9687ba64
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=329223

View File

@ -12507,10 +12507,20 @@ void Sema::ActOnFinishDelayedAttribute(Scope *S, Decl *D,
/// 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
// this name as a function or variable. If so, use that