diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-03-08 00:03:56 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-03-08 00:03:56 +0000 |
commit | 9bca298f6d9dadb1f304ad63becfe28a0eda1b0b (patch) | |
tree | f7090390710aff9cf1cca5469935e4d82cd69add /clang | |
parent | 7f928f14f4235e0cb593857aca4fcedea157c4de (diff) | |
download | bcm5719-llvm-9bca298f6d9dadb1f304ad63becfe28a0eda1b0b.tar.gz bcm5719-llvm-9bca298f6d9dadb1f304ad63becfe28a0eda1b0b.zip |
Module [extern_c] attribute: inherit to submodules, don't write 'extern "C"'
blocks when building in C mode, and serialize and deserialize the attribute.
llvm-svn: 203317
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Basic/Module.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Frontend/FrontendActions.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 21 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTWriter.cpp | 4 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/elsewhere/c-header-indirect.h | 1 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/elsewhere/module.map | 1 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/module.map | 2 | ||||
-rw-r--r-- | clang/test/Modules/extern_c.cpp | 21 | ||||
-rw-r--r-- | clang/unittests/AST/CMakeLists.txt | 1 |
9 files changed, 41 insertions, 16 deletions
diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp index 24c480a7667..237c78981f2 100644 --- a/clang/lib/Basic/Module.cpp +++ b/clang/lib/Basic/Module.cpp @@ -37,6 +37,8 @@ Module::Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent, IsAvailable = false; if (Parent->IsSystem) IsSystem = true; + if (Parent->IsExternC) + IsExternC = true; Parent->SubModuleIndex[Name] = Parent->SubModules.size(); Parent->SubModules.push_back(this); diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 70c34b9653d..71baa10e60a 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -132,7 +132,7 @@ static void addHeaderInclude(StringRef HeaderName, SmallVectorImpl<char> &Includes, const LangOptions &LangOpts, bool IsExternC) { - if (IsExternC) + if (IsExternC && LangOpts.CPlusPlus) Includes += "extern \"C\" {\n"; if (LangOpts.ObjC1) Includes += "#import \""; @@ -140,7 +140,7 @@ static void addHeaderInclude(StringRef HeaderName, Includes += "#include \""; Includes += HeaderName; Includes += "\"\n"; - if (IsExternC) + if (IsExternC && LangOpts.CPlusPlus) Includes += "}\n"; } diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 7e31723b165..6f4dc9bfb58 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -3996,15 +3996,17 @@ bool ASTReader::ReadSubmoduleBlock(ModuleFile &F) { } StringRef Name = Blob; - SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[0]); - SubmoduleID Parent = getGlobalSubmoduleID(F, Record[1]); - bool IsFramework = Record[2]; - bool IsExplicit = Record[3]; - bool IsSystem = Record[4]; - bool InferSubmodules = Record[5]; - bool InferExplicitSubmodules = Record[6]; - bool InferExportWildcard = Record[7]; - bool ConfigMacrosExhaustive = Record[8]; + unsigned Idx = 0; + SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[Idx++]); + SubmoduleID Parent = getGlobalSubmoduleID(F, Record[Idx++]); + bool IsFramework = Record[Idx++]; + bool IsExplicit = Record[Idx++]; + bool IsSystem = Record[Idx++]; + bool IsExternC = Record[Idx++]; + bool InferSubmodules = Record[Idx++]; + bool InferExplicitSubmodules = Record[Idx++]; + bool InferExportWildcard = Record[Idx++]; + bool ConfigMacrosExhaustive = Record[Idx++]; Module *ParentModule = 0; if (Parent) @@ -4040,6 +4042,7 @@ bool ASTReader::ReadSubmoduleBlock(ModuleFile &F) { CurrentModule->IsFromModuleFile = true; CurrentModule->IsSystem = IsSystem || CurrentModule->IsSystem; + CurrentModule->IsExternC = IsExternC; CurrentModule->InferSubmodules = InferSubmodules; CurrentModule->InferExplicitSubmodules = InferExplicitSubmodules; CurrentModule->InferExportWildcard = InferExportWildcard; diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 8c2eeca0215..fc1806fca68 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -2225,7 +2225,8 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) { Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit - Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem + Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem + Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExternC Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferSubmodules... Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExplicit... Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExportWild... @@ -2313,6 +2314,7 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) { Record.push_back(Mod->IsFramework); Record.push_back(Mod->IsExplicit); Record.push_back(Mod->IsSystem); + Record.push_back(Mod->IsExternC); Record.push_back(Mod->InferSubmodules); Record.push_back(Mod->InferExplicitSubmodules); Record.push_back(Mod->InferExportWildcard); diff --git a/clang/test/Modules/Inputs/elsewhere/c-header-indirect.h b/clang/test/Modules/Inputs/elsewhere/c-header-indirect.h new file mode 100644 index 00000000000..083c41f77c5 --- /dev/null +++ b/clang/test/Modules/Inputs/elsewhere/c-header-indirect.h @@ -0,0 +1 @@ +#include "c-header.h" diff --git a/clang/test/Modules/Inputs/elsewhere/module.map b/clang/test/Modules/Inputs/elsewhere/module.map new file mode 100644 index 00000000000..2c56820676a --- /dev/null +++ b/clang/test/Modules/Inputs/elsewhere/module.map @@ -0,0 +1 @@ +module c_library_indirect { header "c-header-indirect.h" } diff --git a/clang/test/Modules/Inputs/module.map b/clang/test/Modules/Inputs/module.map index c4727d74918..574eba47594 100644 --- a/clang/test/Modules/Inputs/module.map +++ b/clang/test/Modules/Inputs/module.map @@ -1,4 +1,4 @@ -module c_library [extern_c] { header "c-header.h" } +module c_library [extern_c] { module inner { header "c-header.h" } } module cxx_library { header "cxx-header.h" requires cplusplus } module c_library_bad [extern_c] { header "c-header-bad.h" } module diamond_top { header "diamond_top.h" } diff --git a/clang/test/Modules/extern_c.cpp b/clang/test/Modules/extern_c.cpp index 7ef47098129..ba466f2a53a 100644 --- a/clang/test/Modules/extern_c.cpp +++ b/clang/test/Modules/extern_c.cpp @@ -9,6 +9,12 @@ // RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs %s -DCXX_HEADER -DEXTERN_CXX // RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs %s -DCXX_HEADER -DEXTERN_C -DEXTERN_CXX // RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs %s -DCXX_HEADER -DEXTERN_C -DNAMESPACE +// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs -x c %s +// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs/elsewhere -I %S/Inputs %s -DEXTERN_C -DINDIRECT + +#ifdef INDIRECT +#include "c-header-indirect.h" +#endif #ifdef NAMESPACE namespace M { @@ -34,7 +40,7 @@ extern "C++" { // expected-error@-3 {{import of C++ module 'cxx_library' appears within extern "C" language linkage specification}} // expected-note@-17 {{extern "C" language linkage specification begins here}} #elif defined(NAMESPACE) -// expected-error-re@-6 {{import of module '{{c_library|cxx_library}}' appears within namespace 'M'}} +// expected-error-re@-6 {{import of module '{{c_library.inner|cxx_library}}' appears within namespace 'M'}} // expected-note@-24 {{namespace 'M' begins here}} #endif @@ -51,16 +57,25 @@ extern "C++" { using namespace M; #endif +#ifdef __cplusplus namespace N { - int k = f(); +#endif + void g() { + int k = f(); + } +#ifdef __cplusplus extern "C" { +#endif int f; #if !defined(CXX_HEADER) // expected-error@-2 {{redefinition of 'f' as different kind of symbol}} // expected-note@c-header.h:1 {{previous}} #endif + +#ifdef __cplusplus } } +#endif -suppress_expected_no_diagnostics_error; // expected-error {{}} +suppress_expected_no_diagnostics_error error_here; // expected-error {{}} diff --git a/clang/unittests/AST/CMakeLists.txt b/clang/unittests/AST/CMakeLists.txt index 55b028c1588..4ad3b1af6f0 100644 --- a/clang/unittests/AST/CMakeLists.txt +++ b/clang/unittests/AST/CMakeLists.txt @@ -10,6 +10,7 @@ add_clang_unittest(ASTTests CommentParser.cpp DeclPrinterTest.cpp DeclTest.cpp + ExternalASTSourceTest.cpp SourceLocationTest.cpp StmtPrinterTest.cpp ) |