diff options
-rw-r--r-- | clang/lib/AST/ExternalASTMerger.cpp | 6 | ||||
-rw-r--r-- | clang/test/Import/objc-method/Inputs/S.m | 4 | ||||
-rw-r--r-- | clang/test/Import/objc-method/test.m | 5 | ||||
-rw-r--r-- | clang/tools/clang-import-test/clang-import-test.cpp | 39 |
4 files changed, 41 insertions, 13 deletions
diff --git a/clang/lib/AST/ExternalASTMerger.cpp b/clang/lib/AST/ExternalASTMerger.cpp index 4f4a99794c5..f69b5d62840 100644 --- a/clang/lib/AST/ExternalASTMerger.cpp +++ b/clang/lib/AST/ExternalASTMerger.cpp @@ -44,6 +44,9 @@ public: ToTag->setMustBuildLookupTable(); } else if (auto ToNamespace = dyn_cast<NamespaceDecl>(To)) { ToNamespace->setHasExternalVisibleStorage(); + } else if (auto ToContainer = dyn_cast<ObjCContainerDecl>(To)) { + ToContainer->setHasExternalLexicalStorage(); + ToContainer->setMustBuildLookupTable(); } return ASTImporter::Imported(From, To); } @@ -80,11 +83,12 @@ LookupSameContext(Source<TranslationUnitDecl *> SourceTU, const DeclContext *DC, } bool IsForwardDeclaration(Decl *D) { - assert(!isa<ObjCInterfaceDecl>(D)); // TODO handle this case if (auto TD = dyn_cast<TagDecl>(D)) { return !TD->isThisDeclarationADefinition(); } else if (auto FD = dyn_cast<FunctionDecl>(D)) { return !FD->isThisDeclarationADefinition(); + } else if (auto OID = dyn_cast<ObjCInterfaceDecl>(D)) { + return OID->isThisDeclarationADefinition(); } else { return false; } diff --git a/clang/test/Import/objc-method/Inputs/S.m b/clang/test/Import/objc-method/Inputs/S.m new file mode 100644 index 00000000000..cf8ffaa602a --- /dev/null +++ b/clang/test/Import/objc-method/Inputs/S.m @@ -0,0 +1,4 @@ +@interface C { +} +-(int)m; +@end diff --git a/clang/test/Import/objc-method/test.m b/clang/test/Import/objc-method/test.m new file mode 100644 index 00000000000..7707110d824 --- /dev/null +++ b/clang/test/Import/objc-method/test.m @@ -0,0 +1,5 @@ +// RUN: clang-import-test -x objective-c++ -import %S/Inputs/S.m -expression %s +void expr() { + C *c; + int i = [c m]; +} diff --git a/clang/tools/clang-import-test/clang-import-test.cpp b/clang/tools/clang-import-test/clang-import-test.cpp index 6b724e9cf5f..286cb05219c 100644 --- a/clang/tools/clang-import-test/clang-import-test.cpp +++ b/clang/tools/clang-import-test/clang-import-test.cpp @@ -17,6 +17,7 @@ #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" #include "clang/CodeGen/ModuleBuilder.h" +#include "clang/Driver/Types.h" #include "clang/Frontend/ASTConsumers.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/MultiplexConsumer.h" @@ -53,6 +54,11 @@ static llvm::cl::list<std::string> llvm::cl::desc("Argument to pass to the CompilerInvocation"), llvm::cl::CommaSeparated); +static llvm::cl::opt<std::string> + Input("x", llvm::cl::Optional, + llvm::cl::desc("The language to parse (default: c++)"), + llvm::cl::init("c++")); + static llvm::cl::opt<bool> DumpAST("dump-ast", llvm::cl::init(false), llvm::cl::desc("Dump combined AST")); @@ -110,6 +116,7 @@ private: llvm::errs() << LineString << '\n'; llvm::errs().indent(LocColumn); llvm::errs() << '^'; + llvm::errs() << '\n'; } virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, @@ -143,7 +150,7 @@ private: }; std::unique_ptr<CompilerInstance> -BuildCompilerInstance(ArrayRef<const char *> ClangArgv) { +BuildCompilerInstance() { auto Ins = llvm::make_unique<CompilerInstance>(); auto DC = llvm::make_unique<TestDiagnosticConsumer>(); const bool ShouldOwnClient = true; @@ -151,13 +158,27 @@ BuildCompilerInstance(ArrayRef<const char *> ClangArgv) { auto Inv = llvm::make_unique<CompilerInvocation>(); + std::vector<const char *> ClangArgv(ClangArgs.size()); + std::transform(ClangArgs.begin(), ClangArgs.end(), ClangArgv.begin(), + [](const std::string &s) -> const char * { return s.data(); }); CompilerInvocation::CreateFromArgs(*Inv, ClangArgv.data(), &ClangArgv.data()[ClangArgv.size()], Ins->getDiagnostics()); - Inv->getLangOpts()->CPlusPlus = true; - Inv->getLangOpts()->CPlusPlus11 = true; - Inv->getHeaderSearchOpts().UseLibcxx = true; + { + using namespace driver::types; + ID Id = lookupTypeForTypeSpecifier(Input.c_str()); + assert(Id != TY_INVALID); + if (isCXX(Id)) { + Inv->getLangOpts()->CPlusPlus = true; + Inv->getLangOpts()->CPlusPlus11 = true; + Inv->getHeaderSearchOpts().UseLibcxx = true; + } + if (isObjC(Id)) { + Inv->getLangOpts()->ObjC1 = 1; + Inv->getLangOpts()->ObjC2 = 1; + } + } Inv->getLangOpts()->Bool = true; Inv->getLangOpts()->WChar = true; Inv->getLangOpts()->Blocks = true; @@ -216,11 +237,8 @@ void AddExternalSource( } std::unique_ptr<CompilerInstance> BuildIndirect(std::unique_ptr<CompilerInstance> &CI) { - std::vector<const char *> ClangArgv(ClangArgs.size()); - std::transform(ClangArgs.begin(), ClangArgs.end(), ClangArgv.begin(), - [](const std::string &s) -> const char * { return s.data(); }); std::unique_ptr<CompilerInstance> IndirectCI = - init_convenience::BuildCompilerInstance(ClangArgv); + init_convenience::BuildCompilerInstance(); auto ST = llvm::make_unique<SelectorTable>(); auto BC = llvm::make_unique<Builtin::Context>(); std::unique_ptr<ASTContext> AST = @@ -247,11 +265,8 @@ llvm::Expected<std::unique_ptr<CompilerInstance>> Parse(const std::string &Path, llvm::ArrayRef<std::unique_ptr<CompilerInstance>> Imports, bool ShouldDumpAST) { - std::vector<const char *> ClangArgv(ClangArgs.size()); - std::transform(ClangArgs.begin(), ClangArgs.end(), ClangArgv.begin(), - [](const std::string &s) -> const char * { return s.data(); }); std::unique_ptr<CompilerInstance> CI = - init_convenience::BuildCompilerInstance(ClangArgv); + init_convenience::BuildCompilerInstance(); auto ST = llvm::make_unique<SelectorTable>(); auto BC = llvm::make_unique<Builtin::Context>(); std::unique_ptr<ASTContext> AST = |