Author: rsmith Date: Thu May 18 14:34:55 2017 New Revision: 303373 URL: http://llvm.org/viewvc/llvm-project?rev=303373&view=rev Log: When we enter a module within a linkage specification, switch the linkage specification and the TU to the new module.
This is necessary to get the module ownership correct for entities that we temporarily hang off the TranslationUnitDecl, such as template parameters and function parameters. Added: cfe/trunk/test/Modules/extern_cxx.cpp Modified: cfe/trunk/lib/Sema/SemaDecl.cpp Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=303373&r1=303372&r2=303373&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu May 18 14:34:55 2017 @@ -16048,8 +16048,10 @@ void Sema::ActOnModuleBegin(SourceLocati // FIXME: Consider creating a child DeclContext to hold the entities // lexically within the module. if (getLangOpts().trackLocalOwningModule()) { - cast<Decl>(CurContext)->setHidden(true); - cast<Decl>(CurContext)->setLocalOwningModule(Mod); + for (auto *DC = CurContext; DC; DC = DC->getLexicalParent()) { + cast<Decl>(DC)->setHidden(true); + cast<Decl>(DC)->setLocalOwningModule(Mod); + } } } @@ -16082,9 +16084,13 @@ void Sema::ActOnModuleEnd(SourceLocation // Any further declarations are in whatever module we returned to. if (getLangOpts().trackLocalOwningModule()) { - cast<Decl>(CurContext)->setLocalOwningModule(getCurrentModule()); - if (!getCurrentModule()) - cast<Decl>(CurContext)->setHidden(false); + // The parser guarantees that this is the same context that we entered + // the module within. + for (auto *DC = CurContext; DC; DC = DC->getLexicalParent()) { + cast<Decl>(DC)->setLocalOwningModule(getCurrentModule()); + if (!getCurrentModule()) + cast<Decl>(DC)->setHidden(false); + } } } Added: cfe/trunk/test/Modules/extern_cxx.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/extern_cxx.cpp?rev=303373&view=auto ============================================================================== --- cfe/trunk/test/Modules/extern_cxx.cpp (added) +++ cfe/trunk/test/Modules/extern_cxx.cpp Thu May 18 14:34:55 2017 @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -x c++-module-map -fmodule-name=A -verify %s -fmodules-local-submodule-visibility +module A { module B {} module C {} } + +#pragma clang module contents + +#pragma clang module begin A.B +extern "C++" { + #pragma clang module begin A.C + template<typename T> void f(T t); + #pragma clang module end + + void g() { f(0); } // ok +} + +extern "C++" { + #pragma clang module begin A.C + } // expected-error {{extraneous closing brace}} + #pragma clang module end + + #pragma clang module begin A.C + extern "C++" { // expected-note {{to match this '{'}} + #pragma clang module end // expected-error {{expected '}' at end of module}} +} + +#pragma clang module end _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits