This is an archive of the discontinued LLVM Phabricator instance.

Use correct semantic DeclContext for local declarations of variables and functions with linkage
ClosedPublic

Authored by rsmith on Aug 23 2013, 4:01 PM.

Details

Summary

This patch switches the semantic DeclContext for a block-scope declaration of a function or variable from being the function to being the enclosing namespace scope (in C++) or the TU (in C). This allows us to fix a selection of related issues where we would build incorrect redeclaration chains for such declarations, and fail to notice type mismatches.

Such declarations are put into a new IdentifierNamespace, IDNS_LocalExtern, which is only found when searching scopes, and not found when searching DeclContexts. Such a declaration is only made visible in its DeclContext if there are no non-LocalExtern declarations.

Diff Detail

Event Timeline

rsmith updated this revision to Unknown Object (????).Aug 23 2013, 6:15 PM

The concept generally seems fine.

The setLocalExternDecl thing seems a bit fiddly, since I'm pretty sure it
can be derived from information we already keep around. Did you consider
computing that information on demand?

Do we compute the correct DeclContext for a friend in a local class which
is a redeclaration of a local extern decl? Might be nice to test.

It looks like some changes slipped in which should be committed separately
(around where you added the reference to 6.2.7p2).

Does you patch work correctly with an extern local decl inside a block?
e.g. "void f() { ^{ void extern_decl(); extern_decl(); }(); }"?

That's all I can think of, at least for now.

rsmith updated this revision to Unknown Object (????).Sep 3 2013, 6:52 PM

Added requested testcases, removed (separately-committed) refactoring.

rsmith accepted this revision.May 30 2014, 12:53 PM
rsmith added a reviewer: rsmith.
This revision is now accepted and ready to land.May 30 2014, 12:53 PM
rsmith closed this revision.May 30 2014, 12:53 PM

This was committed as r191064.