[PATCH] D38208: Add support for remembering origins to ExternalASTMerger

Sean Callanan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 25 05:04:17 PDT 2017


spyffe created this revision.
spyffe added a project: clang.

At @bruno 's request, recreating this with cfe-commits as a subscriber.  The original is https://reviews.llvm.org/D36589

`ExternalASTMerger` has hitherto relied on being able to look up any Decl through its named `DeclContext` chain.  This works for many cases, but causes problems for function-local structs, which cannot be looked up in their containing `FunctionDecl`.  An example case is

  void f() {
    { struct S { int a; }; }
    { struct S { bool b; }; }
  }

It is not possible to lookup either of the two `S`es individually (or even to provide enough information to disambiguate) after parsing is over; and there is typically no need to, since they are invisible to the outside world.

However, ExternalASTMerger needs to be able to complete either S on demand.  This led to an `XFAIL` on test/Import/local-struct, which this patch removes.  The way the patch works is:

- It defines a new data structure, `ExternalASTMerger::OriginMap`, which clients are expected to maintain (default-constructing if the origin does not have an `ExternalASTMerger` servicing it)
- As `DeclContext`s are imported, if they cannot be looked up by name they are placed in the `OriginMap`.  This allows `ExternalASTMerger` to complete them later if necessary.
- As `DeclContext`s are imported from an origin that already has its own `OriginMap`, the origins are forwarded – but only for those `DeclContext`s that are actually used.  This keeps the amount of stored data minimal.


Repository:
  rL LLVM

https://reviews.llvm.org/D38208

Files:
  include/clang/AST/ExternalASTMerger.h
  lib/AST/ExternalASTMerger.cpp
  lib/Sema/SemaType.cpp
  test/Import/extern-c-function/Inputs/F.cpp
  test/Import/extern-c-function/test.cpp
  test/Import/forward-declared-objc-class/Inputs/S1.m
  test/Import/forward-declared-objc-class/Inputs/S2.m
  test/Import/forward-declared-objc-class/Inputs/S3.m
  test/Import/forward-declared-objc-class/test.m
  test/Import/forward-declared-struct/Inputs/S3.c
  test/Import/forward-declared-struct/test.c
  test/Import/local-struct-use-origins/Inputs/Callee.cpp
  test/Import/local-struct-use-origins/test.cpp
  test/Import/local-struct/test.cpp
  test/Import/objc-definitions-in-expression/Inputs/S.m
  test/Import/objc-definitions-in-expression/test.m
  test/Import/struct-and-var/Inputs/S1.cpp
  test/Import/struct-and-var/Inputs/S2.cpp
  test/Import/struct-and-var/test.cpp
  test/Import/template/Inputs/T.cpp
  test/Import/template/test.cpp
  tools/clang-import-test/clang-import-test.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38208.116441.patch
Type: text/x-patch
Size: 43379 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170925/f0ad55e8/attachment-0001.bin>


More information about the cfe-commits mailing list