r314336 - Add support for remembering origins to ExternalASTMerger

2017-09-27 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Wed Sep 27 12:57:58 2017
New Revision: 314336

URL: http://llvm.org/viewvc/llvm-project?rev=314336=rev
Log:
Add support for remembering origins to ExternalASTMerger

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 Ses 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 DeclContexts 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 DeclContexts are imported from an origin that already has 
its own OriginMap, the origins are forwarded – but only for 
those DeclContexts that are actually used. This keeps the 
amount of stored data minimal.

The patch also applies several improvements from review:

- Thoroughly documents the interface to ExternalASTMerger;
- Adds optional logging to help track what's going on; and
- Cleans up a bunch of braces and dangling elses.

Differential Revision: https://reviews.llvm.org/D38208

Added:
cfe/trunk/test/Import/extern-c-function/
  - copied from r311017, cfe/trunk/test/Import/overloaded-function/
cfe/trunk/test/Import/extern-c-function/Inputs/F.cpp
  - copied, changed from r311017, 
cfe/trunk/test/Import/overloaded-function/Inputs/F1.c
cfe/trunk/test/Import/extern-c-function/test.cpp
  - copied, changed from r311017, 
cfe/trunk/test/Import/overloaded-function/test.c
cfe/trunk/test/Import/forward-declared-objc-class/
  - copied from r311468, cfe/trunk/test/Import/forward-declared-struct/
cfe/trunk/test/Import/forward-declared-objc-class/Inputs/S1.m
  - copied, changed from r311468, 
cfe/trunk/test/Import/forward-declared-struct/Inputs/S1.c
cfe/trunk/test/Import/forward-declared-objc-class/Inputs/S2.m
  - copied, changed from r311468, 
cfe/trunk/test/Import/forward-declared-struct/Inputs/S2.c
cfe/trunk/test/Import/forward-declared-objc-class/Inputs/S3.m
  - copied, changed from r311468, 
cfe/trunk/test/Import/forward-declared-struct/Inputs/S1.c
cfe/trunk/test/Import/forward-declared-objc-class/test.m
  - copied, changed from r311468, 
cfe/trunk/test/Import/forward-declared-struct/test.c
cfe/trunk/test/Import/forward-declared-struct/Inputs/S3.c
  - copied unchanged from r311468, 
cfe/trunk/test/Import/forward-declared-struct/Inputs/S1.c
cfe/trunk/test/Import/local-struct-use-origins/
  - copied from r310656, cfe/trunk/test/Import/local-struct/
cfe/trunk/test/Import/objc-definitions-in-expression/
  - copied from r311468, cfe/trunk/test/Import/objc-method/
cfe/trunk/test/Import/struct-and-var/
  - copied from r310656, cfe/trunk/test/Import/conflicting-struct/
cfe/trunk/test/Import/template/
  - copied from r310656, cfe/trunk/test/Import/template-specialization/
Removed:
cfe/trunk/test/Import/extern-c-function/Inputs/F1.c
cfe/trunk/test/Import/extern-c-function/Inputs/F2.c
cfe/trunk/test/Import/extern-c-function/test.c
cfe/trunk/test/Import/forward-declared-objc-class/Inputs/S1.c
cfe/trunk/test/Import/forward-declared-objc-class/Inputs/S2.c
cfe/trunk/test/Import/forward-declared-objc-class/test.c
Modified:
cfe/trunk/include/clang/AST/ExternalASTMerger.h
cfe/trunk/lib/AST/ExternalASTMerger.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/Import/forward-declared-struct/test.c
cfe/trunk/test/Import/local-struct-use-origins/test.cpp
cfe/trunk/test/Import/local-struct/test.cpp
cfe/trunk/test/Import/objc-definitions-in-expression/test.m
cfe/trunk/test/Import/struct-and-var/Inputs/S1.cpp
cfe/trunk/test/Import/struct-and-var/Inputs/S2.cpp
cfe/trunk/test/Import/struct-and-var/test.cpp
cfe/trunk/test/Import/template/Inputs/T.cpp
cfe/trunk/test/Import/template/test.cpp
cfe/trunk/tools/clang-import-test/clang-import-test.cpp

Modified: cfe/trunk/include/clang/AST/ExternalASTMerger.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExternalASTMerger.h?rev=314336=314335=314336=diff
==
--- cfe/trunk/include/clang/AST/ExternalASTMerger.h (original)
+++ 

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

2017-09-25 Thread Sean Callanan via cfe-commits
Updated the diff.  Unfortunately reviews.llvm.org is down, so I'll try 
updating that page in the morning.


Sean

On 9/25/17 5:04 AM, Bruno Cardoso Lopes via Phabricator wrote:

bruno added inline comments.



Comment at: lib/AST/ExternalASTMerger.cpp:79
+  return cast(SearchResultDecl)->getPrimaryContext();
+else
+  return nullptr; // This type of lookup is unsupported

No need for `else` here.



Comment at: lib/AST/ExternalASTMerger.cpp:173
+ASTImporter ::ImporterForOrigin(ASTContext ) {
+  for (const std::unique_ptr  : Importers) {
+if (>getFromContext() == )

No need for curly braces here.



Comment at: lib/AST/ExternalASTMerger.cpp:189
+bool ExternalASTMerger::HasImporterForOrigin(ASTContext ) {
+  for (const std::unique_ptr  : Importers) {
+if (>getFromContext() == )

No need for curly braces here.



Comment at: lib/AST/ExternalASTMerger.cpp:289
+  LookupSameContext(Origin.AST->getTranslationUnitDecl(), ToDC, Reverse);
+  if (!FoundFromDC || !IsSameDC(FoundFromDC.get(), Origin.DC)) {
+if (LoggingEnabled())

You can probably simplify this to something like:


```
bool RecordOrigin = !FoundFromDC || !IsSameDC(FoundFromDC.get(), Origin.DC);

if (RecordOrigin)
   RecordOriginImpl(ToDC, Origin, Importer);
   
if (LoggingEnabled()) {

   logs() << "(ExternalASTMerger*)" << (void*)this
  << " decided";
  
   if (!RecordOrigin)

 logs() << " NOT";
 
   logs() << " to record origin (DeclContext*)" << (void*)Origin.DC

  << ", (ASTContext*)" << (void*)
  << "\n";
}
```



Comment at: lib/AST/ExternalASTMerger.cpp:380
+
+  if (Candidates.empty()) {
+return false;

No need for curly braces here.



Comment at: tools/clang-import-test/clang-import-test.cpp:329
  CG.GetModule()->print(llvm::outs(), nullptr);
-  if (CI->getDiagnosticClient().getNumErrors()) {
+  if (CI.getDiagnosticClient().getNumErrors()) {
  return llvm::make_error(

No need for curly braces here


Repository:
   rL LLVM

https://reviews.llvm.org/D38208





Index: include/clang/AST/ExternalASTMerger.h
===
--- include/clang/AST/ExternalASTMerger.h   (revision 313996)
+++ include/clang/AST/ExternalASTMerger.h   (working copy)
@@ -1,51 +1,176 @@
 //===--- ExternalASTMerger.h - Merging External AST Interface ---*- C++ 
-*-===//
 //
 // The LLVM Compiler Infrastructure
 //
 // This file is distributed under the University of Illinois Open Source
 // License. See LICENSE.TXT for details.
 //
 
//===--===//
 //
 //  This file declares the ExternalASTMerger, which vends a combination of ASTs
 //  from several different ASTContext/FileManager pairs
 //
 
//===--===//
 #ifndef LLVM_CLANG_AST_EXTERNALASTMERGER_H
 #define LLVM_CLANG_AST_EXTERNALASTMERGER_H
 
 #include "clang/AST/ASTImporter.h"
 #include "clang/AST/ExternalASTSource.h"
+#include "llvm/Support/raw_ostream.h"
 
 namespace clang {
 
+/// ExternalASTSource implementation that merges information from several
+/// ASTContexts.
+///
+/// ExtermalASTMerger maintains a vector of ASTImporters that it uses to import
+/// (potentially incomplete) Decls and DeclContexts from the source ASTContexts
+/// in response to ExternalASTSource API calls.
+///
+/// When lookup occurs in the resulting imported DeclContexts, the original
+/// DeclContexts need to be queried.  Roughly, there are three cases here:
+///
+/// - The DeclContext of origin can be found by simple name lookup.  In this
+///   case, no additional state is required.
+///
+/// - The DeclContext of origin is different from what would be found by name
+///   lookup.  In this case, Origins contains an entry overriding lookup and
+///   specifying the correct pair of DeclContext/ASTContext.
+///
+/// - The DeclContext of origin was determined by another ExterenalASTMerger. 
+///   (This is possible when the source ASTContext for one of the Importers has
+///   its own ExternalASTMerger).  The origin must be properly forwarded in 
this
+///   case.
+///
+/// ExternalASTMerger's job is to maintain the data structures necessary to
+/// allow this.  The data structures themselves can be extracted (read-only) 
and
+/// copied for re-use.
 class ExternalASTMerger : public ExternalASTSource {
 public:
-  struct ImporterPair {
-std::unique_ptr Forward;
-std::unique_ptr Reverse;
+  /// A single origin for a DeclContext.  Unlike Decls, DeclContexts do
+  /// not allow their containing ASTContext to be determined in all cases.
+  struct DCOrigin {
+DeclContext *DC;
+ASTContext *AST;
   };
 
+  typedef std::map OriginMap;
+  typedef 

r310318 - This adds the argument --dump-ir to clang-import-test, which allows

2017-08-07 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Mon Aug  7 15:27:30 2017
New Revision: 310318

URL: http://llvm.org/viewvc/llvm-project?rev=310318=rev
Log:
This adds the argument --dump-ir to clang-import-test, which allows 
viewing of the final IR. This is useful for confirming that 
structure layout was correct.

I've added two tests:

- A test that checks that structs in top-level code are completed 
  correctly during struct layout (they are)
- A test that checks that structs defined in function bodies are 
  cpmpleted correctly during struct layout (currently they are not, 
  so this is XFAIL).

The second test fails because LookupSameContext()
(ExternalASTMerger.cpp) can't find the struct. This is an issue I 
intend to resolve separately.

Differential Revision: https://reviews.llvm.org/D36429

Added:
cfe/trunk/test/Import/local-struct/
  - copied from r310276, cfe/trunk/test/Import/import-overrides/
cfe/trunk/test/Import/local-struct/Inputs/Callee.cpp
  - copied, changed from r310276, 
cfe/trunk/test/Import/import-overrides/Inputs/Hierarchy.cpp
cfe/trunk/test/Import/struct-layout/
  - copied from r310276, cfe/trunk/test/Import/import-overrides/
cfe/trunk/test/Import/struct-layout/Inputs/Callee.cpp
  - copied, changed from r310276, 
cfe/trunk/test/Import/import-overrides/Inputs/Hierarchy.cpp
Removed:
cfe/trunk/test/Import/local-struct/Inputs/Hierarchy.cpp
cfe/trunk/test/Import/struct-layout/Inputs/Hierarchy.cpp
Modified:
cfe/trunk/test/Import/local-struct/test.cpp
cfe/trunk/test/Import/struct-layout/test.cpp
cfe/trunk/tools/clang-import-test/clang-import-test.cpp

Copied: cfe/trunk/test/Import/local-struct/Inputs/Callee.cpp (from r310276, 
cfe/trunk/test/Import/import-overrides/Inputs/Hierarchy.cpp)
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/local-struct/Inputs/Callee.cpp?p2=cfe/trunk/test/Import/local-struct/Inputs/Callee.cpp=cfe/trunk/test/Import/import-overrides/Inputs/Hierarchy.cpp=310276=310318=310318=diff
==
--- cfe/trunk/test/Import/import-overrides/Inputs/Hierarchy.cpp (original)
+++ cfe/trunk/test/Import/local-struct/Inputs/Callee.cpp Mon Aug  7 15:27:30 
2017
@@ -1,9 +1,12 @@
-class Base {
-public:
-  virtual void foo() {}
-};
-
-class Derived : public Base {
-public:
-  void foo() override {}
+struct Bar {
+  void bar(int _a, bool _b) {
+{
+  struct S { int a; };
+  S s = { _a };
+}
+{
+  struct S { bool b; };
+  S t = { _b };
+}
+  };
 };

Removed: cfe/trunk/test/Import/local-struct/Inputs/Hierarchy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/import-overrides/Inputs/Hierarchy.cpp?rev=310276=auto
==
--- cfe/trunk/test/Import/local-struct/Inputs/Hierarchy.cpp (original)
+++ cfe/trunk/test/Import/local-struct/Inputs/Hierarchy.cpp (removed)
@@ -1,9 +0,0 @@
-class Base {
-public:
-  virtual void foo() {}
-};
-
-class Derived : public Base {
-public:
-  void foo() override {}
-};

Modified: cfe/trunk/test/Import/local-struct/test.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/local-struct/test.cpp?rev=310318=310276=310318=diff
==
--- cfe/trunk/test/Import/local-struct/test.cpp (original)
+++ cfe/trunk/test/Import/local-struct/test.cpp Mon Aug  7 15:27:30 2017
@@ -1,7 +1,8 @@
-// RUN: clang-import-test -dump-ast -import %S/Inputs/Hierarchy.cpp 
-expression %s | FileCheck %s
-
-// CHECK: Overrides:{{.*}}Base::foo
+// RUN: clang-import-test -dump-ir -import %S/Inputs/Callee.cpp -expression %s 
| FileCheck %s
+// XFAIL: *
+// CHECK: %struct.S = type { i
+// CHECK: %struct.S.0 = type { i1 }
 
 void foo() {
-  Derived d;
+  return Bar().bar(3, true);
 }

Copied: cfe/trunk/test/Import/struct-layout/Inputs/Callee.cpp (from r310276, 
cfe/trunk/test/Import/import-overrides/Inputs/Hierarchy.cpp)
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/struct-layout/Inputs/Callee.cpp?p2=cfe/trunk/test/Import/struct-layout/Inputs/Callee.cpp=cfe/trunk/test/Import/import-overrides/Inputs/Hierarchy.cpp=310276=310318=310318=diff
==
--- cfe/trunk/test/Import/import-overrides/Inputs/Hierarchy.cpp (original)
+++ cfe/trunk/test/Import/struct-layout/Inputs/Callee.cpp Mon Aug  7 15:27:30 
2017
@@ -1,9 +1,9 @@
-class Base {
-public:
-  virtual void foo() {}
+struct S {
+  int a;
 };
 
-class Derived : public Base {
-public:
-  void foo() override {}
+struct Bar {
+  void bar(int _a) {
+S s = { _a };
+  };
 };

Removed: cfe/trunk/test/Import/struct-layout/Inputs/Hierarchy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/import-overrides/Inputs/Hierarchy.cpp?rev=310276=auto
==
--- 

r309018 - Fix a bot by linking clang-import-test against libclangDriver

2017-07-25 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Tue Jul 25 13:09:30 2017
New Revision: 309018

URL: http://llvm.org/viewvc/llvm-project?rev=309018=rev
Log:
Fix a bot by linking clang-import-test against libclangDriver

Modified:
cfe/trunk/tools/clang-import-test/CMakeLists.txt

Modified: cfe/trunk/tools/clang-import-test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-import-test/CMakeLists.txt?rev=309018=309017=309018=diff
==
--- cfe/trunk/tools/clang-import-test/CMakeLists.txt (original)
+++ cfe/trunk/tools/clang-import-test/CMakeLists.txt Tue Jul 25 13:09:30 2017
@@ -17,6 +17,7 @@ set(CLANG_IMPORT_TEST_LIB_DEPS
   clangAST
   clangBasic
   clangCodeGen
+  clangDriver
   clangFrontend
   clangLex
   clangParse


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r309014 - [ExternalASTMerger] Import Objective-C classes

2017-07-25 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Tue Jul 25 12:54:22 2017
New Revision: 309014

URL: http://llvm.org/viewvc/llvm-project?rev=309014=rev
Log:
[ExternalASTMerger] Import Objective-C classes

This patch adds functionality and a test for importing Objective-C classes
and their methods.

It also adds a flag to clang-import-test to set the language used for
parsing. This takes the same argument format as the -x option to the
driver.

Differential Revision: https://reviews.llvm.org/D35274

Added:
cfe/trunk/test/Import/objc-method/
  - copied from r308993, cfe/trunk/test/Import/member-in-struct/
cfe/trunk/test/Import/objc-method/Inputs/S.m
  - copied, changed from r308993, 
cfe/trunk/test/Import/member-in-struct/Inputs/S.c
cfe/trunk/test/Import/objc-method/test.m
  - copied, changed from r308993, 
cfe/trunk/test/Import/member-in-struct/test.c
Removed:
cfe/trunk/test/Import/objc-method/Inputs/S.c
cfe/trunk/test/Import/objc-method/test.c
Modified:
cfe/trunk/lib/AST/ExternalASTMerger.cpp
cfe/trunk/tools/clang-import-test/clang-import-test.cpp

Modified: cfe/trunk/lib/AST/ExternalASTMerger.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExternalASTMerger.cpp?rev=309014=309013=309014=diff
==
--- cfe/trunk/lib/AST/ExternalASTMerger.cpp (original)
+++ cfe/trunk/lib/AST/ExternalASTMerger.cpp Tue Jul 25 12:54:22 2017
@@ -44,6 +44,9 @@ public:
   ToTag->setMustBuildLookupTable();
 } else if (auto ToNamespace = dyn_cast(To)) {
   ToNamespace->setHasExternalVisibleStorage();
+} else if (auto ToContainer = dyn_cast(To)) {
+  ToContainer->setHasExternalLexicalStorage();
+  ToContainer->setMustBuildLookupTable();
 }
 return ASTImporter::Imported(From, To);
   }
@@ -80,11 +83,12 @@ LookupSameContext(Source(D)); // TODO handle this case
   if (auto TD = dyn_cast(D)) {
 return !TD->isThisDeclarationADefinition();
   } else if (auto FD = dyn_cast(D)) {
 return !FD->isThisDeclarationADefinition();
+  } else if (auto OID = dyn_cast(D)) {
+ return OID->isThisDeclarationADefinition();
   } else {
 return false;
   }

Removed: cfe/trunk/test/Import/objc-method/Inputs/S.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/member-in-struct/Inputs/S.c?rev=308993=auto
==
--- cfe/trunk/test/Import/objc-method/Inputs/S.c (original)
+++ cfe/trunk/test/Import/objc-method/Inputs/S.c (removed)
@@ -1,3 +0,0 @@
-struct S {
-  int a;
-};

Copied: cfe/trunk/test/Import/objc-method/Inputs/S.m (from r308993, 
cfe/trunk/test/Import/member-in-struct/Inputs/S.c)
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/objc-method/Inputs/S.m?p2=cfe/trunk/test/Import/objc-method/Inputs/S.m=cfe/trunk/test/Import/member-in-struct/Inputs/S.c=308993=309014=309014=diff
==
--- cfe/trunk/test/Import/member-in-struct/Inputs/S.c (original)
+++ cfe/trunk/test/Import/objc-method/Inputs/S.m Tue Jul 25 12:54:22 2017
@@ -1,3 +1,4 @@
-struct S {
-  int a;
-};
+@interface C {
+}
+-(int)m;
+@end

Removed: cfe/trunk/test/Import/objc-method/test.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/member-in-struct/test.c?rev=308993=auto
==
--- cfe/trunk/test/Import/objc-method/test.c (original)
+++ cfe/trunk/test/Import/objc-method/test.c (removed)
@@ -1,5 +0,0 @@
-// RUN: clang-import-test -import %S/Inputs/S.c -expression %s
-void expr() {
-  struct S MyS;
-  MyS.a = 3;
-}

Copied: cfe/trunk/test/Import/objc-method/test.m (from r308993, 
cfe/trunk/test/Import/member-in-struct/test.c)
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/objc-method/test.m?p2=cfe/trunk/test/Import/objc-method/test.m=cfe/trunk/test/Import/member-in-struct/test.c=308993=309014=309014=diff
==
--- cfe/trunk/test/Import/member-in-struct/test.c (original)
+++ cfe/trunk/test/Import/objc-method/test.m Tue Jul 25 12:54:22 2017
@@ -1,5 +1,5 @@
-// RUN: clang-import-test -import %S/Inputs/S.c -expression %s
+// RUN: clang-import-test -x objective-c++ -import %S/Inputs/S.m -expression %s
 void expr() {
-  struct S MyS;
-  MyS.a = 3;
+  C *c;
+  int i = [c m];
 }

Modified: cfe/trunk/tools/clang-import-test/clang-import-test.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-import-test/clang-import-test.cpp?rev=309014=309013=309014=diff
==
--- cfe/trunk/tools/clang-import-test/clang-import-test.cpp (original)
+++ cfe/trunk/tools/clang-import-test/clang-import-test.cpp Tue Jul 25 12:54:22 
2017
@@ -17,6 +17,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include 

r307603 - [clang-import-test] Test that enumerators and their values are found.

2017-07-10 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Mon Jul 10 17:29:37 2017
New Revision: 307603

URL: http://llvm.org/viewvc/llvm-project?rev=307603=rev
Log:
[clang-import-test] Test that enumerators and their values are found.

Added:
cfe/trunk/test/Import/enum/
  - copied from r307452, cfe/trunk/test/Import/member-in-struct/
cfe/trunk/test/Import/enum/Inputs/S.cpp
  - copied, changed from r307452, 
cfe/trunk/test/Import/member-in-struct/Inputs/S.c
cfe/trunk/test/Import/enum/test.cpp
  - copied, changed from r307452, 
cfe/trunk/test/Import/member-in-struct/test.c
Removed:
cfe/trunk/test/Import/enum/Inputs/S.c
cfe/trunk/test/Import/enum/test.c

Removed: cfe/trunk/test/Import/enum/Inputs/S.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/member-in-struct/Inputs/S.c?rev=307452=auto
==
--- cfe/trunk/test/Import/enum/Inputs/S.c (original)
+++ cfe/trunk/test/Import/enum/Inputs/S.c (removed)
@@ -1,3 +0,0 @@
-struct S {
-  int a;
-};

Copied: cfe/trunk/test/Import/enum/Inputs/S.cpp (from r307452, 
cfe/trunk/test/Import/member-in-struct/Inputs/S.c)
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/enum/Inputs/S.cpp?p2=cfe/trunk/test/Import/enum/Inputs/S.cpp=cfe/trunk/test/Import/member-in-struct/Inputs/S.c=307452=307603=307603=diff
==
--- cfe/trunk/test/Import/member-in-struct/Inputs/S.c (original)
+++ cfe/trunk/test/Import/enum/Inputs/S.cpp Mon Jul 10 17:29:37 2017
@@ -1,3 +1,4 @@
-struct S {
-  int a;
+enum E {
+  a = 1,
+  b = 2
 };

Removed: cfe/trunk/test/Import/enum/test.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/member-in-struct/test.c?rev=307452=auto
==
--- cfe/trunk/test/Import/enum/test.c (original)
+++ cfe/trunk/test/Import/enum/test.c (removed)
@@ -1,5 +0,0 @@
-// RUN: clang-import-test -import %S/Inputs/S.c -expression %s
-void expr() {
-  struct S MyS;
-  MyS.a = 3;
-}

Copied: cfe/trunk/test/Import/enum/test.cpp (from r307452, 
cfe/trunk/test/Import/member-in-struct/test.c)
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/enum/test.cpp?p2=cfe/trunk/test/Import/enum/test.cpp=cfe/trunk/test/Import/member-in-struct/test.c=307452=307603=307603=diff
==
--- cfe/trunk/test/Import/member-in-struct/test.c (original)
+++ cfe/trunk/test/Import/enum/test.cpp Mon Jul 10 17:29:37 2017
@@ -1,5 +1,4 @@
-// RUN: clang-import-test -import %S/Inputs/S.c -expression %s
+// RUN: clang-import-test -import %S/Inputs/S.cpp -expression %s
 void expr() {
-  struct S MyS;
-  MyS.a = 3;
+  static_assert(E::a + E::b == 3);
 }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r307602 - [clang-import-test] Committed missed update to clang-import-test.cpp

2017-07-10 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Mon Jul 10 17:27:57 2017
New Revision: 307602

URL: http://llvm.org/viewvc/llvm-project?rev=307602=rev
Log:
[clang-import-test] Committed missed update to clang-import-test.cpp

I didn't commit clang-import-test.cpp in r307600, but it had some
changes that were part of https://reviews.llvm.org/D35220

Corrected that now.

Modified:
cfe/trunk/tools/clang-import-test/clang-import-test.cpp

Modified: cfe/trunk/tools/clang-import-test/clang-import-test.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-import-test/clang-import-test.cpp?rev=307602=307601=307602=diff
==
--- cfe/trunk/tools/clang-import-test/clang-import-test.cpp (original)
+++ cfe/trunk/tools/clang-import-test/clang-import-test.cpp Mon Jul 10 17:27:57 
2017
@@ -182,14 +182,6 @@ BuildCompilerInstance(ArrayRef
-BuildCompilerInstance(ArrayRef ClangArgs) {
-  std::vector ClangArgv(ClangArgs.size());
-  std::transform(ClangArgs.begin(), ClangArgs.end(), ClangArgv.begin(),
- [](const std::string ) -> const char * { return s.data(); 
});
-  return init_convenience::BuildCompilerInstance(ClangArgv);
-}
-
 std::unique_ptr
 BuildASTContext(CompilerInstance , SelectorTable , Builtin::Context ) 
{
   auto AST = llvm::make_unique(
@@ -313,14 +305,8 @@ int main(int argc, const char **argv) {
   std::vector IndirectCIs;
   if (!Direct) {
 for (auto  : ImportCIs) {
-  llvm::Expected IndirectCI =
-  BuildIndirect(ImportCI);
-  if (auto E = IndirectCI.takeError()) {
-llvm::errs() << llvm::toString(std::move(E));
-exit(-1);
-  } else {
-IndirectCIs.push_back(std::move(*IndirectCI));
-  }
+  std::unique_ptr IndirectCI = BuildIndirect(ImportCI);
+  IndirectCIs.push_back(std::move(IndirectCI));
 }
   }
   llvm::Expected ExpressionCI =


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r307600 - clang-import-test had some dead code. I did the following to eliminate it:

2017-07-10 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Mon Jul 10 16:47:00 2017
New Revision: 307600

URL: http://llvm.org/viewvc/llvm-project?rev=307600=rev
Log:
clang-import-test had some dead code. I did the following to eliminate it:

- eliminated error handling for the indirect CompilerInstance, which should 
  never generate an error as it is created;
- added a new test for direct importation; and
- removed an unused implementation of the CompleteType() API.

This brings clang-import-test.cpp and ExternalASTMerge.cpp back to 100% 
coverage on all metrics measured by DLLVM_BUILD_INSTRUMENTED_COVERAGE.

Differential Revision: https://reviews.llvm.org/D35220

Added:
cfe/trunk/test/Import/direct/
  - copied from r307452, cfe/trunk/test/Import/member-in-struct/
Modified:
cfe/trunk/include/clang/AST/ExternalASTMerger.h
cfe/trunk/lib/AST/ExternalASTMerger.cpp
cfe/trunk/test/Import/direct/test.c

Modified: cfe/trunk/include/clang/AST/ExternalASTMerger.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExternalASTMerger.h?rev=307600=307599=307600=diff
==
--- cfe/trunk/include/clang/AST/ExternalASTMerger.h (original)
+++ cfe/trunk/include/clang/AST/ExternalASTMerger.h Mon Jul 10 16:47:00 2017
@@ -44,10 +44,6 @@ public:
   FindExternalLexicalDecls(const DeclContext *DC,
llvm::function_ref IsKindWeWant,
SmallVectorImpl ) override;
-
-   using ExternalASTSource::CompleteType;
-
-   void CompleteType(TagDecl *Tag) override;
 };
 
 } // end namespace clang

Modified: cfe/trunk/lib/AST/ExternalASTMerger.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExternalASTMerger.cpp?rev=307600=307599=307600=diff
==
--- cfe/trunk/lib/AST/ExternalASTMerger.cpp (original)
+++ cfe/trunk/lib/AST/ExternalASTMerger.cpp Mon Jul 10 16:47:00 2017
@@ -180,8 +180,3 @@ void ExternalASTMerger::FindExternalLexi
   });
 }
 
-void ExternalASTMerger::CompleteType(TagDecl *Tag) {
-  SmallVector Result;
-  FindExternalLexicalDecls(Tag, [](Decl::Kind) { return true; }, Result);
-  Tag->setHasExternalLexicalStorage(false);
-}

Modified: cfe/trunk/test/Import/direct/test.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/direct/test.c?rev=307600=307452=307600=diff
==
--- cfe/trunk/test/Import/direct/test.c (original)
+++ cfe/trunk/test/Import/direct/test.c Mon Jul 10 16:47:00 2017
@@ -1,4 +1,4 @@
-// RUN: clang-import-test -import %S/Inputs/S.c -expression %s
+// RUN: clang-import-test -direct -import %S/Inputs/S.c -expression %s
 void expr() {
   struct S MyS;
   MyS.a = 3;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r302975 - [ASTImporter] Improve handling of incomplete types

2017-05-12 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Fri May 12 19:46:33 2017
New Revision: 302975

URL: http://llvm.org/viewvc/llvm-project?rev=302975=rev
Log:
[ASTImporter] Improve handling of incomplete types

ASTImporter has some bugs when it's importing types 
that themselves come from an ExternalASTSource. This 
is exposed particularly in the behavior when 
comparing complete TagDecls with forward 
declarations. This patch does several things:

- Adds a test case making sure that conflicting 
  forward-declarations are resolved correctly;
- Extends the clang-import-test harness to test 
  two-level importing, so that we make sure we 
  complete types when necessary; and
- Fixes a few bugs I found this way. Failure to 
  complete types was one; however, I also discovered 
  that complete RecordDecls aren't properly added to 
  the redecls chain for existing forward 
  declarations.

Added:
cfe/trunk/test/Import/conflicting-struct/
cfe/trunk/test/Import/conflicting-struct/Inputs/
cfe/trunk/test/Import/conflicting-struct/Inputs/S1.cpp
cfe/trunk/test/Import/conflicting-struct/Inputs/S2.cpp
cfe/trunk/test/Import/conflicting-struct/test.cpp
Modified:
cfe/trunk/include/clang/AST/ExternalASTMerger.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp
cfe/trunk/lib/AST/ExternalASTMerger.cpp
cfe/trunk/tools/clang-import-test/clang-import-test.cpp

Modified: cfe/trunk/include/clang/AST/ExternalASTMerger.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExternalASTMerger.h?rev=302975=302974=302975=diff
==
--- cfe/trunk/include/clang/AST/ExternalASTMerger.h (original)
+++ cfe/trunk/include/clang/AST/ExternalASTMerger.h Fri May 12 19:46:33 2017
@@ -44,6 +44,8 @@ public:
   FindExternalLexicalDecls(const DeclContext *DC,
llvm::function_ref IsKindWeWant,
SmallVectorImpl ) override;
+
+   void CompleteType(TagDecl *Tag) override;
 };
 
 } // end namespace clang

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=302975=302974=302975=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Fri May 12 19:46:33 2017
@@ -1622,10 +1622,18 @@ Decl *ASTNodeImporter::VisitRecordDecl(R
 
   // We may already have a record of the same name; try to find and match it.
   RecordDecl *AdoptDecl = nullptr;
+  RecordDecl *PrevDecl = nullptr;
   if (!DC->isFunctionOrMethod()) {
 SmallVector ConflictingDecls;
 SmallVector FoundDecls;
 DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls);
+
+if (!FoundDecls.empty()) {
+  // We're going to have to compare D against potentially conflicting 
Decls, so complete it.
+  if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition())
+D->getASTContext().getExternalSource()->CompleteType(D);
+}
+
 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
   if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
 continue;
@@ -1652,6 +1660,8 @@ Decl *ASTNodeImporter::VisitRecordDecl(R
   }
 }
 
+PrevDecl = FoundRecord;
+
 if (RecordDecl *FoundDef = FoundRecord->getDefinition()) {
   if ((SearchName && !D->isCompleteDefinition())
   || (D->isCompleteDefinition() &&
@@ -1744,6 +1754,10 @@ Decl *ASTNodeImporter::VisitRecordDecl(R
 LexicalDC->addDeclInternal(D2);
 if (D->isAnonymousStructOrUnion())
   D2->setAnonymousStructOrUnion(true);
+if (PrevDecl) {
+  // FIXME: do this for all Redeclarables, not just RecordDecls.
+  D2->setPreviousDecl(PrevDecl);
+}
   }
   
   Importer.Imported(D, D2);

Modified: cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp?rev=302975=302974=302975=diff
==
--- cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp (original)
+++ cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp Fri May 12 19:46:33 2017
@@ -855,6 +855,11 @@ static bool IsStructurallyEquivalent(Str
 
   if (CXXRecordDecl *D1CXX = dyn_cast(D1)) {
 if (CXXRecordDecl *D2CXX = dyn_cast(D2)) {
+  if (D1CXX->hasExternalLexicalStorage() &&
+  !D1CXX->isCompleteDefinition()) {
+D1CXX->getASTContext().getExternalSource()->CompleteType(D1CXX);
+  }
+
   if (D1CXX->getNumBases() != D2CXX->getNumBases()) {
 if (Context.Complain) {
   Context.Diag2(D2->getLocation(), 
diag::warn_odr_tag_type_inconsistent)

Modified: cfe/trunk/lib/AST/ExternalASTMerger.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExternalASTMerger.cpp?rev=302975=302974=302975=diff

r301573 - Added an Importer test for in-class member initializers.

2017-04-27 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Thu Apr 27 13:10:29 2017
New Revision: 301573

URL: http://llvm.org/viewvc/llvm-project?rev=301573=rev
Log:
Added an Importer test for in-class member initializers.

Added:
cfe/trunk/test/Import/in-class-initializer/
cfe/trunk/test/Import/in-class-initializer/Inputs/
cfe/trunk/test/Import/in-class-initializer/Inputs/S.cpp
cfe/trunk/test/Import/in-class-initializer/test.cpp

Added: cfe/trunk/test/Import/in-class-initializer/Inputs/S.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/in-class-initializer/Inputs/S.cpp?rev=301573=auto
==
--- cfe/trunk/test/Import/in-class-initializer/Inputs/S.cpp (added)
+++ cfe/trunk/test/Import/in-class-initializer/Inputs/S.cpp Thu Apr 27 13:10:29 
2017
@@ -0,0 +1,3 @@
+struct S {
+  int a = 3;
+};

Added: cfe/trunk/test/Import/in-class-initializer/test.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/in-class-initializer/test.cpp?rev=301573=auto
==
--- cfe/trunk/test/Import/in-class-initializer/test.cpp (added)
+++ cfe/trunk/test/Import/in-class-initializer/test.cpp Thu Apr 27 13:10:29 2017
@@ -0,0 +1,5 @@
+// RUN: clang-import-test -import %S/Inputs/S.cpp -expression %s
+void expr() {
+  S MyS;
+  int b = MyS.a + MyS.a;
+}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r299983 - [ExternalASTMerger] Removed a move constructor to address MSVC build failure

2017-04-11 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Tue Apr 11 15:51:21 2017
New Revision: 299983

URL: http://llvm.org/viewvc/llvm-project?rev=299983=rev
Log:
[ExternalASTMerger] Removed a move constructor to address MSVC build failure

Modified:
cfe/trunk/lib/AST/ExternalASTMerger.cpp

Modified: cfe/trunk/lib/AST/ExternalASTMerger.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExternalASTMerger.cpp?rev=299983=299982=299983=diff
==
--- cfe/trunk/lib/AST/ExternalASTMerger.cpp (original)
+++ cfe/trunk/lib/AST/ExternalASTMerger.cpp Tue Apr 11 15:51:21 2017
@@ -23,7 +23,7 @@ namespace {
 
 template  struct Source {
   T t;
-  Source(T &) : t(std::move(t)) {}
+  Source(T t) : t(t) {}
   operator T() { return t; }
   template  U () { return t; }
   template  const U () const { return t; }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r299977 - [ExternalASTMerger] Fix the MSVC build

2017-04-11 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Tue Apr 11 14:50:37 2017
New Revision: 299977

URL: http://llvm.org/viewvc/llvm-project?rev=299977=rev
Log:
[ExternalASTMerger] Fix the MSVC build

Modified:
cfe/trunk/lib/AST/ExternalASTMerger.cpp

Modified: cfe/trunk/lib/AST/ExternalASTMerger.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExternalASTMerger.cpp?rev=299977=299976=299977=diff
==
--- cfe/trunk/lib/AST/ExternalASTMerger.cpp (original)
+++ cfe/trunk/lib/AST/ExternalASTMerger.cpp Tue Apr 11 14:50:37 2017
@@ -172,10 +172,10 @@ void ExternalASTMerger::FindExternalLexi
   ForEachMatchingDC(
   DC, Importers, [DC, IsKindWeWant](const ImporterPair ,
 Source SourceDC) {
-for (Source SourceDecl : SourceDC.get()->decls()) {
-  if (IsKindWeWant(SourceDecl.get()->getKind())) {
+for (const Decl *SourceDecl : SourceDC.get()->decls()) {
+  if (IsKindWeWant(SourceDecl->getKind())) {
 Decl *ImportedDecl =
-IP.Forward->Import(const_cast(SourceDecl.get()));
+IP.Forward->Import(const_cast(SourceDecl));
 assert(ImportedDecl->getDeclContext() == DC);
   }
 }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r299976 - [clang-import-test] Lookup inside contexts

2017-04-11 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Tue Apr 11 14:33:35 2017
New Revision: 299976

URL: http://llvm.org/viewvc/llvm-project?rev=299976=rev
Log:
[clang-import-test] Lookup inside contexts

clang-import-test has until now been only able to report top-level Decls.
This is clearly insufficient; we should be able to look inside structs 
and namespaces also.  This patch adds new test cases for a variety of 
lookups inside existing ASTContexts, and adds the functionality necessar
to make most of these testcases work.  (One testcase is known to fail 
because of ASTImporter limitations when importing templates; I'll look 
into that separately.)

This patch also separates the core functionality out into 
ExternalASTMerger, an interface that allows clients like LLDB to make 
use of it.  clang-import-test now only has the machinery necessary to
set up the tests.

Differential revision: https://reviews.llvm.org/D30435

Added:
cfe/trunk/include/clang/AST/ExternalASTMerger.h
cfe/trunk/lib/AST/ExternalASTMerger.cpp
cfe/trunk/test/Import/forward-declared-struct/
cfe/trunk/test/Import/forward-declared-struct/Inputs/
cfe/trunk/test/Import/forward-declared-struct/Inputs/S1.c
cfe/trunk/test/Import/forward-declared-struct/Inputs/S2.c
cfe/trunk/test/Import/forward-declared-struct/test.c
cfe/trunk/test/Import/member-in-struct/
cfe/trunk/test/Import/member-in-struct/Inputs/
cfe/trunk/test/Import/member-in-struct/Inputs/S.c
cfe/trunk/test/Import/member-in-struct/test.c
cfe/trunk/test/Import/multiple-forward-declarations/
cfe/trunk/test/Import/multiple-forward-declarations/Inputs/
cfe/trunk/test/Import/multiple-forward-declarations/Inputs/S1.c
cfe/trunk/test/Import/multiple-forward-declarations/Inputs/S2.c
cfe/trunk/test/Import/multiple-forward-declarations/test.c
cfe/trunk/test/Import/overloaded-function/
cfe/trunk/test/Import/overloaded-function/Inputs/
cfe/trunk/test/Import/overloaded-function/Inputs/F1.c
cfe/trunk/test/Import/overloaded-function/Inputs/F2.c
cfe/trunk/test/Import/overloaded-function/test.c
cfe/trunk/test/Import/struct-in-namespace/
cfe/trunk/test/Import/struct-in-namespace/Inputs/
cfe/trunk/test/Import/struct-in-namespace/Inputs/N1.cpp
cfe/trunk/test/Import/struct-in-namespace/Inputs/N2.cpp
cfe/trunk/test/Import/struct-in-namespace/Inputs/N3.cpp
cfe/trunk/test/Import/struct-in-namespace/test.cpp
cfe/trunk/test/Import/template-specialization/
cfe/trunk/test/Import/template-specialization/Inputs/
cfe/trunk/test/Import/template-specialization/Inputs/T.cpp
cfe/trunk/test/Import/template-specialization/test.cpp
Modified:
cfe/trunk/lib/AST/CMakeLists.txt
cfe/trunk/tools/clang-import-test/clang-import-test.cpp

Added: cfe/trunk/include/clang/AST/ExternalASTMerger.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExternalASTMerger.h?rev=299976=auto
==
--- cfe/trunk/include/clang/AST/ExternalASTMerger.h (added)
+++ cfe/trunk/include/clang/AST/ExternalASTMerger.h Tue Apr 11 14:33:35 2017
@@ -0,0 +1,51 @@
+//===--- ExternalASTMerger.h - Merging External AST Interface ---*- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This file declares the ExternalASTMerger, which vends a combination of ASTs
+//  from several different ASTContext/FileManager pairs
+//
+//===--===//
+#ifndef LLVM_CLANG_AST_EXTERNALASTMERGER_H
+#define LLVM_CLANG_AST_EXTERNALASTMERGER_H
+
+#include "clang/AST/ASTImporter.h"
+#include "clang/AST/ExternalASTSource.h"
+
+namespace clang {
+
+class ExternalASTMerger : public ExternalASTSource {
+public:
+  struct ImporterPair {
+std::unique_ptr Forward;
+std::unique_ptr Reverse;
+  };
+
+private:
+  std::vector Importers;
+
+public:
+  struct ImporterEndpoint {
+ASTContext 
+FileManager 
+  };
+  ExternalASTMerger(const ImporterEndpoint ,
+llvm::ArrayRef Sources);
+
+  bool FindExternalVisibleDeclsByName(const DeclContext *DC,
+  DeclarationName Name) override;
+
+  void
+  FindExternalLexicalDecls(const DeclContext *DC,
+   llvm::function_ref IsKindWeWant,
+   SmallVectorImpl ) override;
+};
+
+} // end namespace clang
+
+#endif

Modified: cfe/trunk/lib/AST/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CMakeLists.txt?rev=299976=299975=299976=diff
==
--- cfe/trunk/lib/AST/CMakeLists.txt (original)
+++ cfe/trunk/lib/AST/CMakeLists.txt Tue Apr 11 14:33:35 

Re: [PATCH] D30435: [clang-import-test] Lookup inside entities

2017-03-06 Thread Sean Callanan via cfe-commits
Gosh, I missed the reserve() call.  Sorry!  I'll be happy to implement this 
change.

Sean

> On Mar 6, 2017, at 10:05 AM, Sean Callanan  wrote:
> 
> Aleksei,
> 
> thank you for your comments!
> 
> I appreciate your comments in particular about source/destination confusion.  
> I can relate to this, as this was (a) an area that confused me while I was 
> working on this code in LLDB; and (b) it was something I had to keep straight 
> in my head even when doing the work here.  I will implement a type-system 
> based solution to this and update the patch, then you can have a look and 
> we'll decide if it looks better that way.
> The std::transform is more efficient than the for loop because it reallocates 
> the array once at the beginning, instead of progressively as we push_back.  
> This means the asymptotic runtime of this loop will be worse than the 
> std::transform.  Is that an acceptable trade?
> The other points are well-taken – in particular, I like your idea about 
> breaking the std::none_of block out into a function.  I'll apply them in an 
> updated patch.
> 
> Sean
> 
>> On Mar 6, 2017, at 9:48 AM, Aleksei Sidorin via Phabricator 
>> > wrote:
>> 
>> a.sidorin added a comment.
>> 
>> Hello Sean,
>> 
>> It is good to have the ability of recursive lookup. But for me (and I'm 
>> sorry), the code becomes very hard to understand: I need to track if the 
>> Decl/DC is in the source AST or in the AST being imported, if it was 
>> imported or if was in the AST before across lambdas and calls. Can we make 
>> this more clear?
>> 
>> 
>> 
>> 
>> Comment at: tools/clang-import-test/clang-import-test.cpp:201
>> +  Decl *Imported(Decl *From, Decl *To) override {
>> +if (auto ToTag = llvm::dyn_cast(To)) {
>> +  ToTag->setHasExternalLexicalStorage();
>> 
>> Can we make the usage of qualified and non-qualified casts consistent? 
>> Usually, casts are used as unqualified.
>> 
>> 
>> 
>> Comment at: tools/clang-import-test/clang-import-test.cpp:298
>> +
>> +std::vector CompleteDecls;
>> +std::vector ForwardDecls;
>> 
>> I guess we can use `SmallVector`s here too.
>> 
>> 
>> 
>> Comment at: tools/clang-import-test/clang-import-test.cpp:303
>> +  if (IsForwardDeclaration(C.first)) {
>> +if (std::none_of(ForwardDecls.begin(), ForwardDecls.end(),
>> + [](Candidate ) {
>> 
>> Nit: to make the code cleaner, we can extract this `std::none_of` to a 
>> separate function like `IsFoundAsForward()`. Nested lambdas are harder to 
>> read.
>> 
>> 
>> 
>> Comment at: tools/clang-import-test/clang-import-test.cpp:333
>> +Decls.resize(DeclsToReport.size());
>> +std::transform(DeclsToReport.begin(), DeclsToReport.end(), 
>> Decls.begin(),
>> +   [](Candidate ) {
>> 
>> The loop:
>> ```
>> Decls.reserve(DeclsToReport.size());
>> for (Candidate  : DeclsToReport)
>>  Decls.push_back(cast(C.second->Import(C.first)));
>> ```
>> will look a bit nicer here. What do you think?
>> 
>> 
>> Repository:
>>  rL LLVM
>> 
>> https://reviews.llvm.org/D30435 
>> 
>> 
>> 
> 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D30435: [clang-import-test] Lookup inside entities

2017-03-06 Thread Sean Callanan via cfe-commits
Aleksei,

thank you for your comments!

I appreciate your comments in particular about source/destination confusion.  I 
can relate to this, as this was (a) an area that confused me while I was 
working on this code in LLDB; and (b) it was something I had to keep straight 
in my head even when doing the work here.  I will implement a type-system based 
solution to this and update the patch, then you can have a look and we'll 
decide if it looks better that way.
The std::transform is more efficient than the for loop because it reallocates 
the array once at the beginning, instead of progressively as we push_back.  
This means the asymptotic runtime of this loop will be worse than the 
std::transform.  Is that an acceptable trade?
The other points are well-taken – in particular, I like your idea about 
breaking the std::none_of block out into a function.  I'll apply them in an 
updated patch.

Sean

> On Mar 6, 2017, at 9:48 AM, Aleksei Sidorin via Phabricator 
> > wrote:
> 
> a.sidorin added a comment.
> 
> Hello Sean,
> 
> It is good to have the ability of recursive lookup. But for me (and I'm 
> sorry), the code becomes very hard to understand: I need to track if the 
> Decl/DC is in the source AST or in the AST being imported, if it was imported 
> or if was in the AST before across lambdas and calls. Can we make this more 
> clear?
> 
> 
> 
> 
> Comment at: tools/clang-import-test/clang-import-test.cpp:201
> +  Decl *Imported(Decl *From, Decl *To) override {
> +if (auto ToTag = llvm::dyn_cast(To)) {
> +  ToTag->setHasExternalLexicalStorage();
> 
> Can we make the usage of qualified and non-qualified casts consistent? 
> Usually, casts are used as unqualified.
> 
> 
> 
> Comment at: tools/clang-import-test/clang-import-test.cpp:298
> +
> +std::vector CompleteDecls;
> +std::vector ForwardDecls;
> 
> I guess we can use `SmallVector`s here too.
> 
> 
> 
> Comment at: tools/clang-import-test/clang-import-test.cpp:303
> +  if (IsForwardDeclaration(C.first)) {
> +if (std::none_of(ForwardDecls.begin(), ForwardDecls.end(),
> + [](Candidate ) {
> 
> Nit: to make the code cleaner, we can extract this `std::none_of` to a 
> separate function like `IsFoundAsForward()`. Nested lambdas are harder to 
> read.
> 
> 
> 
> Comment at: tools/clang-import-test/clang-import-test.cpp:333
> +Decls.resize(DeclsToReport.size());
> +std::transform(DeclsToReport.begin(), DeclsToReport.end(), Decls.begin(),
> +   [](Candidate ) {
> 
> The loop:
> ```
> Decls.reserve(DeclsToReport.size());
> for (Candidate  : DeclsToReport)
>  Decls.push_back(cast(C.second->Import(C.first)));
> ```
> will look a bit nicer here. What do you think?
> 
> 
> Repository:
>  rL LLVM
> 
> https://reviews.llvm.org/D30435 
> 
> 
> 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r290367 - Testbed and skeleton of a new expression parser

2016-12-22 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Thu Dec 22 14:03:14 2016
New Revision: 290367

URL: http://llvm.org/viewvc/llvm-project?rev=290367=rev
Log:
Testbed and skeleton of a new expression parser

Recommitted after formal approval.

LLVM's JIT is now the foundation of dynamic-compilation features for many 
languages. Clang also has low-level support for dynamic compilation 
(ASTImporter and ExternalASTSource, notably). How the compiler is set up for 
dynamic parsing is generally left up to individual clients, for example LLDB's 
C/C++/Objective-C expression parser and the ROOT project.

Although this arrangement offers external clients the flexibility to implement 
dynamic features as they see fit, the lack of an in-tree client means that 
subtle bugs can be introduced that cause regressions in the external clients 
but aren't caught by tests (or users) until much later. LLDB for example 
regularly encounters complicated ODR violation scenarios where it is not 
immediately clear who is at fault.

Other external clients (notably, Cling) rely on similar functionality, and 
another goal is to break this functionality up into composable parts so that 
any client can be built easily on top of Clang without requiring extensive 
additional code.

I propose that the parts required to build a simple expression parser be added 
to Clang. Initially, I aim to have the following features:

A piece that looks up external declarations from a variety of sources (e.g., 
from previous dynamic compilations, from modules, or from DWARF) and uses clear 
conflict resolution rules to reconcile differences, with easily understood 
errors. This functionality will be supported by in-tree tests.
A piece that works hand in hand with the LLVM JIT to resolve the locations of 
external declarations so that e.g. variables can be redeclared and (for 
high-performance applications like DTrace) external variables can be accessed 
directly from the registers where they reside.
This commit adds a tester that parses a sequence of source files and then uses 
them as source data for an expression. External references are resolved using 
an ExternalASTSource that responds to name queries using an ASTImporter. This 
is the setup that LLDB uses, and the motivating reason for MinimalImport in 
ASTImporter. When complete, this tester will implement the first of the above 
goals.

Differential Revision: https://reviews.llvm.org/D27180

Added:
cfe/trunk/test/Import/
cfe/trunk/test/Import/clang-flags/
cfe/trunk/test/Import/clang-flags/Inputs/
cfe/trunk/test/Import/clang-flags/Inputs/S.c
cfe/trunk/test/Import/clang-flags/test.c
cfe/trunk/test/Import/empty-struct/
cfe/trunk/test/Import/empty-struct/Inputs/
cfe/trunk/test/Import/empty-struct/Inputs/S.c
cfe/trunk/test/Import/empty-struct/test.c
cfe/trunk/test/Import/error-in-expression/
cfe/trunk/test/Import/error-in-expression/Inputs/
cfe/trunk/test/Import/error-in-expression/Inputs/S.c
cfe/trunk/test/Import/error-in-expression/test.c
cfe/trunk/test/Import/error-in-import/
cfe/trunk/test/Import/error-in-import/Inputs/
cfe/trunk/test/Import/error-in-import/Inputs/S.c
cfe/trunk/test/Import/error-in-import/test.c
cfe/trunk/test/Import/missing-import/
cfe/trunk/test/Import/missing-import/test.c
cfe/trunk/tools/clang-import-test/
cfe/trunk/tools/clang-import-test/CMakeLists.txt
cfe/trunk/tools/clang-import-test/clang-import-test.cpp
Modified:
cfe/trunk/test/CMakeLists.txt
cfe/trunk/tools/CMakeLists.txt

Modified: cfe/trunk/test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CMakeLists.txt?rev=290367=290366=290367=diff
==
--- cfe/trunk/test/CMakeLists.txt (original)
+++ cfe/trunk/test/CMakeLists.txt Thu Dec 22 14:03:14 2016
@@ -39,6 +39,7 @@ list(APPEND CLANG_TEST_DEPS
   c-index-test diagtool
   clang-tblgen
   clang-offload-bundler
+  clang-import-test
   )
   
 if(CLANG_ENABLE_STATIC_ANALYZER)

Added: cfe/trunk/test/Import/clang-flags/Inputs/S.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/clang-flags/Inputs/S.c?rev=290367=auto
==
--- cfe/trunk/test/Import/clang-flags/Inputs/S.c (added)
+++ cfe/trunk/test/Import/clang-flags/Inputs/S.c Thu Dec 22 14:03:14 2016
@@ -0,0 +1,2 @@
+STRUCT S {
+};

Added: cfe/trunk/test/Import/clang-flags/test.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/clang-flags/test.c?rev=290367=auto
==
--- cfe/trunk/test/Import/clang-flags/test.c (added)
+++ cfe/trunk/test/Import/clang-flags/test.c Thu Dec 22 14:03:14 2016
@@ -0,0 +1,5 @@
+// RUN: clang-import-test -import %S/Inputs/S.c -expression %s -Xcc 
-DSTRUCT=struct
+void expr() {
+  STRUCT S MyS;
+  void *MyPtr = 
+}

Added: cfe/trunk/test/Import/empty-struct/Inputs/S.c

Re: [PATCH] D27180: Testbed and skeleton of a new expression parser

2016-12-19 Thread Sean Callanan via cfe-commits
Reverted by 290130.  I have new comments from Aleksei in 
https://reviews.llvm.org/D27180 .  I'll apply 
those and update the patch. 

Sean

> On Dec 19, 2016, at 9:48 AM, Sean Callanan  wrote:
> 
> David,
> 
> thanks for keeping an eye on this and sorry for the breach of process.
> Would having Vassil approve the changelist (https://reviews.llvm.org/D27180 
> ) be appropriate?
> Let's say if he has any concerns or can't get to it by tomorrow, we revert my 
> patches since they're pretty self-contained.
> 
> Sean
> 
>> On Dec 19, 2016, at 8:55 AM, David Blaikie > > wrote:
>> 
>> 
>> 
>> On Thu, Dec 15, 2016 at 2:18 PM Sean Callanan via Phabricator via 
>> cfe-commits > 
>> wrote:
>> spyffe updated this revision to Diff 81661.
>> spyffe marked 2 inline comments as done.
>> spyffe added a comment.
>> Herald added a subscriber: jgosnell.
>> 
>> Applied Vassil and Vedant's comments.  I will commit this soon.
>> 
>> Was this change approved/accepted by anyone? "commit if no one has 
>> objections in " isn't generally how LLVM project changes are 
>> reviewed/committed.
>>  
>> 
>> 
>> Repository:
>>   rL LLVM
>> 
>> https://reviews.llvm.org/D27180 
>> 
>> Files:
>>   test/Import/clang-flags/Inputs/S.c
>>   test/Import/clang-flags/test.c
>>   test/Import/empty-struct/Inputs/S.c
>>   test/Import/empty-struct/test.c
>>   test/Import/error-in-expression/Inputs/S.c
>>   test/Import/error-in-expression/test.c
>>   test/Import/error-in-import/Inputs/S.c
>>   test/Import/error-in-import/test.c
>>   test/Import/missing-import/test.c
>>   tools/CMakeLists.txt
>>   tools/clang-import-test/CMakeLists.txt
>>   tools/clang-import-test/clang-import-test.cpp
>> 
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org 
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits 
>> 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r290130 - Reverting r290004, r290006, r290010 pending review.

2016-12-19 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Mon Dec 19 13:15:43 2016
New Revision: 290130

URL: http://llvm.org/viewvc/llvm-project?rev=290130=rev
Log:
Reverting r290004, r290006, r290010 pending review.

Removed:
cfe/trunk/test/Import/
cfe/trunk/tools/clang-import-test/
Modified:
cfe/trunk/test/CMakeLists.txt
cfe/trunk/tools/CMakeLists.txt

Modified: cfe/trunk/test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CMakeLists.txt?rev=290130=290129=290130=diff
==
--- cfe/trunk/test/CMakeLists.txt (original)
+++ cfe/trunk/test/CMakeLists.txt Mon Dec 19 13:15:43 2016
@@ -39,7 +39,6 @@ list(APPEND CLANG_TEST_DEPS
   c-index-test diagtool
   clang-tblgen
   clang-offload-bundler
-  clang-import-test
   )
   
 if(CLANG_ENABLE_STATIC_ANALYZER)

Modified: cfe/trunk/tools/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CMakeLists.txt?rev=290130=290129=290130=diff
==
--- cfe/trunk/tools/CMakeLists.txt (original)
+++ cfe/trunk/tools/CMakeLists.txt Mon Dec 19 13:15:43 2016
@@ -5,7 +5,6 @@ add_clang_subdirectory(driver)
 add_clang_subdirectory(clang-format)
 add_clang_subdirectory(clang-format-vs)
 add_clang_subdirectory(clang-fuzzer)
-add_clang_subdirectory(clang-import-test)
 add_clang_subdirectory(clang-offload-bundler)
 
 add_clang_subdirectory(c-index-test)


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D27180: Testbed and skeleton of a new expression parser

2016-12-19 Thread Sean Callanan via cfe-commits
David,

thanks for keeping an eye on this and sorry for the breach of process.
Would having Vassil approve the changelist (https://reviews.llvm.org/D27180 
) be appropriate?
Let's say if he has any concerns or can't get to it by tomorrow, we revert my 
patches since they're pretty self-contained.

Sean

> On Dec 19, 2016, at 8:55 AM, David Blaikie  wrote:
> 
> 
> 
> On Thu, Dec 15, 2016 at 2:18 PM Sean Callanan via Phabricator via cfe-commits 
> > wrote:
> spyffe updated this revision to Diff 81661.
> spyffe marked 2 inline comments as done.
> spyffe added a comment.
> Herald added a subscriber: jgosnell.
> 
> Applied Vassil and Vedant's comments.  I will commit this soon.
> 
> Was this change approved/accepted by anyone? "commit if no one has objections 
> in " isn't generally how LLVM project changes are 
> reviewed/committed.
>  
> 
> 
> Repository:
>   rL LLVM
> 
> https://reviews.llvm.org/D27180 
> 
> Files:
>   test/Import/clang-flags/Inputs/S.c
>   test/Import/clang-flags/test.c
>   test/Import/empty-struct/Inputs/S.c
>   test/Import/empty-struct/test.c
>   test/Import/error-in-expression/Inputs/S.c
>   test/Import/error-in-expression/test.c
>   test/Import/error-in-import/Inputs/S.c
>   test/Import/error-in-import/test.c
>   test/Import/missing-import/test.c
>   tools/CMakeLists.txt
>   tools/clang-import-test/CMakeLists.txt
>   tools/clang-import-test/clang-import-test.cpp
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org 
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits 
> 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D27683: Prepare PrettyStackTrace for LLDB adoption

2016-12-19 Thread Sean Callanan via cfe-commits
That would require making LLDB crash and collecting the relevant crash log data 
out of the user's own logs.  This isn't impossible – but additionally the 
generation of that log is asynchronous and you don't quite know when it'll land.
Would you be all right with a more restricted macOS-only unit test where we 
check that __crashreporter_info__ contains what we think it does?  That won't 
check end-to-end but at least it'll give us some confidence that things are 
sane.

Sean

> On Dec 19, 2016, at 9:01 AM, David Blaikie  wrote:
> 
> Test coverage?
> 
> On Tue, Dec 13, 2016 at 2:39 PM Sean Callanan via Phabricator via cfe-commits 
> > wrote:
> spyffe retitled this revision from "Fix the linkage for __crashtracer_info__" 
> to "Prepare PrettyStackTrace for LLDB adoption".
> spyffe updated the summary for this revision.
> spyffe updated this revision to Diff 81304.
> 
> Repository:
>   rL LLVM
> 
> https://reviews.llvm.org/D27683 
> 
> Files:
>   include/llvm/Support/PrettyStackTrace.h
>   lib/Support/PrettyStackTrace.cpp
> 
> 
> Index: lib/Support/PrettyStackTrace.cpp
> ===
> --- lib/Support/PrettyStackTrace.cpp
> +++ lib/Support/PrettyStackTrace.cpp
> @@ -89,7 +89,7 @@
>  = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0 };
>  }
>  #elif defined (__APPLE__) && HAVE_CRASHREPORTER_INFO
> -static const char *__crashreporter_info__ = 0;
> +extern "C" const char *__crashreporter_info__ 
> __attribute__((visibility("hidden"))) = 0;
>  asm(".desc ___crashreporter_info__, 0x10");
>  #endif
> 
> @@ -145,6 +145,28 @@
>OS << Str << "\n";
>  }
> 
> +PrettyStackTraceFormat::PrettyStackTraceFormat(const char *format, ...) {
> +  va_list ap;
> +
> +  va_start(ap, format);
> +  const int size_or_error = vsnprintf(nullptr, 0, format, ap);
> +  va_end(ap);
> +
> +  if (size_or_error < 0) {
> +return;
> +  }
> +
> +  const int size = size_or_error + 1; // '\0'
> +
> +  Str.resize(size);
> +
> +  va_start(ap, format);
> +  vsnprintf(Str.data(), size, format, ap);
> +  va_end(ap);
> +}
> +
> +void PrettyStackTraceFormat::print(raw_ostream ) const { OS << Str << 
> "\n"; }
> +
>  void PrettyStackTraceProgram::print(raw_ostream ) const {
>OS << "Program arguments: ";
>// Print the argument list.
> Index: include/llvm/Support/PrettyStackTrace.h
> ===
> --- include/llvm/Support/PrettyStackTrace.h
> +++ include/llvm/Support/PrettyStackTrace.h
> @@ -16,6 +16,7 @@
>  #ifndef LLVM_SUPPORT_PRETTYSTACKTRACE_H
>  #define LLVM_SUPPORT_PRETTYSTACKTRACE_H
> 
> +#include "llvm/ADT/SmallVector.h"
>  #include "llvm/Support/Compiler.h"
> 
>  namespace llvm {
> @@ -55,6 +56,16 @@
>  void print(raw_ostream ) const override;
>};
> 
> +  /// PrettyStackTraceFormat - This object prints a string (which may use
> +  /// printf-style formatting but should not contain newlines) to the stream
> +  /// as the stack trace when a crash occurs.
> +  class PrettyStackTraceFormat : public PrettyStackTraceEntry {
> +llvm::SmallVector Str;
> +  public:
> +PrettyStackTraceFormat(const char *format, ...);
> +void print(raw_ostream ) const override;
> +  };
> +
>/// PrettyStackTraceProgram - This object prints a specified program 
> arguments
>/// to the stream as the stack trace when a crash occurs.
>class PrettyStackTraceProgram : public PrettyStackTraceEntry {
> 
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org 
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits 
> 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r290010 - Added clangLex to the dependencies for clang-import-test.

2016-12-16 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Fri Dec 16 17:45:03 2016
New Revision: 290010

URL: http://llvm.org/viewvc/llvm-project?rev=290010=rev
Log:
Added clangLex to the dependencies for clang-import-test.

This is part of the effort to get the i686-mingw32-RA-on-linux bot to like 
clang-import-test.

Modified:
cfe/trunk/tools/clang-import-test/CMakeLists.txt

Modified: cfe/trunk/tools/clang-import-test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-import-test/CMakeLists.txt?rev=290010=290009=290010=diff
==
--- cfe/trunk/tools/clang-import-test/CMakeLists.txt (original)
+++ cfe/trunk/tools/clang-import-test/CMakeLists.txt Fri Dec 16 17:45:03 2016
@@ -18,6 +18,7 @@ set(CLANG_IMPORT_TEST_LIB_DEPS
   clangBasic
   clangCodeGen
   clangFrontend
+  clangLex
   clangParse
   )
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r290006 - Fixed library dependencies on clang-import-test to clean up the bots.

2016-12-16 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Fri Dec 16 17:34:16 2016
New Revision: 290006

URL: http://llvm.org/viewvc/llvm-project?rev=290006=rev
Log:
Fixed library dependencies on clang-import-test to clean up the bots.

Modified:
cfe/trunk/tools/clang-import-test/CMakeLists.txt

Modified: cfe/trunk/tools/clang-import-test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-import-test/CMakeLists.txt?rev=290006=290005=290006=diff
==
--- cfe/trunk/tools/clang-import-test/CMakeLists.txt (original)
+++ cfe/trunk/tools/clang-import-test/CMakeLists.txt Fri Dec 16 17:34:16 2016
@@ -1,4 +1,5 @@
 set(LLVM_LINK_COMPONENTS
+  core
   support
 )
 
@@ -17,6 +18,7 @@ set(CLANG_IMPORT_TEST_LIB_DEPS
   clangBasic
   clangCodeGen
   clangFrontend
+  clangParse
   )
 
 target_link_libraries(clang-import-test


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r290004 - Testbed and skeleton of a new expression parser

2016-12-16 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Fri Dec 16 17:21:38 2016
New Revision: 290004

URL: http://llvm.org/viewvc/llvm-project?rev=290004=rev
Log:
Testbed and skeleton of a new expression parser

LLVM's JIT is now the foundation of dynamic-compilation features for many 
languages. Clang also has low-level support for dynamic compilation 
(ASTImporter and ExternalASTSource, notably). How the compiler is set up for 
dynamic parsing is generally left up to individual clients, for example LLDB's 
C/C++/Objective-C expression parser and the ROOT project.

Although this arrangement offers external clients the flexibility to implement 
dynamic features as they see fit, the lack of an in-tree client means that 
subtle bugs can be introduced that cause regressions in the external clients 
but aren't caught by tests (or users) until much later. LLDB for example 
regularly encounters complicated ODR violation scenarios where it is not 
immediately clear who is at fault.

Other external clients (notably, Cling) rely on similar functionality, and 
another goal is to break this functionality up into composable parts so that 
any client can be built easily on top of Clang without requiring extensive 
additional code.

I propose that the parts required to build a simple expression parser be added 
to Clang.  Initially, I aim to have the following features:

- A piece that looks up external declarations from a variety of sources (e.g., 
from previous dynamic compilations, from modules, or from DWARF) and uses clear 
conflict resolution rules to reconcile differences, with easily understood 
errors. This functionality will be supported by in-tree tests.

- A piece that works hand in hand with the LLVM JIT to resolve the locations of 
external declarations so that e.g. variables can be redeclared and (for 
high-performance applications like DTrace) external variables can be accessed 
directly from the registers where they reside.

This commit adds a tester that parses a sequence of source files and then uses 
them as source data for an expression. External references are resolved using 
an ExternalASTSource that responds to name queries using an ASTImporter. This 
is the setup that LLDB uses, and the motivating reason for MinimalImport in 
ASTImporter.  When complete, this tester will implement the first of the above 
goals.

Differential Revision: https://reviews.llvm.org/D27180

Added:
cfe/trunk/test/Import/
cfe/trunk/test/Import/clang-flags/
cfe/trunk/test/Import/clang-flags/Inputs/
cfe/trunk/test/Import/clang-flags/Inputs/S.c
cfe/trunk/test/Import/clang-flags/test.c
cfe/trunk/test/Import/empty-struct/
cfe/trunk/test/Import/empty-struct/Inputs/
cfe/trunk/test/Import/empty-struct/Inputs/S.c
cfe/trunk/test/Import/empty-struct/test.c
cfe/trunk/test/Import/error-in-expression/
cfe/trunk/test/Import/error-in-expression/Inputs/
cfe/trunk/test/Import/error-in-expression/Inputs/S.c
cfe/trunk/test/Import/error-in-expression/test.c
cfe/trunk/test/Import/error-in-import/
cfe/trunk/test/Import/error-in-import/Inputs/
cfe/trunk/test/Import/error-in-import/Inputs/S.c
cfe/trunk/test/Import/error-in-import/test.c
cfe/trunk/test/Import/missing-import/
cfe/trunk/test/Import/missing-import/test.c
cfe/trunk/tools/clang-import-test/
cfe/trunk/tools/clang-import-test/CMakeLists.txt
cfe/trunk/tools/clang-import-test/clang-import-test.cpp
Modified:
cfe/trunk/test/CMakeLists.txt
cfe/trunk/tools/CMakeLists.txt

Modified: cfe/trunk/test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CMakeLists.txt?rev=290004=290003=290004=diff
==
--- cfe/trunk/test/CMakeLists.txt (original)
+++ cfe/trunk/test/CMakeLists.txt Fri Dec 16 17:21:38 2016
@@ -39,6 +39,7 @@ list(APPEND CLANG_TEST_DEPS
   c-index-test diagtool
   clang-tblgen
   clang-offload-bundler
+  clang-import-test
   )
   
 if(CLANG_ENABLE_STATIC_ANALYZER)

Added: cfe/trunk/test/Import/clang-flags/Inputs/S.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/clang-flags/Inputs/S.c?rev=290004=auto
==
--- cfe/trunk/test/Import/clang-flags/Inputs/S.c (added)
+++ cfe/trunk/test/Import/clang-flags/Inputs/S.c Fri Dec 16 17:21:38 2016
@@ -0,0 +1,2 @@
+STRUCT S {
+};

Added: cfe/trunk/test/Import/clang-flags/test.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/clang-flags/test.c?rev=290004=auto
==
--- cfe/trunk/test/Import/clang-flags/test.c (added)
+++ cfe/trunk/test/Import/clang-flags/test.c Fri Dec 16 17:21:38 2016
@@ -0,0 +1,5 @@
+// RUN: clang-import-test -import %S/Inputs/S.c -expression %s -Xcc 
-DSTRUCT=struct
+void expr() {
+  STRUCT S MyS;
+  void *MyPtr = 
+}

Added: cfe/trunk/test/Import/empty-struct/Inputs/S.c
URL: 

[PATCH] D26808: [Sema] Don't allow applying address-of operator to a call to a function with __unknown_anytype return type

2016-11-18 Thread Sean Callanan via cfe-commits
spyffe accepted this revision.
spyffe added a comment.
This revision is now accepted and ready to land.

I think it's all right to be conservative here.  The inference rules could get 
quite complicated if (for example) the use looked like this

  extern void foo (double *bar);
  extern __unknown_anytype func();
  // ...
  foo(());

One could come up with even more complicated cases.  It's probably not worth 
making sure they all work.


https://reviews.llvm.org/D26808



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26753: ASTImporter: improve support for C++ templates

2016-11-16 Thread Sean Callanan via cfe-commits
spyffe requested changes to this revision.
spyffe added a comment.
This revision now requires changes to proceed.

This looks amazing.  I have a few minor quibbles and a testing concern, but 
overall this looks like a great step forward!  Thank you!




Comment at: lib/AST/ASTImporter.cpp:458
+  }
+  return true;
+}

Is this really an appropriate default result?  I would argue for `false` here 
so that an error would propagate, as is typical in ASTImporter.
Note that this does disagree with the original source's `true` but I think that 
was because we knew we didn't handle anything, whereas now the assumption is we 
handle everything.



Comment at: lib/AST/ASTImporter.cpp:496
+return false;
+  if (DN1->isIdentifier())
+return IsStructurallyEquivalent(DN1->getIdentifier(),

We should probably also check whether `DN1->isIdentifier() == 
DN2->isIdentifier()`.



Comment at: lib/AST/ASTImporter.cpp:520
+  }
   return true;
 }

As above, I'd argue for `false` here now that we're flipping to the assumption 
that this code is complete.



Comment at: lib/AST/ASTImporter.cpp:4911
+
+if (D->getTypeAsWritten()) {
+  TypeSourceInfo *TInfo = Importer.Import(D->getTypeAsWritten());

Could you assign this to a variable here, to avoid the redundant call a line 
below?



Comment at: lib/AST/ASTImporter.cpp:4931
 LexicalDC->addDeclInternal(D2);
+
   }

This blank line is probably not needed.



Comment at: lib/AST/ASTImporter.cpp:7035
 
 NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) {
+  // Copied from NestedNameSpecifier mostly.

Is this function properly covered by the test?  I would like to see some 
deeply-neded name specifiers in the test, with entries for all the cases here.
If I'm missing the part of the test that covers this, please let me know.


https://reviews.llvm.org/D26753



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26571: Clean up layout of ASTMerge tests

2016-11-16 Thread Sean Callanan via cfe-commits
spyffe closed this revision.
spyffe added a comment.

Committed r287129


Repository:
  rL LLVM

https://reviews.llvm.org/D26571



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r287129 - Fixed layout of test/ASTMerge.

2016-11-16 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Wed Nov 16 12:21:00 2016
New Revision: 287129

URL: http://llvm.org/viewvc/llvm-project?rev=287129=rev
Log:
Fixed layout of test/ASTMerge.

As outlined in a previous RFC, the test/ASTMerge/Inputs folder is getting full 
and the tests are starting to become interdependent. This is undesirable because

- it makes it harder to write new tests
- it makes it harder to figure out at a glance what old tests are doing, and
- it adds the risk of breaking one test while changing a different one, because 
of the interdependencies.

To fix this, according to the conversation in the RFC, I have changed the 
layout from

a.c
Inputs/a1.c
Inputs/a2.c

to

a/test.c
a/Inputs/a1.c
a/Inputs/a2.c
for all existing tests. I have also eliminated interdependencies by replicating 
the input files for each test that uses them.

https://reviews.llvm.org/D26571

Added:
cfe/trunk/test/ASTMerge/anonymous-fields/
cfe/trunk/test/ASTMerge/anonymous-fields/Inputs/
cfe/trunk/test/ASTMerge/anonymous-fields/Inputs/anonymous-fields1.cpp
  - copied unchanged from r287128, 
cfe/trunk/test/ASTMerge/Inputs/anonymous-fields1.cpp
cfe/trunk/test/ASTMerge/anonymous-fields/Inputs/anonymous-fields2.cpp
  - copied unchanged from r287128, 
cfe/trunk/test/ASTMerge/Inputs/anonymous-fields2.cpp
cfe/trunk/test/ASTMerge/anonymous-fields/test.cpp
  - copied unchanged from r287128, 
cfe/trunk/test/ASTMerge/anonymous-fields.cpp
cfe/trunk/test/ASTMerge/asm/
cfe/trunk/test/ASTMerge/asm/Inputs/
cfe/trunk/test/ASTMerge/asm/Inputs/asm-function.cpp
  - copied unchanged from r287128, 
cfe/trunk/test/ASTMerge/Inputs/asm-function.cpp
cfe/trunk/test/ASTMerge/asm/test.cpp
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/asm.cpp
cfe/trunk/test/ASTMerge/category/
cfe/trunk/test/ASTMerge/category/Inputs/
cfe/trunk/test/ASTMerge/category/Inputs/category1.m
  - copied unchanged from r287128, 
cfe/trunk/test/ASTMerge/Inputs/category1.m
cfe/trunk/test/ASTMerge/category/Inputs/category2.m
  - copied unchanged from r287128, 
cfe/trunk/test/ASTMerge/Inputs/category2.m
cfe/trunk/test/ASTMerge/category/test.m
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/category.m
cfe/trunk/test/ASTMerge/class/
cfe/trunk/test/ASTMerge/class-template/
cfe/trunk/test/ASTMerge/class-template/Inputs/
cfe/trunk/test/ASTMerge/class-template/Inputs/class-template1.cpp
  - copied unchanged from r287128, 
cfe/trunk/test/ASTMerge/Inputs/class-template1.cpp
cfe/trunk/test/ASTMerge/class-template/Inputs/class-template2.cpp
  - copied unchanged from r287128, 
cfe/trunk/test/ASTMerge/Inputs/class-template2.cpp
cfe/trunk/test/ASTMerge/class-template/test.cpp
  - copied unchanged from r287128, 
cfe/trunk/test/ASTMerge/class-template.cpp
cfe/trunk/test/ASTMerge/class/Inputs/
cfe/trunk/test/ASTMerge/class/Inputs/class1.cpp
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/Inputs/class1.cpp
cfe/trunk/test/ASTMerge/class/Inputs/class2.cpp
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/Inputs/class2.cpp
cfe/trunk/test/ASTMerge/class/test.cpp
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/class.cpp
cfe/trunk/test/ASTMerge/class2/
cfe/trunk/test/ASTMerge/class2/Inputs/
cfe/trunk/test/ASTMerge/class2/Inputs/class3.cpp
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/Inputs/class3.cpp
cfe/trunk/test/ASTMerge/class2/test.cpp
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/class2.cpp
cfe/trunk/test/ASTMerge/codegen-body/
cfe/trunk/test/ASTMerge/codegen-body/Inputs/
cfe/trunk/test/ASTMerge/codegen-body/Inputs/body1.c
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/Inputs/body1.c
cfe/trunk/test/ASTMerge/codegen-body/Inputs/body2.c
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/Inputs/body2.c
cfe/trunk/test/ASTMerge/codegen-body/test.c
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/codegen-body.c
cfe/trunk/test/ASTMerge/codegen-exprs/
cfe/trunk/test/ASTMerge/codegen-exprs/Inputs/
cfe/trunk/test/ASTMerge/codegen-exprs/Inputs/exprs1.c
  - copied unchanged from r286635, cfe/trunk/test/ASTMerge/Inputs/exprs1.c
cfe/trunk/test/ASTMerge/codegen-exprs/Inputs/exprs2.c
  - copied unchanged from r286635, cfe/trunk/test/ASTMerge/Inputs/exprs2.c
cfe/trunk/test/ASTMerge/codegen-exprs/test.c
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/codegen-exprs.c
cfe/trunk/test/ASTMerge/enum/
cfe/trunk/test/ASTMerge/enum/Inputs/
cfe/trunk/test/ASTMerge/enum/Inputs/enum1.c
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/Inputs/enum1.c
cfe/trunk/test/ASTMerge/enum/Inputs/enum2.c
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/Inputs/enum2.c
cfe/trunk/test/ASTMerge/enum/test.c
  - copied unchanged from r287128, 

[PATCH] D26571: Clean up layout of ASTMerge tests

2016-11-14 Thread Sean Callanan via cfe-commits
spyffe added a reviewer: beanz.
spyffe updated this revision to Diff 77928.
spyffe added a comment.

Updated the locations so the structure is now

  a/test.c
  a/Inputs/a1.c
  a/Inputs/a2.c

The naming of "test.c" is no longer a requirement but only a convention.  Also 
`lit.site.cfg` is no longer required because we no longer do anything unusual 
from `lit`'s perspective.


Repository:
  rL LLVM

https://reviews.llvm.org/D26571

Files:
  Inputs/anonymous-fields1.cpp
  Inputs/anonymous-fields2.cpp
  Inputs/asm-function.cpp
  Inputs/body1.c
  Inputs/body2.c
  Inputs/category1.m
  Inputs/category2.m
  Inputs/class-template1.cpp
  Inputs/class-template2.cpp
  Inputs/class1.cpp
  Inputs/class2.cpp
  Inputs/class3.cpp
  Inputs/enum1.c
  Inputs/enum2.c
  Inputs/exprs1.c
  Inputs/exprs2.c
  Inputs/exprs3.cpp
  Inputs/function1.c
  Inputs/function2.c
  Inputs/inheritance-base.cpp
  Inputs/init-ctors-classes.cpp
  Inputs/interface1.m
  Inputs/interface2.m
  Inputs/macro.modulemap
  Inputs/macro1.h
  Inputs/macro1.m
  Inputs/macro2.m
  Inputs/namespace1.cpp
  Inputs/namespace2.cpp
  Inputs/property1.m
  Inputs/property2.m
  Inputs/struct1.c
  Inputs/struct2.c
  Inputs/typedef1.c
  Inputs/typedef2.c
  Inputs/var1.c
  Inputs/var1.h
  Inputs/var2.c
  anonymous-fields.cpp
  anonymous-fields/Inputs/anonymous-fields1.cpp
  anonymous-fields/Inputs/anonymous-fields2.cpp
  anonymous-fields/test.cpp
  asm.cpp
  asm/Inputs/asm-function.cpp
  asm/test.cpp
  category.m
  category/Inputs/category1.m
  category/Inputs/category2.m
  category/test.m
  class-template.cpp
  class-template/Inputs/class-template1.cpp
  class-template/Inputs/class-template2.cpp
  class-template/test.cpp
  class.cpp
  class/Inputs/class1.cpp
  class/Inputs/class2.cpp
  class/test.cpp
  class2.cpp
  class2/Inputs/class3.cpp
  class2/test.cpp
  codegen-body.c
  codegen-body/Inputs/body1.c
  codegen-body/Inputs/body2.c
  codegen-body/test.c
  codegen-exprs.c
  codegen-exprs/Inputs/exprs1.c
  codegen-exprs/Inputs/exprs2.c
  codegen-exprs/test.c
  enum.c
  enum/Inputs/enum1.c
  enum/Inputs/enum2.c
  enum/test.c
  exprs-cpp/Inputs/exprs3.cpp
  exprs-cpp/test.cpp
  exprs.c
  exprs.cpp
  exprs/Inputs/exprs1.c
  exprs/Inputs/exprs2.c
  exprs/test.c
  function.c
  function/Inputs/function1.c
  function/Inputs/function2.c
  function/test.c
  inheritance.cpp
  inheritance/Inputs/inheritance-base.cpp
  inheritance/test.cpp
  init-ctors.cpp
  init-ctors/Inputs/init-ctors-classes.cpp
  init-ctors/test.cpp
  interface.m
  interface/Inputs/interface1.m
  interface/Inputs/interface2.m
  interface/test.m
  macro.m
  macro/Inputs/macro.modulemap
  macro/Inputs/macro1.h
  macro/Inputs/macro1.m
  macro/Inputs/macro2.m
  macro/test.m
  namespace.cpp
  namespace/Inputs/namespace1.cpp
  namespace/Inputs/namespace2.cpp
  namespace/test.cpp
  property.m
  property/Inputs/property1.m
  property/Inputs/property2.m
  property/test.m
  struct.c
  struct/Inputs/struct1.c
  struct/Inputs/struct2.c
  struct/test.c
  typedef.c
  typedef/Inputs/typedef1.c
  typedef/Inputs/typedef2.c
  typedef/test.c
  var.c
  var/Inputs/var1.c
  var/Inputs/var1.h
  var/Inputs/var2.c
  var/test.c

Index: var.c
===
--- var.c
+++ var.c
@@ -1,12 +0,0 @@
-// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/var1.c
-// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/var2.c
-// RUN: not %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only -fdiagnostics-show-note-include-stack %s 2>&1 | FileCheck %s
-
-// CHECK: var2.c:2:9: error: external variable 'x1' declared with incompatible types in different translation units ('double *' vs. 'float **')
-// CHECK: var1.c:2:9: note: declared here with type 'float **'
-// CHECK: var2.c:3:5: error: external variable 'x2' declared with incompatible types in different translation units ('int' vs. 'double')
-// CHECK: In file included from{{.*}}var1.c:3:
-// CHECK: var1.h:1:8: note: declared here with type 'double'
-// CHECK: error: external variable 'xarray3' declared with incompatible types in different translation units ('int [17]' vs. 'int [18]')
-// CHECK: var1.c:7:5: note: declared here with type 'int [18]'
-// CHECK: 3 errors
Index: typedef.c
===
--- typedef.c
+++ typedef.c
@@ -1,7 +0,0 @@
-// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/typedef1.c
-// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/typedef2.c
-// RUN: not %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s
-
-// CHECK: typedef2.c:4:10: error: external variable 'x2' declared with incompatible types in different translation units ('Typedef2' (aka 'double') vs. 'Typedef2' (aka 'int'))
-// CHECK: typedef1.c:4:10: note: declared here with type 'Typedef2' (aka 'int')
-// CHECK: 1 error
Index: struct.c
===
--- struct.c
+++ struct.c
@@ -1,42 +0,0 @@
-// RUN: %clang_cc1 

[PATCH] D26571: Clean up layout of ASTMerge tests

2016-11-11 Thread Sean Callanan via cfe-commits
spyffe created this revision.
spyffe added a reviewer: a.sidorin.
spyffe added a subscriber: cfe-commits.
spyffe set the repository for this revision to rL LLVM.

As outlined in a previous RFC, the `test/ASTMerge/Inputs` folder is getting 
full and the tests are starting to become interdependent.  This is undesirable 
because

- it makes it harder to write new tests
- it makes it harder to figure out at a glance what old tests are doing, and
- it adds the risk of breaking one test while changing a different one, because 
of the interdependencies.

To fix this, according to the conversation in the RFC, I have changed the 
layout from

  a.c
  Inputs/a1.c
  Inputs/a2.c

to

  a/test.c
  a/a1.c
  a/a2.c

for all existing tests.  I have also eliminated interdependencies (by 
replicating the input files for each test that uses them) and made a little 
`lit.cfg` that makes sure that lit only processes 
`test.c`/`test.m`/`test.cpp`/`test.mm`.


Repository:
  rL LLVM

https://reviews.llvm.org/D26571

Files:
  test/ASTMerge/Inputs/anonymous-fields1.cpp
  test/ASTMerge/Inputs/anonymous-fields2.cpp
  test/ASTMerge/Inputs/asm-function.cpp
  test/ASTMerge/Inputs/body1.c
  test/ASTMerge/Inputs/body2.c
  test/ASTMerge/Inputs/category1.m
  test/ASTMerge/Inputs/category2.m
  test/ASTMerge/Inputs/class-template1.cpp
  test/ASTMerge/Inputs/class-template2.cpp
  test/ASTMerge/Inputs/class1.cpp
  test/ASTMerge/Inputs/class2.cpp
  test/ASTMerge/Inputs/class3.cpp
  test/ASTMerge/Inputs/enum1.c
  test/ASTMerge/Inputs/enum2.c
  test/ASTMerge/Inputs/exprs1.c
  test/ASTMerge/Inputs/exprs2.c
  test/ASTMerge/Inputs/exprs3.cpp
  test/ASTMerge/Inputs/function1.c
  test/ASTMerge/Inputs/function2.c
  test/ASTMerge/Inputs/inheritance-base.cpp
  test/ASTMerge/Inputs/init-ctors-classes.cpp
  test/ASTMerge/Inputs/interface1.m
  test/ASTMerge/Inputs/interface2.m
  test/ASTMerge/Inputs/macro.modulemap
  test/ASTMerge/Inputs/macro1.h
  test/ASTMerge/Inputs/macro1.m
  test/ASTMerge/Inputs/macro2.m
  test/ASTMerge/Inputs/namespace1.cpp
  test/ASTMerge/Inputs/namespace2.cpp
  test/ASTMerge/Inputs/property1.m
  test/ASTMerge/Inputs/property2.m
  test/ASTMerge/Inputs/struct1.c
  test/ASTMerge/Inputs/struct2.c
  test/ASTMerge/Inputs/typedef1.c
  test/ASTMerge/Inputs/typedef2.c
  test/ASTMerge/Inputs/var1.c
  test/ASTMerge/Inputs/var1.h
  test/ASTMerge/Inputs/var2.c
  test/ASTMerge/anonymous-fields.cpp
  test/ASTMerge/anonymous-fields/anonymous-fields1.cpp
  test/ASTMerge/anonymous-fields/anonymous-fields2.cpp
  test/ASTMerge/anonymous-fields/test.cpp
  test/ASTMerge/asm.cpp
  test/ASTMerge/asm/asm-function.cpp
  test/ASTMerge/asm/test.cpp
  test/ASTMerge/category.m
  test/ASTMerge/category/category1.m
  test/ASTMerge/category/category2.m
  test/ASTMerge/category/test.m
  test/ASTMerge/class-template.cpp
  test/ASTMerge/class-template/class-template1.cpp
  test/ASTMerge/class-template/class-template2.cpp
  test/ASTMerge/class-template/test.cpp
  test/ASTMerge/class.cpp
  test/ASTMerge/class/class1.cpp
  test/ASTMerge/class/class2.cpp
  test/ASTMerge/class/test.cpp
  test/ASTMerge/class2.cpp
  test/ASTMerge/class2/class3.cpp
  test/ASTMerge/class2/test.cpp
  test/ASTMerge/codegen-body.c
  test/ASTMerge/codegen-body/body1.c
  test/ASTMerge/codegen-body/body2.c
  test/ASTMerge/codegen-body/test.c
  test/ASTMerge/codegen-exprs.c
  test/ASTMerge/codegen-exprs/exprs1.c
  test/ASTMerge/codegen-exprs/exprs2.c
  test/ASTMerge/codegen-exprs/test.c
  test/ASTMerge/enum.c
  test/ASTMerge/enum/enum1.c
  test/ASTMerge/enum/enum2.c
  test/ASTMerge/enum/test.c
  test/ASTMerge/exprs-cpp/exprs3.cpp
  test/ASTMerge/exprs-cpp/test.cpp
  test/ASTMerge/exprs.c
  test/ASTMerge/exprs.cpp
  test/ASTMerge/exprs/exprs.c
  test/ASTMerge/exprs/exprs1.c
  test/ASTMerge/exprs/exprs2.c
  test/ASTMerge/function.c
  test/ASTMerge/function/function1.c
  test/ASTMerge/function/function2.c
  test/ASTMerge/function/test.c
  test/ASTMerge/inheritance.cpp
  test/ASTMerge/inheritance/inheritance-base.cpp
  test/ASTMerge/inheritance/test.cpp
  test/ASTMerge/init-ctors.cpp
  test/ASTMerge/init-ctors/init-ctors-classes.cpp
  test/ASTMerge/init-ctors/test.cpp
  test/ASTMerge/interface.m
  test/ASTMerge/interface/interface1.m
  test/ASTMerge/interface/interface2.m
  test/ASTMerge/interface/test.m
  test/ASTMerge/macro.m
  test/ASTMerge/macro/macro.modulemap
  test/ASTMerge/macro/macro1.h
  test/ASTMerge/macro/macro1.m
  test/ASTMerge/macro/macro2.m
  test/ASTMerge/macro/test.m
  test/ASTMerge/namespace.cpp
  test/ASTMerge/namespace/namespace1.cpp
  test/ASTMerge/namespace/namespace2.cpp
  test/ASTMerge/namespace/test.cpp
  test/ASTMerge/property.m
  test/ASTMerge/property/property1.m
  test/ASTMerge/property/property2.m
  test/ASTMerge/property/test.m
  test/ASTMerge/struct.c
  test/ASTMerge/struct/struct1.c
  test/ASTMerge/struct/struct2.c
  test/ASTMerge/struct/test.c
  test/ASTMerge/typedef.c
  test/ASTMerge/typedef/test.c
  test/ASTMerge/typedef/typedef1.c
  test/ASTMerge/typedef/typedef2.c
  

r286151 - Updated ASTMerge/macro.m to use _Nullable.

2016-11-07 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Mon Nov  7 15:10:31 2016
New Revision: 286151

URL: http://llvm.org/viewvc/llvm-project?rev=286151=rev
Log:
Updated ASTMerge/macro.m to use _Nullable.

Modified:
cfe/trunk/test/ASTMerge/Inputs/macro1.h

Modified: cfe/trunk/test/ASTMerge/Inputs/macro1.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/macro1.h?rev=286151=286150=286151=diff
==
--- cfe/trunk/test/ASTMerge/Inputs/macro1.h (original)
+++ cfe/trunk/test/ASTMerge/Inputs/macro1.h Mon Nov  7 15:10:31 2016
@@ -2,4 +2,4 @@ typedef void *VoidRef;
 
 void maybeNull(
   int i,
-  __nullable VoidRef *__nullable);
+  _Nullable VoidRef *_Nullable);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26054: Use `getFileLoc()` instead of `getSpellingLoc()` in the ASTImporter

2016-11-07 Thread Sean Callanan via cfe-commits
spyffe added a comment.

Fixed the testcase to use _Nullable instead of __nullable, for Linux buildbots

  $ svn commit test
  Sendingtest/ASTMerge/Inputs/macro1.h
  Transmitting file data .done
  Committing transaction...
  Committed revision 286151.


https://reviews.llvm.org/D26054



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26054: Use `getFileLoc()` instead of `getSpellingLoc()` in the ASTImporter

2016-11-07 Thread Sean Callanan via cfe-commits
spyffe closed this revision.
spyffe added a comment.

  $ svn commit lib test
  Sendinglib/AST/ASTImporter.cpp
  Adding test/ASTMerge/Inputs/macro.modulemap
  Adding test/ASTMerge/Inputs/macro1.h
  Adding test/ASTMerge/Inputs/macro1.m
  Adding test/ASTMerge/Inputs/macro2.m
  Adding test/ASTMerge/macro.m
  Transmitting file data ..done
  Committing transaction...
  Committed revision 286144.


https://reviews.llvm.org/D26054



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r286144 - When the ASTImporter imports a source location, it avoids importing macro

2016-11-07 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Mon Nov  7 14:42:25 2016
New Revision: 286144

URL: http://llvm.org/viewvc/llvm-project?rev=286144=rev
Log:
When the ASTImporter imports a source location, it avoids importing macro
expansions by calling getSpellingLoc(). That's great in most cases, but for
macros defined in the '' source file, the source file is invalid
and does not import correctly, causing an assertion failure (the assertion
is Invalid SLocOffset or bad function choice).

A more reliable way to avoid this is to use getFileLoc(), which does not
return built-in locations. This avoids the crash but still preserves valid
source locations.

I've added a testcase that covers the previously crashing scenario.

https://reviews.llvm.org/D26054

Added:
cfe/trunk/test/ASTMerge/Inputs/macro.modulemap
cfe/trunk/test/ASTMerge/Inputs/macro1.h
cfe/trunk/test/ASTMerge/Inputs/macro1.m
cfe/trunk/test/ASTMerge/Inputs/macro2.m
cfe/trunk/test/ASTMerge/macro.m
Modified:
cfe/trunk/lib/AST/ASTImporter.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=286144=286143=286144=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Mon Nov  7 14:42:25 2016
@@ -6943,10 +6943,10 @@ SourceLocation ASTImporter::Import(Sourc
 
   SourceManager  = FromContext.getSourceManager();
   
-  // For now, map everything down to its spelling location, so that we
+  // For now, map everything down to its file location, so that we
   // don't have to import macro expansions.
   // FIXME: Import macro expansions!
-  FromLoc = FromSM.getSpellingLoc(FromLoc);
+  FromLoc = FromSM.getFileLoc(FromLoc);
   std::pair Decomposed = FromSM.getDecomposedLoc(FromLoc);
   SourceManager  = ToContext.getSourceManager();
   FileID ToFileID = Import(Decomposed.first);

Added: cfe/trunk/test/ASTMerge/Inputs/macro.modulemap
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/macro.modulemap?rev=286144=auto
==
--- cfe/trunk/test/ASTMerge/Inputs/macro.modulemap (added)
+++ cfe/trunk/test/ASTMerge/Inputs/macro.modulemap Mon Nov  7 14:42:25 2016
@@ -0,0 +1,4 @@
+module macro1 [extern_c] {
+  header "macro1.h"
+  export *
+}

Added: cfe/trunk/test/ASTMerge/Inputs/macro1.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/macro1.h?rev=286144=auto
==
--- cfe/trunk/test/ASTMerge/Inputs/macro1.h (added)
+++ cfe/trunk/test/ASTMerge/Inputs/macro1.h Mon Nov  7 14:42:25 2016
@@ -0,0 +1,5 @@
+typedef void *VoidRef;
+
+void maybeNull(
+  int i,
+  __nullable VoidRef *__nullable);

Added: cfe/trunk/test/ASTMerge/Inputs/macro1.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/macro1.m?rev=286144=auto
==
--- cfe/trunk/test/ASTMerge/Inputs/macro1.m (added)
+++ cfe/trunk/test/ASTMerge/Inputs/macro1.m Mon Nov  7 14:42:25 2016
@@ -0,0 +1,5 @@
+@import macro1;
+
+void foo() {
+  maybeNull(0, 0);
+}

Added: cfe/trunk/test/ASTMerge/Inputs/macro2.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/macro2.m?rev=286144=auto
==
--- cfe/trunk/test/ASTMerge/Inputs/macro2.m (added)
+++ cfe/trunk/test/ASTMerge/Inputs/macro2.m Mon Nov  7 14:42:25 2016
@@ -0,0 +1,5 @@
+void foo();
+
+void bar() {
+  foo();
+}

Added: cfe/trunk/test/ASTMerge/macro.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/macro.m?rev=286144=auto
==
--- cfe/trunk/test/ASTMerge/macro.m (added)
+++ cfe/trunk/test/ASTMerge/macro.m Mon Nov  7 14:42:25 2016
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/cache
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache 
-fmodule-map-file=%S/Inputs/macro.modulemap -I%S/Inputs -emit-pch -o %t.1.ast 
%S/Inputs/macro1.m
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache 
-fmodule-map-file=%S/Inputs/macro.modulemap -I%S/Inputs -emit-pch -o %t.2.ast 
%S/Inputs/macro2.m
+// RUN: %clang_cc1 -fmodules -ast-merge %t.1.ast -ast-merge %t.2.ast 
-fsyntax-only -verify %s
+// expected-no-diagnostics


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26054: Use `getFileLoc()` instead of `getSpellingLoc()` in the ASTImporter

2016-11-07 Thread Sean Callanan via cfe-commits
spyffe added a comment.

That seems reasonable, and would go a long way toward cleaning up the `Inputs` 
and making clear exactly which inputs correspond to which test file.
Do you think it would be reasonable to take this diff the way it currently it 
is, and start a new one that pulls all the input fiels into test-specific 
subdirectories?
That way the desired layout of the `Inputs` directory will be clear to future 
developers touching the source base.


https://reviews.llvm.org/D26054



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26328: [ASTImporter] Added ability to import AtomicType nodes

2016-11-07 Thread Sean Callanan via cfe-commits
spyffe accepted this revision.
spyffe added a comment.
This revision is now accepted and ready to land.

Looks good to me.  Thanks, Kareem!


https://reviews.llvm.org/D26328



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26054: Use `getFileLoc()` instead of `getSpellingLoc()` in the ASTImporter

2016-11-07 Thread Sean Callanan via cfe-commits
spyffe added a comment.

Aleksei, thank you for your review.
I don't quite follow what you'd like me to do with the `Input` files, though.  
Some of them certainly appear to be input files in the same way that all the 
other files in `Inputs` are.  Are you suggesting that I move `macro.modulemap` 
and `macro1.h` somewhere else (say, `Modules/`) or are you making a general 
comment about the layout of all of the tests?


https://reviews.llvm.org/D26054



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26054: Use `getFileLoc()` instead of `getSpellingLoc()` in the ASTImporter

2016-10-28 Thread Sean Callanan via cfe-commits
spyffe updated this revision to Diff 76213.
spyffe added a comment.

Updated the corresponding comment.


https://reviews.llvm.org/D26054

Files:
  lib/AST/ASTImporter.cpp
  test/ASTMerge/Inputs/macro.modulemap
  test/ASTMerge/Inputs/macro1.h
  test/ASTMerge/Inputs/macro1.m
  test/ASTMerge/Inputs/macro2.m
  test/ASTMerge/macro.m


Index: test/ASTMerge/macro.m
===
--- test/ASTMerge/macro.m
+++ test/ASTMerge/macro.m
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/cache
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache 
-fmodule-map-file=%S/Inputs/macro.modulemap -I%S/Inputs -emit-pch -o %t.1.ast 
%S/Inputs/macro1.m
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache 
-fmodule-map-file=%S/Inputs/macro.modulemap -I%S/Inputs -emit-pch -o %t.2.ast 
%S/Inputs/macro2.m
+// RUN: %clang_cc1 -fmodules -ast-merge %t.1.ast -ast-merge %t.2.ast 
-fsyntax-only -verify %s
+// expected-no-diagnostics
Index: test/ASTMerge/Inputs/macro2.m
===
--- test/ASTMerge/Inputs/macro2.m
+++ test/ASTMerge/Inputs/macro2.m
@@ -0,0 +1,5 @@
+void foo();
+
+void bar() {
+  foo();
+}
Index: test/ASTMerge/Inputs/macro1.m
===
--- test/ASTMerge/Inputs/macro1.m
+++ test/ASTMerge/Inputs/macro1.m
@@ -0,0 +1,5 @@
+@import macro1;
+
+void foo() {
+  maybeNull(0, 0);
+}
Index: test/ASTMerge/Inputs/macro1.h
===
--- test/ASTMerge/Inputs/macro1.h
+++ test/ASTMerge/Inputs/macro1.h
@@ -0,0 +1,5 @@
+typedef void *VoidRef;
+
+void maybeNull(
+  int i,
+  __nullable VoidRef *__nullable);
Index: test/ASTMerge/Inputs/macro.modulemap
===
--- test/ASTMerge/Inputs/macro.modulemap
+++ test/ASTMerge/Inputs/macro.modulemap
@@ -0,0 +1,4 @@
+module macro1 [extern_c] {
+  header "macro1.h"
+  export *
+}
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -6943,10 +6943,10 @@
 
   SourceManager  = FromContext.getSourceManager();
   
-  // For now, map everything down to its spelling location, so that we
+  // For now, map everything down to its file location, so that we
   // don't have to import macro expansions.
   // FIXME: Import macro expansions!
-  FromLoc = FromSM.getSpellingLoc(FromLoc);
+  FromLoc = FromSM.getFileLoc(FromLoc);
   std::pair Decomposed = FromSM.getDecomposedLoc(FromLoc);
   SourceManager  = ToContext.getSourceManager();
   FileID ToFileID = Import(Decomposed.first);


Index: test/ASTMerge/macro.m
===
--- test/ASTMerge/macro.m
+++ test/ASTMerge/macro.m
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/cache
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache -fmodule-map-file=%S/Inputs/macro.modulemap -I%S/Inputs -emit-pch -o %t.1.ast %S/Inputs/macro1.m
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache -fmodule-map-file=%S/Inputs/macro.modulemap -I%S/Inputs -emit-pch -o %t.2.ast %S/Inputs/macro2.m
+// RUN: %clang_cc1 -fmodules -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only -verify %s
+// expected-no-diagnostics
Index: test/ASTMerge/Inputs/macro2.m
===
--- test/ASTMerge/Inputs/macro2.m
+++ test/ASTMerge/Inputs/macro2.m
@@ -0,0 +1,5 @@
+void foo();
+
+void bar() {
+  foo();
+}
Index: test/ASTMerge/Inputs/macro1.m
===
--- test/ASTMerge/Inputs/macro1.m
+++ test/ASTMerge/Inputs/macro1.m
@@ -0,0 +1,5 @@
+@import macro1;
+
+void foo() {
+  maybeNull(0, 0);
+}
Index: test/ASTMerge/Inputs/macro1.h
===
--- test/ASTMerge/Inputs/macro1.h
+++ test/ASTMerge/Inputs/macro1.h
@@ -0,0 +1,5 @@
+typedef void *VoidRef;
+
+void maybeNull(
+  int i,
+  __nullable VoidRef *__nullable);
Index: test/ASTMerge/Inputs/macro.modulemap
===
--- test/ASTMerge/Inputs/macro.modulemap
+++ test/ASTMerge/Inputs/macro.modulemap
@@ -0,0 +1,4 @@
+module macro1 [extern_c] {
+  header "macro1.h"
+  export *
+}
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -6943,10 +6943,10 @@
 
   SourceManager  = FromContext.getSourceManager();
   
-  // For now, map everything down to its spelling location, so that we
+  // For now, map everything down to its file location, so that we
   // don't have to import macro expansions.
   // FIXME: Import macro expansions!
-  FromLoc = FromSM.getSpellingLoc(FromLoc);
+  FromLoc = FromSM.getFileLoc(FromLoc);
   std::pair 

[PATCH] D26054: Use `getFileLoc()` instead of `getSpellingLoc()` in the ASTImporter

2016-10-27 Thread Sean Callanan via cfe-commits
spyffe created this revision.
spyffe added reviewers: bruno, akyrtzi, a.sidorin.
spyffe added a subscriber: cfe-commits.

When the `ASTImporter`imports a source location, it avoids importing macro 
expansions by calling `getSpellingLoc()`.  That's great in most cases, but for 
macros defined in the '' source file, the source file is invalid and 
does not import correctly, causing an assertion failure (the assertion is 
`Invalid SLocOffset or bad function choice`).

A more reliable way to avoid this is to use `getFileLoc()`, which does not 
return built-in locations.  This avoids the crash but still preserves valid 
source locations.

I've added a testcase that covers the previously crashing scenario.


https://reviews.llvm.org/D26054

Files:
  lib/AST/ASTImporter.cpp
  test/ASTMerge/Inputs/macro.modulemap
  test/ASTMerge/Inputs/macro1.h
  test/ASTMerge/Inputs/macro1.m
  test/ASTMerge/Inputs/macro2.m
  test/ASTMerge/macro.m


Index: test/ASTMerge/macro.m
===
--- test/ASTMerge/macro.m
+++ test/ASTMerge/macro.m
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/cache
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache 
-fmodule-map-file=%S/Inputs/macro.modulemap -I%S/Inputs -emit-pch -o %t.1.ast 
%S/Inputs/macro1.m
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache 
-fmodule-map-file=%S/Inputs/macro.modulemap -I%S/Inputs -emit-pch -o %t.2.ast 
%S/Inputs/macro2.m
+// RUN: %clang_cc1 -fmodules -ast-merge %t.1.ast -ast-merge %t.2.ast 
-fsyntax-only -verify %s
+// expected-no-diagnostics
Index: test/ASTMerge/Inputs/macro2.m
===
--- test/ASTMerge/Inputs/macro2.m
+++ test/ASTMerge/Inputs/macro2.m
@@ -0,0 +1,5 @@
+void foo();
+
+void bar() {
+  foo();
+}
Index: test/ASTMerge/Inputs/macro1.m
===
--- test/ASTMerge/Inputs/macro1.m
+++ test/ASTMerge/Inputs/macro1.m
@@ -0,0 +1,5 @@
+@import macro1;
+
+void foo() {
+  maybeNull(0, 0);
+}
Index: test/ASTMerge/Inputs/macro1.h
===
--- test/ASTMerge/Inputs/macro1.h
+++ test/ASTMerge/Inputs/macro1.h
@@ -0,0 +1,5 @@
+typedef void *VoidRef;
+
+void maybeNull(
+  int i,
+  __nullable VoidRef *__nullable);
Index: test/ASTMerge/Inputs/macro.modulemap
===
--- test/ASTMerge/Inputs/macro.modulemap
+++ test/ASTMerge/Inputs/macro.modulemap
@@ -0,0 +1,4 @@
+module macro1 [extern_c] {
+  header "macro1.h"
+  export *
+}
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -6946,7 +6946,7 @@
   // For now, map everything down to its spelling location, so that we
   // don't have to import macro expansions.
   // FIXME: Import macro expansions!
-  FromLoc = FromSM.getSpellingLoc(FromLoc);
+  FromLoc = FromSM.getFileLoc(FromLoc);
   std::pair Decomposed = FromSM.getDecomposedLoc(FromLoc);
   SourceManager  = ToContext.getSourceManager();
   FileID ToFileID = Import(Decomposed.first);


Index: test/ASTMerge/macro.m
===
--- test/ASTMerge/macro.m
+++ test/ASTMerge/macro.m
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/cache
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache -fmodule-map-file=%S/Inputs/macro.modulemap -I%S/Inputs -emit-pch -o %t.1.ast %S/Inputs/macro1.m
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache -fmodule-map-file=%S/Inputs/macro.modulemap -I%S/Inputs -emit-pch -o %t.2.ast %S/Inputs/macro2.m
+// RUN: %clang_cc1 -fmodules -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only -verify %s
+// expected-no-diagnostics
Index: test/ASTMerge/Inputs/macro2.m
===
--- test/ASTMerge/Inputs/macro2.m
+++ test/ASTMerge/Inputs/macro2.m
@@ -0,0 +1,5 @@
+void foo();
+
+void bar() {
+  foo();
+}
Index: test/ASTMerge/Inputs/macro1.m
===
--- test/ASTMerge/Inputs/macro1.m
+++ test/ASTMerge/Inputs/macro1.m
@@ -0,0 +1,5 @@
+@import macro1;
+
+void foo() {
+  maybeNull(0, 0);
+}
Index: test/ASTMerge/Inputs/macro1.h
===
--- test/ASTMerge/Inputs/macro1.h
+++ test/ASTMerge/Inputs/macro1.h
@@ -0,0 +1,5 @@
+typedef void *VoidRef;
+
+void maybeNull(
+  int i,
+  __nullable VoidRef *__nullable);
Index: test/ASTMerge/Inputs/macro.modulemap
===
--- test/ASTMerge/Inputs/macro.modulemap
+++ test/ASTMerge/Inputs/macro.modulemap
@@ -0,0 +1,4 @@
+module macro1 [extern_c] {
+  header "macro1.h"
+  export *
+}
Index: lib/AST/ASTImporter.cpp
===
--- 

Re: [PATCH] D14326: ASTImporter: expressions, pt.2

2016-08-23 Thread Sean Callanan via cfe-commits
spyffe accepted this revision.
spyffe added a comment.
This revision is now accepted and ready to land.

Yes, I look forward to testing this in LLDB.  Thanks for your hard work.


https://reviews.llvm.org/D14326



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r275460 - When importing classes and structs with anonymous structs, it is critical that

2016-07-14 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Thu Jul 14 14:53:44 2016
New Revision: 275460

URL: http://llvm.org/viewvc/llvm-project?rev=275460=rev
Log:
When importing classes and structs with anonymous structs, it is critical that
distinct anonymous structs remain distinct despite having similar layout.

This is already ensured by distinguishing based on their placement in the parent
struct, using the function `findAnonymousStructOrUnionIndex`.

The problem is that this function only handles anonymous structs, like
```
class Foo { struct { int a; } }
```
and not untagged structs like
```
class Foo { struct { int a; } var; }
```
Both need to be handled, and this patch fixes that.  The test case ensures that 
this functionality doesn't regress.

Thanks to Manman Ren for review.

https://reviews.llvm.org/D22270

Added:
cfe/trunk/test/ASTMerge/Inputs/anonymous-fields1.cpp
cfe/trunk/test/ASTMerge/Inputs/anonymous-fields2.cpp
cfe/trunk/test/ASTMerge/anonymous-fields.cpp
Modified:
cfe/trunk/lib/AST/ASTImporter.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=275460=275459=275460=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Thu Jul 14 14:53:44 2016
@@ -1029,7 +1029,7 @@ static bool IsStructurallyEquivalent(Str
 /// including the next assigned index (if none of them match). Returns an
 /// empty option if the context is not a record, i.e.. if the anonymous
 /// struct/union is at namespace or block scope.
-static Optional findAnonymousStructOrUnionIndex(RecordDecl *Anon) {
+static Optional findUntaggedStructOrUnionIndex(RecordDecl *Anon) {
   ASTContext  = Anon->getASTContext();
   QualType AnonTy = Context.getRecordType(Anon);
 
@@ -1040,13 +1040,29 @@ static Optional findAnonymousS
   unsigned Index = 0;
   for (const auto *D : Owner->noload_decls()) {
 const auto *F = dyn_cast(D);
-if (!F || !F->isAnonymousStructOrUnion())
+if (!F)
   continue;
 
-if (Context.hasSameType(F->getType(), AnonTy))
-  break;
+if (F->isAnonymousStructOrUnion()) {
+  if (Context.hasSameType(F->getType(), AnonTy))
+break;
+  ++Index;
+  continue;
+}
 
-++Index;
+// If the field looks like this:
+// struct { ... } A;
+QualType FieldType = F->getType();
+if (const auto *RecType = dyn_cast(FieldType)) {
+  const RecordDecl *RecDecl = RecType->getDecl();
+  if (RecDecl->getDeclContext() == Owner &&
+  !RecDecl->getIdentifier()) {
+if (Context.hasSameType(FieldType, AnonTy))
+  break;
+++Index;
+continue;
+  }
+}
   }
 
   return Index;
@@ -1068,8 +1084,8 @@ static bool IsStructurallyEquivalent(Str
   if (D1->isAnonymousStructOrUnion() && D2->isAnonymousStructOrUnion()) {
 // If both anonymous structs/unions are in a record context, make sure
 // they occur in the same location in the context records.
-if (Optional Index1 = findAnonymousStructOrUnionIndex(D1)) {
-  if (Optional Index2 = findAnonymousStructOrUnionIndex(D2)) {
+if (Optional Index1 = findUntaggedStructOrUnionIndex(D1)) {
+  if (Optional Index2 = findUntaggedStructOrUnionIndex(D2)) {
 if (*Index1 != *Index2)
   return false;
   }
@@ -2749,9 +2765,9 @@ Decl *ASTNodeImporter::VisitRecordDecl(R
   // If both anonymous structs/unions are in a record context, make 
sure
   // they occur in the same location in the context records.
   if (Optional Index1
-  = findAnonymousStructOrUnionIndex(D)) {
+  = findUntaggedStructOrUnionIndex(D)) {
 if (Optional Index2 =
-findAnonymousStructOrUnionIndex(FoundRecord)) {
+findUntaggedStructOrUnionIndex(FoundRecord)) {
   if (*Index1 != *Index2)
 continue;
 }

Added: cfe/trunk/test/ASTMerge/Inputs/anonymous-fields1.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/anonymous-fields1.cpp?rev=275460=auto
==
--- cfe/trunk/test/ASTMerge/Inputs/anonymous-fields1.cpp (added)
+++ cfe/trunk/test/ASTMerge/Inputs/anonymous-fields1.cpp Thu Jul 14 14:53:44 
2016
@@ -0,0 +1,5 @@
+class A {
+public:
+  struct { int foo; } f;
+  struct { int foo; } g;
+};

Added: cfe/trunk/test/ASTMerge/Inputs/anonymous-fields2.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/anonymous-fields2.cpp?rev=275460=auto
==
--- cfe/trunk/test/ASTMerge/Inputs/anonymous-fields2.cpp (added)
+++ cfe/trunk/test/ASTMerge/Inputs/anonymous-fields2.cpp Thu Jul 14 14:53:44 
2016
@@ -0,0 +1,9 @@
+class A {
+public:
+  struct { int foo; } f;
+  struct { int foo; } g;
+};
+
+inline int useA(A ) {

Re: [PATCH] D22270: [ASTImporter] Properly report the locations of anonymous structs declared as part of named fields

2016-07-13 Thread Sean Callanan via cfe-commits
spyffe updated this revision to Diff 63894.
spyffe added a comment.

Applied Manman's changes:

- `const auto*` instead of `const RecordType*`
- kept the if's separate because I...
- ...moved the `Index++` and `continue` in so that we only increment the 
counter when we're really dealing with something untagged
- changed the function name to `findUntaggedStructOrUnionIndex`


Repository:
  rL LLVM

http://reviews.llvm.org/D22270

Files:
  lib/AST/ASTImporter.cpp
  test/ASTMerge/Inputs/anonymous-fields1.cpp
  test/ASTMerge/Inputs/anonymous-fields2.cpp
  test/ASTMerge/anonymous-fields.cpp

Index: test/ASTMerge/anonymous-fields.cpp
===
--- /dev/null
+++ test/ASTMerge/anonymous-fields.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/anonymous-fields1.cpp
+// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/anonymous-fields2.cpp
+// RUN: %clang_cc1 -emit-obj -o /dev/null -ast-merge %t.1.ast -ast-merge %t.2.ast %s
+// expected-no-diagnostics
Index: test/ASTMerge/Inputs/anonymous-fields2.cpp
===
--- /dev/null
+++ test/ASTMerge/Inputs/anonymous-fields2.cpp
@@ -0,0 +1,9 @@
+class A {
+public:
+  struct { int foo; } f;
+  struct { int foo; } g;
+};
+
+inline int useA(A ) {
+  return (a.f.foo + a.g.foo);
+}
Index: test/ASTMerge/Inputs/anonymous-fields1.cpp
===
--- /dev/null
+++ test/ASTMerge/Inputs/anonymous-fields1.cpp
@@ -0,0 +1,5 @@
+class A {
+public:
+  struct { int foo; } f;
+  struct { int foo; } g;
+};
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -1029,7 +1029,7 @@
 /// including the next assigned index (if none of them match). Returns an
 /// empty option if the context is not a record, i.e.. if the anonymous
 /// struct/union is at namespace or block scope.
-static Optional findAnonymousStructOrUnionIndex(RecordDecl *Anon) {
+static Optional findUntaggedStructOrUnionIndex(RecordDecl *Anon) {
   ASTContext  = Anon->getASTContext();
   QualType AnonTy = Context.getRecordType(Anon);
 
@@ -1040,13 +1040,29 @@
   unsigned Index = 0;
   for (const auto *D : Owner->noload_decls()) {
 const auto *F = dyn_cast(D);
-if (!F || !F->isAnonymousStructOrUnion())
+if (!F)
   continue;
 
-if (Context.hasSameType(F->getType(), AnonTy))
-  break;
+if (F->isAnonymousStructOrUnion()) {
+  if (Context.hasSameType(F->getType(), AnonTy))
+break;
+  ++Index;
+  continue;
+}
 
-++Index;
+// If the field looks like this:
+// struct { ... } A;
+QualType FieldType = F->getType();
+if (const auto *RecType = dyn_cast(FieldType)) {
+  const RecordDecl *RecDecl = RecType->getDecl();
+  if (RecDecl->getDeclContext() == Owner &&
+  !RecDecl->getIdentifier()) {
+if (Context.hasSameType(FieldType, AnonTy))
+  break;
+++Index;
+continue;
+  }
+}
   }
 
   return Index;
@@ -1068,8 +1084,8 @@
   if (D1->isAnonymousStructOrUnion() && D2->isAnonymousStructOrUnion()) {
 // If both anonymous structs/unions are in a record context, make sure
 // they occur in the same location in the context records.
-if (Optional Index1 = findAnonymousStructOrUnionIndex(D1)) {
-  if (Optional Index2 = findAnonymousStructOrUnionIndex(D2)) {
+if (Optional Index1 = findUntaggedStructOrUnionIndex(D1)) {
+  if (Optional Index2 = findUntaggedStructOrUnionIndex(D2)) {
 if (*Index1 != *Index2)
   return false;
   }
@@ -2749,9 +2765,9 @@
   // If both anonymous structs/unions are in a record context, make sure
   // they occur in the same location in the context records.
   if (Optional Index1
-  = findAnonymousStructOrUnionIndex(D)) {
+  = findUntaggedStructOrUnionIndex(D)) {
 if (Optional Index2 =
-findAnonymousStructOrUnionIndex(FoundRecord)) {
+findUntaggedStructOrUnionIndex(FoundRecord)) {
   if (*Index1 != *Index2)
 continue;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22270: [ASTImporter] Properly report the locations of anonymous structs declared as part of named fields

2016-07-13 Thread Sean Callanan via cfe-commits
spyffe added a comment.

I mean `findUntaggedStructOrUnionIndex`


Repository:
  rL LLVM

http://reviews.llvm.org/D22270



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22270: [ASTImporter] Properly report the locations of anonymous structs declared as part of named fields

2016-07-13 Thread Sean Callanan via cfe-commits
spyffe added a comment.

Thank you very much for your review, Manman!  I can implement all your 
individual fixes, those look fine.  In answer to two of your bigger questions, 
though:

- I see what you mean about the definition of an anonymous structure.  It looks 
like our structure is an //untagged// structure, not an //anonymous// one.  
That said, this change is safe for all the places that use this function, so it 
may be appropriate to change the name to `findAnonymousStructOrUnionIndex`.  
What do you think?
- The test case is unfortunately only an approximation to the more complicated 
behavior that occurs in lldb.  The difference is that the testing 
infrastructure inside Clang does not implement an ExternalASTSource, which LLDB 
does.  As a result, I've used the test case to verify that we don't break 
parsing by making this change.


Repository:
  rL LLVM

http://reviews.llvm.org/D22270



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D22270: [ASTImporter] Properly report the locations of anonymous structs declared as part of named fields

2016-07-12 Thread Sean Callanan via cfe-commits
spyffe created this revision.
spyffe added a reviewer: manmanren.
spyffe added a subscriber: cfe-commits.
spyffe set the repository for this revision to rL LLVM.

When importing classes and structs with anonymous structs, it is critical that 
distinct anonymous structs remain distinct despite having similar layout.
This is already ensured by distinguishing based on their placement in the 
parent struct, using the function `findAnonymousStructOrUnionIndex`.
The problem is that this function only handles 
```
class Foo { struct { int a; } }
```
and not
```
class Foo { struct { int a; } var; }
```
Both need to be handled, and this patch fixes that.  The test case ensures that 
this functionality doesn't regress.

Repository:
  rL LLVM

http://reviews.llvm.org/D22270

Files:
  lib/AST/ASTImporter.cpp
  test/ASTMerge/Inputs/anonymous-fields1.cpp
  test/ASTMerge/Inputs/anonymous-fields2.cpp
  test/ASTMerge/anonymous-fields.cpp

Index: test/ASTMerge/anonymous-fields.cpp
===
--- /dev/null
+++ test/ASTMerge/anonymous-fields.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/anonymous-fields1.cpp
+// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/anonymous-fields2.cpp
+// RUN: %clang_cc1 -emit-obj -o /dev/null -ast-merge %t.1.ast -ast-merge 
%t.2.ast %s
+// expected-no-diagnostics
Index: test/ASTMerge/Inputs/anonymous-fields2.cpp
===
--- /dev/null
+++ test/ASTMerge/Inputs/anonymous-fields2.cpp
@@ -0,0 +1,9 @@
+class A {
+public:
+  struct { int foo; } f;
+  struct { int foo; } g;
+};
+
+inline int useA(A ) {
+  return (a.f.foo + a.g.foo);
+}
Index: test/ASTMerge/Inputs/anonymous-fields1.cpp
===
--- /dev/null
+++ test/ASTMerge/Inputs/anonymous-fields1.cpp
@@ -0,0 +1,5 @@
+class A {
+public:
+  struct { int foo; } f;
+  struct { int foo; } g;
+};
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -1040,11 +1040,27 @@
   unsigned Index = 0;
   for (const auto *D : Owner->noload_decls()) {
 const auto *F = dyn_cast(D);
-if (!F || !F->isAnonymousStructOrUnion())
+if (!F)
   continue;
-
-if (Context.hasSameType(F->getType(), AnonTy))
-  break;
+  
+if (F->isAnonymousStructOrUnion()) {
+  if (Context.hasSameType(F->getType(), AnonTy)) {
+break;
+  }
+} else {
+  // If the field looks like this:
+  // struct { ... } A;
+  QualType FieldType = F->getType();
+  if (const RecordType *RecType = dyn_cast(FieldType)) {
+const RecordDecl *RecDecl = RecType->getDecl();
+if (RecDecl->getDeclContext() == Owner &&
+!RecDecl->getIdentifier()) {
+  if (Context.hasSameType(FieldType, AnonTy)) {
+break;
+  }
+}
+  }
+}
 
 ++Index;
   }


Index: test/ASTMerge/anonymous-fields.cpp
===
--- /dev/null
+++ test/ASTMerge/anonymous-fields.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/anonymous-fields1.cpp
+// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/anonymous-fields2.cpp
+// RUN: %clang_cc1 -emit-obj -o /dev/null -ast-merge %t.1.ast -ast-merge %t.2.ast %s
+// expected-no-diagnostics
Index: test/ASTMerge/Inputs/anonymous-fields2.cpp
===
--- /dev/null
+++ test/ASTMerge/Inputs/anonymous-fields2.cpp
@@ -0,0 +1,9 @@
+class A {
+public:
+  struct { int foo; } f;
+  struct { int foo; } g;
+};
+
+inline int useA(A ) {
+  return (a.f.foo + a.g.foo);
+}
Index: test/ASTMerge/Inputs/anonymous-fields1.cpp
===
--- /dev/null
+++ test/ASTMerge/Inputs/anonymous-fields1.cpp
@@ -0,0 +1,5 @@
+class A {
+public:
+  struct { int foo; } f;
+  struct { int foo; } g;
+};
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -1040,11 +1040,27 @@
   unsigned Index = 0;
   for (const auto *D : Owner->noload_decls()) {
 const auto *F = dyn_cast(D);
-if (!F || !F->isAnonymousStructOrUnion())
+if (!F)
   continue;
-
-if (Context.hasSameType(F->getType(), AnonTy))
-  break;
+  
+if (F->isAnonymousStructOrUnion()) {
+  if (Context.hasSameType(F->getType(), AnonTy)) {
+break;
+  }
+} else {
+  // If the field looks like this:
+  // struct { ... } A;
+  QualType FieldType = F->getType();
+  if (const RecordType *RecType = dyn_cast(FieldType)) {
+const RecordDecl *RecDecl = RecType->getDecl();
+if (RecDecl->getDeclContext() == Owner &&
+!RecDecl->getIdentifier()) {
+  if (Context.hasSameType(FieldType, 

r269693 - Added support to the ASTImporter for C++ constructor initializers.

2016-05-16 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Mon May 16 15:48:03 2016
New Revision: 269693

URL: http://llvm.org/viewvc/llvm-project?rev=269693=rev
Log:
Added support to the ASTImporter for C++ constructor initializers.
Also added named casts and propagation of "implicit" to fix the LLDB testsuite.
This is a fixed commit of r269546, which was reverted by r269575.

Thanks to Aleksei Sidorin for review and advice.

Added:
cfe/trunk/test/ASTMerge/Inputs/init-ctors-classes.cpp
cfe/trunk/test/ASTMerge/init-ctors.cpp
Modified:
cfe/trunk/include/clang/AST/ASTImporter.h
cfe/trunk/lib/AST/ASTImporter.cpp

Modified: cfe/trunk/include/clang/AST/ASTImporter.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTImporter.h?rev=269693=269692=269693=diff
==
--- cfe/trunk/include/clang/AST/ASTImporter.h (original)
+++ cfe/trunk/include/clang/AST/ASTImporter.h Mon May 16 15:48:03 2016
@@ -23,6 +23,7 @@
 
 namespace clang {
   class ASTContext;
+  class CXXCtorInitializer;
   class Decl;
   class DeclContext;
   class DiagnosticsEngine;
@@ -204,6 +205,14 @@ namespace clang {
 /// \returns the equivalent file ID in the source manager of the "to"
 /// context.
 FileID Import(FileID);
+
+/// \brief Import the given C++ constructor initializer from the "from"
+/// context into the "to" context.
+///
+/// \returns the equivalent initializer in the "to" context.
+CXXCtorInitializer *Import(CXXCtorInitializer *FromInit);
+
+
 
 /// \brief Import the definition of the given declaration, including all of
 /// the declarations it contains.

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=269693=269692=269693=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Mon May 16 15:48:03 2016
@@ -252,6 +252,8 @@ namespace clang {
 Expr *VisitMemberExpr(MemberExpr *E);
 Expr *VisitCallExpr(CallExpr *E);
 Expr *VisitInitListExpr(InitListExpr *E);
+Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
+Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
 
 template
 void ImportArray(IIter Ibegin, IIter Iend, OIter Obegin) {
@@ -3029,6 +3031,22 @@ Decl *ASTNodeImporter::VisitFunctionDecl
 D->isInlineSpecified(), 
 D->isImplicit(),
 D->isConstexpr());
+if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
+  SmallVector CtorInitializers;
+  for (CXXCtorInitializer *I : FromConstructor->inits()) {
+CXXCtorInitializer *ToI =
+cast_or_null(Importer.Import(I));
+if (!ToI && I)
+  return nullptr;
+CtorInitializers.push_back(ToI);
+  }
+  CXXCtorInitializer **Memory =
+  new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
+  std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
+  CXXConstructorDecl *ToCtor = llvm::cast(ToFunction);
+  ToCtor->setCtorInitializers(Memory);
+  ToCtor->setNumCtorInitializers(NumInitializers);
+}
   } else if (isa(D)) {
 ToFunction = CXXDestructorDecl::Create(Importer.getToContext(),
cast(DC),
@@ -5779,12 +5797,12 @@ Expr *ASTNodeImporter::VisitCXXConstruct
 return nullptr;
 
   NamedDecl *ToFound =
-dyn_cast(Importer.Import(E->getFoundDecl()));
+dyn_cast_or_null(Importer.Import(E->getFoundDecl()));
   if (!ToFound)
 return nullptr;
 
   CXXConstructorDecl *ToCCD =
-dyn_cast(Importer.Import(E->getConstructor()));
+dyn_cast_or_null(Importer.Import(E->getConstructor()));
   if (!ToCCD)
 return nullptr;
 
@@ -5955,6 +5973,50 @@ Expr *ASTNodeImporter::VisitInitListExpr
   return To;
 }
 
+Expr *ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) {
+  FieldDecl *ToField = llvm::dyn_cast_or_null(
+  Importer.Import(DIE->getField()));
+  if (!ToField && DIE->getField())
+return nullptr;
+
+  return CXXDefaultInitExpr::Create(
+  Importer.getToContext(), Importer.Import(DIE->getLocStart()), ToField);
+}
+
+Expr *ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
+  QualType ToType = Importer.Import(E->getType());
+  if (ToType.isNull() && !E->getType().isNull())
+return nullptr;
+  ExprValueKind VK = E->getValueKind();
+  CastKind CK = E->getCastKind();
+  Expr *ToOp = Importer.Import(E->getSubExpr());
+  if (!ToOp && E->getSubExpr())
+return nullptr;
+  CXXCastPath BasePath;
+  if (ImportCastPath(E, BasePath))
+return nullptr;
+  TypeSourceInfo *ToWritten = Importer.Import(E->getTypeInfoAsWritten());
+  SourceLocation ToOperatorLoc = Importer.Import(E->getOperatorLoc());
+  SourceLocation 

r269554 - Update identifiers as needed when loading macros from serialized ASTs.

2016-05-14 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Sat May 14 01:24:14 2016
New Revision: 269554

URL: http://llvm.org/viewvc/llvm-project?rev=269554=rev
Log:
Update identifiers as needed when loading macros from serialized ASTs.

This is essential for iterating across macros properly, which LLDB does when
loading macros from modules.  A naiver version of this patch (without the
conditional) caused assertion failures in the testsuite, but this version should
be safe.

Thanks to Ben Langmuir for the refinement that made this work.

Modified:
cfe/trunk/lib/Serialization/ASTReader.cpp

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=269554=269553=269554=diff
==
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Sat May 14 01:24:14 2016
@@ -1680,9 +1680,12 @@ void ASTReader::ReadDefinedMacros() {
   break;
   
 case PP_MACRO_OBJECT_LIKE:
-case PP_MACRO_FUNCTION_LIKE:
-  getLocalIdentifier(*I, Record[0]);
+case PP_MACRO_FUNCTION_LIKE: {
+  IdentifierInfo *II = getLocalIdentifier(*I, Record[0]);
+  if (II->isOutOfDate())
+updateOutOfDateIdentifier(*II);
   break;
+}
   
 case PP_TOKEN:
   // Ignore tokens.


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r269553 - Fixed a bug where the ASTImporter didn't propagate builtin IDs at all.

2016-05-14 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Sat May 14 01:11:19 2016
New Revision: 269553

URL: http://llvm.org/viewvc/llvm-project?rev=269553=rev
Log:
Fixed a bug where the ASTImporter didn't propagate builtin IDs at all.

IdentifierInfos are assigned builtin IDs during parsing, but Idents.get() does 
not do that work.  So the ASTImporter needs to additionally set the builtin ID
for the newly-created IdentifierInfo.  This patch does that.

Currently ASTMerge tests only check syntax and the ASTMatchers don't check for
builtin IDs, so this is tricky to test, but LLDB will have a test for this.

Modified:
cfe/trunk/lib/AST/ASTImporter.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=269553=269552=269553=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Sat May 14 01:11:19 2016
@@ -6546,7 +6546,12 @@ IdentifierInfo *ASTImporter::Import(cons
   if (!FromId)
 return nullptr;
 
-  return (FromId->getName());
+  IdentifierInfo *ToId = (FromId->getName());
+
+  if (!ToId->getBuiltinID() && FromId->getBuiltinID())
+ToId->setBuiltinID(FromId->getBuiltinID());
+
+  return ToId;
 }
 
 Selector ASTImporter::Import(Selector FromSel) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r269551 - Handle injected class names in the ASTImporter.

2016-05-13 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Sat May 14 00:43:57 2016
New Revision: 269551

URL: http://llvm.org/viewvc/llvm-project?rev=269551=rev
Log:
Handle injected class names in the ASTImporter.

Every class as parsed by Clang has a forward declaration of itself as a member:

class A {
  class A;
  ...
}

but when the parser generates this it ensures that the RecordTypes for the two 
are the same.  This makes (among other things) inheritance work.  This patch
fixes a bug where the ASTImporter generated two separate RecordTypes when
importing the class and the contained forward declaration, and adds a test case.

Thanks to Doug Gregor for advice on this.

Added:
cfe/trunk/test/ASTMerge/Inputs/inheritance-base.cpp
cfe/trunk/test/ASTMerge/inheritance.cpp
Modified:
cfe/trunk/lib/AST/ASTImporter.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=269551=269550=269551=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Sat May 14 00:43:57 2016
@@ -2820,8 +2820,17 @@ Decl *ASTNodeImporter::VisitRecordDecl(R
 Decl *CDecl = Importer.Import(DCXX->getLambdaContextDecl());
 if (DCXX->getLambdaContextDecl() && !CDecl)
   return nullptr;
-D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(),
- CDecl);
+D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), CDecl);
+  } else if (DCXX->isInjectedClassName()) {
 
+// We have to be careful to do a similar dance to the one in   
 
+// Sema::ActOnStartCXXMemberDeclarations   
 
+CXXRecordDecl *const PrevDecl = nullptr;   
 
+const bool DelayTypeCreation = true;   
 
+D2CXX = CXXRecordDecl::Create( 
 
+Importer.getToContext(), D->getTagKind(), DC, StartLoc, Loc,   
 
+Name.getAsIdentifierInfo(), PrevDecl, DelayTypeCreation);  
 
+Importer.getToContext().getTypeDeclType(   
 
+D2CXX, llvm::dyn_cast(DC)); 
 
   } else {
 D2CXX = CXXRecordDecl::Create(Importer.getToContext(),
   D->getTagKind(),

Added: cfe/trunk/test/ASTMerge/Inputs/inheritance-base.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/inheritance-base.cpp?rev=269551=auto
==
--- cfe/trunk/test/ASTMerge/Inputs/inheritance-base.cpp (added)
+++ cfe/trunk/test/ASTMerge/Inputs/inheritance-base.cpp Sat May 14 00:43:57 2016
@@ -0,0 +1,7 @@
+class A
+{
+public:
+  int x;
+  A(int _x) : x(_x) {
+  }
+};

Added: cfe/trunk/test/ASTMerge/inheritance.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/inheritance.cpp?rev=269551=auto
==
--- cfe/trunk/test/ASTMerge/inheritance.cpp (added)
+++ cfe/trunk/test/ASTMerge/inheritance.cpp Sat May 14 00:43:57 2016
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++1z -emit-pch -o 
%t.1.ast %S/Inputs/inheritance-base.cpp
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++1z -ast-merge %t.1.ast 
-fsyntax-only -verify %s
+// expected-no-diagnostics
+
+class B : public A {
+  B(int _a) : A(_a) {
+  }
+};


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r269546 - Added support to the ASTImporter for C++ constructor initializers.

2016-05-13 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Sat May 14 00:20:31 2016
New Revision: 269546

URL: http://llvm.org/viewvc/llvm-project?rev=269546=rev
Log:
Added support to the ASTImporter for C++ constructor initializers.

Thanks to Aleksei Sidorin for review and advice.

Added:
cfe/trunk/test/ASTMerge/Inputs/init-ctors-classes.cpp
cfe/trunk/test/ASTMerge/init-ctors.cpp
Modified:
cfe/trunk/include/clang/AST/ASTImporter.h
cfe/trunk/lib/AST/ASTImporter.cpp

Modified: cfe/trunk/include/clang/AST/ASTImporter.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTImporter.h?rev=269546=269545=269546=diff
==
--- cfe/trunk/include/clang/AST/ASTImporter.h (original)
+++ cfe/trunk/include/clang/AST/ASTImporter.h Sat May 14 00:20:31 2016
@@ -23,6 +23,7 @@
 
 namespace clang {
   class ASTContext;
+  class CXXCtorInitializer;
   class Decl;
   class DeclContext;
   class DiagnosticsEngine;
@@ -204,6 +205,14 @@ namespace clang {
 /// \returns the equivalent file ID in the source manager of the "to"
 /// context.
 FileID Import(FileID);
+
+/// \brief Import the given C++ constructor initializer from the "from"
+/// context into the "to" context.
+///
+/// \returns the equivalent initializer in the "to" context.
+CXXCtorInitializer *Import(CXXCtorInitializer *FromInit);
+
+
 
 /// \brief Import the definition of the given declaration, including all of
 /// the declarations it contains.

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=269546=269545=269546=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Sat May 14 00:20:31 2016
@@ -3020,6 +3020,22 @@ Decl *ASTNodeImporter::VisitFunctionDecl
 D->isInlineSpecified(), 
 D->isImplicit(),
 D->isConstexpr());
+if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
+  SmallVector CtorInitializers;
+  for (CXXCtorInitializer *I : FromConstructor->inits()) {
+CXXCtorInitializer *ToI =
+cast_or_null(Importer.Import(I));
+if (!ToI && I)
+  return nullptr;
+CtorInitializers.push_back(ToI);
+  }
+  CXXCtorInitializer **Memory =
+  new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
+  std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
+  CXXConstructorDecl *ToCtor = llvm::cast(ToFunction);
+  ToCtor->setCtorInitializers(Memory);
+  ToCtor->setNumCtorInitializers(NumInitializers);
+}
   } else if (isa(D)) {
 ToFunction = CXXDestructorDecl::Create(Importer.getToContext(),
cast(DC),
@@ -6351,6 +6367,72 @@ FileID ASTImporter::Import(FileID FromID
   return ToID;
 }
 
+CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) {
+  Expr *ToExpr = Import(From->getInit());
+  if (!ToExpr && From->getInit())
+return nullptr;
+
+  if (From->isBaseInitializer()) {
+TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo());
+if (!ToTInfo && From->getTypeSourceInfo())
+  return nullptr;
+
+return new (ToContext) CXXCtorInitializer(
+ToContext, ToTInfo, From->isBaseVirtual(), 
Import(From->getLParenLoc()),
+ToExpr, Import(From->getRParenLoc()),
+From->isPackExpansion() ? Import(From->getEllipsisLoc())
+: SourceLocation());
+  } else if (From->isMemberInitializer()) {
+FieldDecl *ToField =
+llvm::cast_or_null(Import(From->getMember()));
+if (!ToField && From->getMember())
+  return nullptr;
+
+return new (ToContext) CXXCtorInitializer(
+ToContext, ToField, Import(From->getMemberLocation()),
+Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc()));
+  } else if (From->isIndirectMemberInitializer()) {
+IndirectFieldDecl *ToIField = llvm::cast_or_null(
+Import(From->getIndirectMember()));
+if (!ToIField && From->getIndirectMember())
+  return nullptr;
+
+return new (ToContext) CXXCtorInitializer(
+ToContext, ToIField, Import(From->getMemberLocation()),
+Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc()));
+  } else if (From->isDelegatingInitializer()) {
+TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo());
+if (!ToTInfo && From->getTypeSourceInfo())
+  return nullptr;
+
+return new (ToContext)
+CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()),
+   ToExpr, Import(From->getRParenLoc()));
+  } else if (unsigned NumArrayIndices = From->getNumArrayIndices()) {
+FieldDecl *ToField =
+

Re: [PATCH] D20118: Add support for injected class names and constructor initializers in C++

2016-05-13 Thread Sean Callanan via cfe-commits
spyffe added a comment.

I’m just going to use clang-format to resolve trailing whitespace/etc issues.  
It changes around some indentation in the class declaration for ASTImporter but 
that probably needs to be taken care of anyway…

Sean


Repository:
  rL LLVM

http://reviews.llvm.org/D20118



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20118: Add support for injected class names and constructor initializers in C++

2016-05-13 Thread Sean Callanan via cfe-commits
I’m just going to use clang-format to resolve trailing whitespace/etc issues.  
It changes around some indentation in the class declaration for ASTImporter but 
that probably needs to be taken care of anyway…

Sean

> On May 13, 2016, at 1:40 PM, Sean Callanan  wrote:
> 
> spyffe added a subscriber: spyffe.
> spyffe added a comment.
> 
> Thank you for your comments, I’m working on them now.
> 
> Sean
> 
> 
> Repository:
>  rL LLVM
> 
> http://reviews.llvm.org/D20118
> 
> 
> 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20118: Add support for injected class names and constructor initializers in C++

2016-05-13 Thread Sean Callanan via cfe-commits
spyffe added a subscriber: spyffe.
spyffe added a comment.

Thank you for your comments, I’m working on them now.

Sean


Repository:
  rL LLVM

http://reviews.llvm.org/D20118



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20118: Add support for injected class names and constructor initializers in C++

2016-05-13 Thread Sean Callanan via cfe-commits
Thank you for your comments, I’m working on them now.

Sean

> On May 11, 2016, at 4:39 AM, Aleksei Sidorin  wrote:
> 
> a.sidorin added a comment.
> 
> I' d like to have some tests for this. CXXCtorInitializers can be tested with 
> D14224 -like stuff or with ASTMatchers 
> (ASTImporterTest.cpp).
> Some code samples may be found in CXX/Sema tests, you just need to 
> port/simplify them.
> 
> 
> 
> Comment at: lib/AST/ASTImporter.cpp:3034
> @@ +3033,3 @@
> +SmallVector CtorInitializers;
> +for (const CXXCtorInitializer *I : FromConstructor->inits()) {
> +  CXXCtorInitializer *ToI =cast_or_null(
> 
> In my latest patch, I have introduced a function named 
> `ImportContainerChecked()`. I think it could make this code a bit more clean. 
> What do you think?
> 
> 
> Comment at: lib/AST/ASTImporter.cpp:3035
> @@ +3034,3 @@
> +for (const CXXCtorInitializer *I : FromConstructor->inits()) {
> +  CXXCtorInitializer *ToI =cast_or_null(
> +  Importer.Import(I));
> 
> Space after '='
> 
> 
> Comment at: lib/AST/ASTImporter.cpp:3041
> @@ +3040,3 @@
> +}
> +if (unsigned NumInitializers = CtorInitializers.size()) {
> +  CXXCtorInitializer **Memory = new (Importer.getToContext())
> 
> If we move this condition (I suggest to use 
> `FromConstructor->getNumCtorIintializers()` instead) upper to cover the 
> importing loop, we may skip this loop as well.
> 
> 
> Comment at: lib/AST/ASTImporter.cpp:3045
> @@ +3044,3 @@
> +  std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
> +  
> llvm::cast(ToFunction)->setCtorInitializers(Memory);
> +  llvm::cast(ToFunction)->setNumCtorInitializers(
> 
> As I can see, LLVM code style avoids qualified `cast`s.
> 
> 
> Comment at: lib/AST/ASTImporter.cpp:6384
> @@ +6383,3 @@
> +  return nullptr;
> +
> +return new (ToContext)
> 
> Trailing whitespace.
> 
> 
> Comment at: lib/AST/ASTImporter.cpp:6389
> @@ +6388,3 @@
> + Import(From->getRParenLoc()),
> + From->isPackExpansion() ?
> + Import(From->getEllipsisLoc()) : SourceLocation());
> 
> The indentation for `?:` here is a bit confusing.
> 
> 
> Comment at: lib/AST/ASTImporter.cpp:6396
> @@ +6395,3 @@
> +  return nullptr;
> +
> +return new (ToContext)
> 
> Training whitespace. It's pretty difficult to find them with Phabricator, 
> could you check your patch for them?
> 
> 
> Comment at: lib/AST/ASTImporter.cpp:6423
> @@ +6422,3 @@
> +  } else {
> +return nullptr;
> +  }
> 
> It seems like a case with indexed initializer is missed here. You can find my 
> implementation on 
> https://github.com/haoNoQ/clang/blob/summary-ipa-draft/lib/AST/ASTImporter.cpp#L2456-L2464.
> A sample that requires it is `auto parens4 = [p4(1)] {};` 
> (test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p4.cpp)
> 
> 
> 
> Repository:
>  rL LLVM
> 
> http://reviews.llvm.org/D20118
> 
> 
> 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20118: Add support for injected class names and constructor initializers in C++

2016-05-10 Thread Sean Callanan via cfe-commits
spyffe created this revision.
spyffe added reviewers: sepavloff, a.sidorin.
spyffe added a subscriber: cfe-commits.
spyffe set the repository for this revision to rL LLVM.
spyffe added a project: clang-c.

The AST importer currently does not handle injected class names properly (it 
does not bind their types to the type of the parent as the parser would) and it 
doesn't handle constructor initializers at all.

This patch adds support for both of those, and also forwards the `isImplicit()` 
and `isReferenced()` flags for *all* declarations as is done for `isUsed()`.

Repository:
  rL LLVM

http://reviews.llvm.org/D20118

Files:
  include/clang/AST/ASTImporter.h
  lib/AST/ASTImporter.cpp

Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -2820,6 +2820,18 @@
   return nullptr;
 D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(),
  CDecl);
+  } else if (DCXX->isInjectedClassName()) {
+// We have to be careful to do a similar dance to the one in
+// Sema::ActOnStartCXXMemberDeclarations
+CXXRecordDecl * const PrevDecl = nullptr;
+const bool DelayTypeCreation = true;
+D2CXX = CXXRecordDecl::Create(Importer.getToContext(),
+  D->getTagKind(),
+  DC, StartLoc, Loc,
+  Name.getAsIdentifierInfo(),
+  PrevDecl, DelayTypeCreation);
+Importer.getToContext().getTypeDeclType(
+D2CXX, llvm::dyn_cast(DC));
   } else {
 D2CXX = CXXRecordDecl::Create(Importer.getToContext(),
   D->getTagKind(),
@@ -3018,6 +3030,22 @@
 D->isInlineSpecified(), 
 D->isImplicit(),
 D->isConstexpr());
+SmallVector CtorInitializers;
+for (const CXXCtorInitializer *I : FromConstructor->inits()) {
+  CXXCtorInitializer *ToI =cast_or_null(
+  Importer.Import(I));
+  if (!ToI && I)
+return nullptr;
+  CtorInitializers.push_back(ToI);
+}
+if (unsigned NumInitializers = CtorInitializers.size()) {
+  CXXCtorInitializer **Memory = new (Importer.getToContext())
+ CXXCtorInitializer*[NumInitializers];
+  std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
+  llvm::cast(ToFunction)->setCtorInitializers(Memory);
+  llvm::cast(ToFunction)->setNumCtorInitializers(
+  NumInitializers);
+}
   } else if (isa(D)) {
 ToFunction = CXXDestructorDecl::Create(Importer.getToContext(),
cast(DC),
@@ -6344,6 +6372,58 @@
   return ToID;
 }
 
+CXXCtorInitializer *ASTImporter::Import(const CXXCtorInitializer *From) {
+  Expr *ToExpr = Import(From->getInit());
+  if (!ToExpr && From->getInit())
+return nullptr;
+
+  if (From->isBaseInitializer()) {
+TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo());
+if (!ToTInfo && From->getTypeSourceInfo())
+  return nullptr;
+
+return new (ToContext)
+  CXXCtorInitializer(ToContext, ToTInfo, From->isBaseVirtual(),
+ Import(From->getLParenLoc()), ToExpr, 
+ Import(From->getRParenLoc()),
+ From->isPackExpansion() ?
+ Import(From->getEllipsisLoc()) : SourceLocation());
+  } else if (From->isMemberInitializer()) {
+FieldDecl *ToField = llvm::cast_or_null(Import(
+From->getMember()));
+if (!ToField && From->getMember())
+  return nullptr;
+
+return new (ToContext)
+CXXCtorInitializer(ToContext, ToField,
+   Import(From->getMemberLocation()),
+   Import(From->getLParenLoc()), ToExpr, 
+   Import(From->getRParenLoc()));
+  } else if (From->isIndirectMemberInitializer()) {
+IndirectFieldDecl *ToIField = llvm::cast_or_null(Import(
+From->getIndirectMember()));
+if (!ToIField && From->getIndirectMember())
+  return nullptr;
+
+return new (ToContext)
+CXXCtorInitializer(ToContext, ToIField,
+   Import(From->getMemberLocation()),
+   Import(From->getLParenLoc()), ToExpr, 
+   Import(From->getRParenLoc()));
+  } else if (From->isDelegatingInitializer()) {
+TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo());
+if (!ToTInfo && From->getTypeSourceInfo())
+  return nullptr;
+
+return new (ToContext)
+CXXCtorInitializer(ToContext, ToTInfo,
+   Import(From->getLParenLoc()), ToExpr,
+   Import(From->getRParenLoc()));
+  } else {

Re: [PATCH] D14286: ASTImporter: expressions, pt.1

2016-04-12 Thread Sean Callanan via cfe-commits
spyffe accepted this revision.
spyffe added a comment.
This revision is now accepted and ready to land.

This all looks fine to me, and the LLDB test suite is happy also.


http://reviews.llvm.org/D14286



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D14286: ASTImporter: expressions, pt.1

2016-04-12 Thread Sean Callanan via cfe-commits
Aleksei,

it looks like I might have made a bad assumption in my ImportArray – namely 
that there were some entities that required arrays of things they’re 
constructed with to be allocated in the ASTContext.  Looking at the 
constructors for those entities, it looks like most of them actually do the 
allocation and copying themselves.

Thanks for cleaning that up.  I’m going to try running the LLDB testsuite with 
your patch applied and I’ll let you know what happens.

Sean


> On Apr 12, 2016, at 5:46 AM, Aleksei Sidorin  wrote:
> 
> 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D14286: ASTImporter: expressions, pt.1

2016-04-12 Thread Sean Callanan via cfe-commits
spyffe added a subscriber: spyffe.
spyffe added a comment.

Aleksei,

it looks like I might have made a bad assumption in my ImportArray – namely 
that there were some entities that required arrays of things they’re 
constructed with to be allocated in the ASTContext.  Looking at the 
constructors for those entities, it looks like most of them actually do the 
allocation and copying themselves.

Thanks for cleaning that up.  I’m going to try running the LLDB testsuite with 
your patch applied and I’ll let you know what happens.

Sean


http://reviews.llvm.org/D14286



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D14286: ASTImporter: expressions, pt.1

2016-03-29 Thread Sean Callanan via cfe-commits
spyffe requested changes to this revision.
spyffe added a comment.
This revision now requires changes to proceed.

Overall this is a great improvement and I look forward to taking advantage of 
this patch in LLDB!

I had one specific nit about `NullPtrTy`, and one more general comment about 
your infrastructure that imports multiple things – it seems like we can 
collaborate and create some combination of `ImportArray` and your code to 
handle all cases.  Particularly you handle the cases where the array doesn't 
have to be  allocated inside `getToContext()` – my code doesn't handle that at 
all.

Thanks for working on this.



Comment at: lib/AST/ASTImporter.cpp:35
@@ +34,3 @@
+void ImportMultipleItems(IIter Ibegin, IIter Iend, OIter Obegin) {
+  ASTImporter  = Importer;
+  std::transform(Ibegin, Iend, Obegin,

I recently added a function, `ImportArray`, that does something similar.  Could 
it be adapted to your needs?


Comment at: lib/AST/ASTImporter.cpp:5462
@@ +5461,3 @@
+  ASTContext  = Importer.getToContext();
+  return new(ToCtx) CXXNullPtrLiteralExpr(ToCtx.NullPtrTy,
+  Importer.Import(E->getLocation()));

I'm worried about using `NullPtrTy` here directly, because the type may have 
been coerced to a `typedef` or something like that.  The fact that the 
constructor takes a type argument suggests that the type is not implicit – I'd 
feel much more comfortable just importing the type.


Comment at: lib/AST/ASTImporter.cpp:5466
@@ +5465,3 @@
+
+Expr *ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
+  ASTContext  = Importer.getToContext();

I recently committed `VisitCXXBoolLiteralExpr`.  Sorry to step on your toes!


Comment at: lib/AST/ASTImporter.cpp:5878
@@ -5346,1 +5877,3 @@
 
+Expr *ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) {
+  QualType T = Importer.Import(E->getType());

Sorry again!  I recently committed `VisitCXXThisExpr`


Comment at: unittests/AST/ASTImporterTest.cpp:118
@@ +117,3 @@
+   hasType(
+ asString("const char [4]");
+  EXPECT_TRUE(testImport("void declToImport() { L\"foo\"; }",

This is a good point; if you use LLDB to test this (e.g., lldb's 
`test/testcases/expression_command/top-level`) then you can verify that these 
imported entities make it all the way to generated machine code and work as 
expected.

Ideally there would be a mode in Clang that parses the input file, makes a 
translation unit out of it, imports everything from that translation unit into 
another translation unit, and then `CodeGen`s the second translation unit.  
That is something I'd like to hook up when I get some time.  I've also talked 
to Doug Gregor and he suggested that perhaps .pch files can be abused for this 
purpose, repurposing some of the functionality in the `ASTMerge` tests (though 
those don't do `CodeGen`).


http://reviews.llvm.org/D14286



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r264669 - Improvements to the ASTImporter to support LLDB top-level Clang expressions.

2016-03-28 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Mon Mar 28 16:43:01 2016
New Revision: 264669

URL: http://llvm.org/viewvc/llvm-project?rev=264669=rev
Log:
Improvements to the ASTImporter to support LLDB top-level Clang expressions.

The testcase for this is in LLDB, adeed by r264662.

This patch adds support for a variety of new expression types to the AST
importer, mostly related to C++.  It also adds support for importing lambdas
correctly, and adds support for importing the attributes attached to any Decl.

Finally, the patch adds a new templated function to ASTNodeImporter that imports
arbitrary arrays of importable things into a bump-allocated array attached to
getToContext().  This is a pattern we see at many places in ASTNodeImporter;
rather than do it slightly differently at each point, this function does it one
way.



Modified:
cfe/trunk/lib/AST/ASTImporter.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=264669=264668=264669=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Mon Mar 28 16:43:01 2016
@@ -224,8 +224,36 @@ namespace clang {
 Expr *VisitImplicitCastExpr(ImplicitCastExpr *E);
 Expr *VisitCStyleCastExpr(CStyleCastExpr *E);
 Expr *VisitCXXConstructExpr(CXXConstructExpr *E);
+Expr *VisitCXXMemberCallExpr(CXXMemberCallExpr *E);
+Expr *VisitCXXThisExpr(CXXThisExpr *E);
+Expr *VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
 Expr *VisitMemberExpr(MemberExpr *E);
 Expr *VisitCallExpr(CallExpr *E);
+Expr *VisitInitListExpr(InitListExpr *E);
+
+template  bool ImportArray(Iter B, Iter E, 
llvm::ArrayRef ) {
+  size_t NumElements = E - B;
+  SmallVector ImportedElements(NumElements);
+  ASTImporter &_Importer = Importer;
+  
+  bool Failed = false;
+  std::transform(B, E, ImportedElements.begin(),
+ [&_Importer, ](T *Element) -> T* {
+   T *ToElement = _Importer.Import(Element);
+   if (Element && !ToElement)
+ Failed = true;
+   return ToElement;
+ });
+  
+  if (Failed)
+return false;
+  
+  T **CopiedElements = new (Importer.getToContext()) T*[NumElements];
+  std::copy(ImportedElements.begin(), ImportedElements.end(), 
[0]);
+  ToArray = llvm::ArrayRef(CopiedElements, NumElements);
+  
+  return true;
+}
   };
 }
 using namespace clang;
@@ -2683,11 +2711,26 @@ Decl *ASTNodeImporter::VisitRecordDecl(R
   RecordDecl *D2 = AdoptDecl;
   SourceLocation StartLoc = Importer.Import(D->getLocStart());
   if (!D2) {
-if (isa(D)) {
-  CXXRecordDecl *D2CXX = CXXRecordDecl::Create(Importer.getToContext(), 
-   D->getTagKind(),
-   DC, StartLoc, Loc,
-   Name.getAsIdentifierInfo());
+CXXRecordDecl *D2CXX = nullptr;
+if (CXXRecordDecl *DCXX = llvm::dyn_cast(D)) {
+  if (DCXX->isLambda()) {
+TypeSourceInfo *TInfo = Importer.Import(DCXX->getLambdaTypeInfo());
+D2CXX = CXXRecordDecl::CreateLambda(Importer.getToContext(),
+DC, TInfo, Loc,
+DCXX->isDependentLambda(),
+DCXX->isGenericLambda(),
+DCXX->getLambdaCaptureDefault());
+Decl *CDecl = Importer.Import(DCXX->getLambdaContextDecl());
+if (DCXX->getLambdaContextDecl() && !CDecl)
+  return nullptr;
+D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(),
+ CDecl);
+  } else {
+D2CXX = CXXRecordDecl::Create(Importer.getToContext(),
+  D->getTagKind(),
+  DC, StartLoc, Loc,
+  Name.getAsIdentifierInfo());
+  }
   D2 = D2CXX;
   D2->setAccess(D->getAccess());
 } else {
@@ -4653,16 +4696,11 @@ Stmt *ASTNodeImporter::VisitNullStmt(Nul
 }
 
 Stmt *ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) {
-  SmallVector ToStmts(S->size());
-  auto &_Importer = this->Importer;
-  std::transform(S->body_begin(), S->body_end(), ToStmts.begin(),
-[&_Importer](Stmt *CS) -> Stmt * {
-  return _Importer.Import(CS);
-});
-  for (Stmt *ToS : ToStmts) {
-if (!ToS)
-  return nullptr;
-  }
+  llvm::ArrayRef ToStmts;
+
+  if (!ImportArray(S->body_begin(), S->body_end(), ToStmts))
+return nullptr;
+
   SourceLocation ToLBraceLoc = Importer.Import(S->getLBracLoc());
   SourceLocation ToRBraceLoc = Importer.Import(S->getRBracLoc());
   return new 

Re: r262576 - Caught and fixed a typo in r262572.

2016-03-03 Thread Sean Callanan via cfe-commits
Nico,

the tests for ASTImporter (currently, test/ASTMerge) are currently set up to do 
an AST merge and check that certain errors occur.  I don’t believe they 
actually go and code-gen, which would have caught this.

I think investing in better ASTImporter testing is a great goal, but right now 
LLDB is actually the most comprehensive validation suite for the ASTImporter 
I’m aware of.

Sean

> On Mar 2, 2016, at 11:04 PM, Nico Weber <tha...@chromium.org> wrote:
> 
> Is it possible to test this?
> 
> On Mar 2, 2016 6:26 PM, "Sean Callanan via cfe-commits" 
> <cfe-commits@lists.llvm.org <mailto:cfe-commits@lists.llvm.org>> wrote:
> Author: spyffe
> Date: Wed Mar  2 20:22:05 2016
> New Revision: 262576
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=262576=rev 
> <http://llvm.org/viewvc/llvm-project?rev=262576=rev>
> Log:
> Caught and fixed a typo in r262572.
> 
> I should have checked and imported D's in-class initializer.
> Instead I accidentally used ToField's in-class initializer,
> which is always NULL so ToField will never get one.
> 
> 
> 
> Modified:
> cfe/trunk/lib/AST/ASTImporter.cpp
> 
> Modified: cfe/trunk/lib/AST/ASTImporter.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=262576=262575=262576=diff
>  
> <http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=262576=262575=262576=diff>
> ==
> --- cfe/trunk/lib/AST/ASTImporter.cpp (original)
> +++ cfe/trunk/lib/AST/ASTImporter.cpp Wed Mar  2 20:22:05 2016
> @@ -3038,7 +3038,7 @@ Decl *ASTNodeImporter::VisitFieldDecl(Fi
>   D->getInClassInitStyle());
>ToField->setAccess(D->getAccess());
>ToField->setLexicalDeclContext(LexicalDC);
> -  if (Expr *FromInitializer = ToField->getInClassInitializer()) {
> +  if (Expr *FromInitializer = D->getInClassInitializer()) {
>  Expr *ToInitializer = Importer.Import(FromInitializer);
>  if (ToInitializer)
>ToField->setInClassInitializer(ToInitializer);
> 
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org <mailto:cfe-commits@lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits 
> <http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits>

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r262576 - Caught and fixed a typo in r262572.

2016-03-02 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Wed Mar  2 20:22:05 2016
New Revision: 262576

URL: http://llvm.org/viewvc/llvm-project?rev=262576=rev
Log:
Caught and fixed a typo in r262572.

I should have checked and imported D's in-class initializer.
Instead I accidentally used ToField's in-class initializer,
which is always NULL so ToField will never get one.



Modified:
cfe/trunk/lib/AST/ASTImporter.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=262576=262575=262576=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Wed Mar  2 20:22:05 2016
@@ -3038,7 +3038,7 @@ Decl *ASTNodeImporter::VisitFieldDecl(Fi
  D->getInClassInitStyle());
   ToField->setAccess(D->getAccess());
   ToField->setLexicalDeclContext(LexicalDC);
-  if (Expr *FromInitializer = ToField->getInClassInitializer()) {
+  if (Expr *FromInitializer = D->getInClassInitializer()) {
 Expr *ToInitializer = Importer.Import(FromInitializer);
 if (ToInitializer)
   ToField->setInClassInitializer(ToInitializer);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r262572 - Fixed a problem where the ASTImporter mishandled in-class initializers.

2016-03-02 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Wed Mar  2 19:21:28 2016
New Revision: 262572

URL: http://llvm.org/viewvc/llvm-project?rev=262572=rev
Log:
Fixed a problem where the ASTImporter mishandled in-class initializers.

Previously, the ASTImporter, when copying a FieldDecl, would make the
new FieldDecl use the exact same in-class initializer as the original
FieldDecl, which is a problem since the initializer is in the wrong AST.
The initializer must be imported, just like all the other parts of the
field.

Doug Gregor reviewed this fix.



Modified:
cfe/trunk/lib/AST/ASTImporter.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=262572=262571=262572=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Wed Mar  2 19:21:28 2016
@@ -3038,8 +3038,13 @@ Decl *ASTNodeImporter::VisitFieldDecl(Fi
  D->getInClassInitStyle());
   ToField->setAccess(D->getAccess());
   ToField->setLexicalDeclContext(LexicalDC);
-  if (ToField->hasInClassInitializer())
-ToField->setInClassInitializer(D->getInClassInitializer());
+  if (Expr *FromInitializer = ToField->getInClassInitializer()) {
+Expr *ToInitializer = Importer.Import(FromInitializer);
+if (ToInitializer)
+  ToField->setInClassInitializer(ToInitializer);
+else
+  return nullptr;
+  }
   ToField->setImplicit(D->isImplicit());
   Importer.Imported(D, ToField);
   LexicalDC->addDeclInternal(ToField);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits