r203317 - Module [extern_c] attribute: inherit to submodules, don't write 'extern "C"'
Richard Smith
richard at metafoo.co.uk
Thu Mar 13 19:47:39 PDT 2014
On Sun, Mar 9, 2014 at 1:18 AM, NAKAMURA Takumi <geek4civic at gmail.com>wrote:
> 2014-03-08 9:03 GMT+09:00 Richard Smith <richard-llvm at metafoo.co.uk>:
> > Author: rsmith
> > Date: Fri Mar 7 18:03:56 2014
> > New Revision: 203317
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=203317&view=rev
> > Log:
> > Module [extern_c] attribute: inherit to submodules, don't write 'extern
> "C"'
> > blocks when building in C mode, and serialize and deserialize the
> attribute.
> >
> > Added:
> > cfe/trunk/test/Modules/Inputs/elsewhere/
> > cfe/trunk/test/Modules/Inputs/elsewhere/c-header-indirect.h
> > cfe/trunk/test/Modules/Inputs/elsewhere/module.map
> > Modified:
> > cfe/trunk/lib/Basic/Module.cpp
> > cfe/trunk/lib/Frontend/FrontendActions.cpp
> > cfe/trunk/lib/Serialization/ASTReader.cpp
> > cfe/trunk/lib/Serialization/ASTWriter.cpp
> > cfe/trunk/test/Modules/Inputs/module.map
> > cfe/trunk/test/Modules/extern_c.cpp
> > cfe/trunk/unittests/AST/CMakeLists.txt
> >
> > Modified: cfe/trunk/lib/Basic/Module.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Module.cpp?rev=203317&r1=203316&r2=203317&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/Basic/Module.cpp (original)
> > +++ cfe/trunk/lib/Basic/Module.cpp Fri Mar 7 18:03:56 2014
> > @@ -37,6 +37,8 @@ Module::Module(StringRef Name, SourceLoc
> > IsAvailable = false;
> > if (Parent->IsSystem)
> > IsSystem = true;
> > + if (Parent->IsExternC)
> > + IsExternC = true;
> >
> > Parent->SubModuleIndex[Name] = Parent->SubModules.size();
> > Parent->SubModules.push_back(this);
> >
> > Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=203317&r1=203316&r2=203317&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
> > +++ cfe/trunk/lib/Frontend/FrontendActions.cpp Fri Mar 7 18:03:56 2014
> > @@ -132,7 +132,7 @@ static void addHeaderInclude(StringRef H
> > 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 H
> > Includes += "#include \"";
> > Includes += HeaderName;
> > Includes += "\"\n";
> > - if (IsExternC)
> > + if (IsExternC && LangOpts.CPlusPlus)
> > Includes += "}\n";
> > }
> >
> >
> > Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=203317&r1=203316&r2=203317&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
> > +++ cfe/trunk/lib/Serialization/ASTReader.cpp Fri Mar 7 18:03:56 2014
> > @@ -3996,15 +3996,17 @@ bool ASTReader::ReadSubmoduleBlock(Modul
> > }
> >
> > 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++];
>
> Richard, I saw a few tests crashed due to incompatibility of file format.
>
> Failing Tests (2):
> Clang :: Index/retain-comments-from-system-headers.c
> Clang Tools :: pp-trace/pp-trace-modules.cpp
>
> How to reproduce:
> - rm -rf tools/clang/test/Index/Output
> - Checkout r203316
> - Build and run a test (Index/retain-comments-from-system-headers.c)
> - Checkout r203318 (yours)
> - Build and run a test w/o removing test tree.
>
> Lit might be required to sweep Output(s) in test directories, or
> ASTReader might be responsible to check micro-version.
>
> Any idea?
IIUC, building at a different revision should cause us to generate a
different hash and put the files in a different place. Is it possible that
your bot is not picking up the SVN revision number when it builds? I'm
surprised these tests didn't fail when I made the change locally.
In any case, these tests should be cleaning out the cache themselves (for
stability).
> > Module *ParentModule = 0;
> > if (Parent)
> > @@ -4040,6 +4042,7 @@ bool ASTReader::ReadSubmoduleBlock(Modul
> >
> > CurrentModule->IsFromModuleFile = true;
> > CurrentModule->IsSystem = IsSystem || CurrentModule->IsSystem;
> > + CurrentModule->IsExternC = IsExternC;
> > CurrentModule->InferSubmodules = InferSubmodules;
> > CurrentModule->InferExplicitSubmodules = InferExplicitSubmodules;
> > CurrentModule->InferExportWildcard = InferExportWildcard;
> >
> > Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=203317&r1=203316&r2=203317&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
> > +++ cfe/trunk/lib/Serialization/ASTWriter.cpp Fri Mar 7 18:03:56 2014
> > @@ -2225,7 +2225,8 @@ void ASTWriter::WriteSubmodules(Module *
> > 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 *
> > 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);
> >
> > Added: cfe/trunk/test/Modules/Inputs/elsewhere/c-header-indirect.h
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/elsewhere/c-header-indirect.h?rev=203317&view=auto
> >
> ==============================================================================
> > --- cfe/trunk/test/Modules/Inputs/elsewhere/c-header-indirect.h (added)
> > +++ cfe/trunk/test/Modules/Inputs/elsewhere/c-header-indirect.h Fri Mar
> 7 18:03:56 2014
> > @@ -0,0 +1 @@
> > +#include "c-header.h"
> >
> > Added: cfe/trunk/test/Modules/Inputs/elsewhere/module.map
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/elsewhere/module.map?rev=203317&view=auto
> >
> ==============================================================================
> > --- cfe/trunk/test/Modules/Inputs/elsewhere/module.map (added)
> > +++ cfe/trunk/test/Modules/Inputs/elsewhere/module.map Fri Mar 7
> 18:03:56 2014
> > @@ -0,0 +1 @@
> > +module c_library_indirect { header "c-header-indirect.h" }
> >
> > Modified: cfe/trunk/test/Modules/Inputs/module.map
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/module.map?rev=203317&r1=203316&r2=203317&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/test/Modules/Inputs/module.map (original)
> > +++ cfe/trunk/test/Modules/Inputs/module.map Fri Mar 7 18:03:56 2014
> > @@ -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" }
> >
> > Modified: cfe/trunk/test/Modules/extern_c.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/extern_c.cpp?rev=203317&r1=203316&r2=203317&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/test/Modules/extern_c.cpp (original)
> > +++ cfe/trunk/test/Modules/extern_c.cpp Fri Mar 7 18:03:56 2014
> > @@ -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 at -3 {{import of C++ module 'cxx_library' appears
> within extern "C" language linkage specification}}
> > // expected-note at -17 {{extern "C" language linkage specification
> begins here}}
> > #elif defined(NAMESPACE)
> > -// expected-error-re at -6 {{import of module '{{c_library|cxx_library}}'
> appears within namespace 'M'}}
> > +// expected-error-re at -6 {{import of module
> '{{c_library.inner|cxx_library}}' appears within namespace 'M'}}
> > // expected-note at -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 at -2 {{redefinition of 'f' as different kind of
> symbol}}
> > // expected-note at 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
> {{}}
> >
> > Modified: cfe/trunk/unittests/AST/CMakeLists.txt
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/CMakeLists.txt?rev=203317&r1=203316&r2=203317&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/unittests/AST/CMakeLists.txt (original)
> > +++ cfe/trunk/unittests/AST/CMakeLists.txt Fri Mar 7 18:03:56 2014
> > @@ -10,6 +10,7 @@ add_clang_unittest(ASTTests
> > CommentParser.cpp
> > DeclPrinterTest.cpp
> > DeclTest.cpp
> > + ExternalASTSourceTest.cpp
> > SourceLocationTest.cpp
> > StmtPrinterTest.cpp
> > )
> >
> >
> > _______________________________________________
> > cfe-commits mailing list
> > cfe-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140313/8fc6fed4/attachment.html>
More information about the cfe-commits
mailing list