teemperor updated this revision to Diff 99728. teemperor edited the summary of this revision. teemperor added a comment.
- Now unhiding/unowning the created functions like Richard suggested. - Extended the test case to stress test the lookup with the new visibility settings. https://reviews.llvm.org/D33366 Files: lib/Sema/SemaExprCXX.cpp test/Modules/Inputs/local-submodule-globaldelete/a.h test/Modules/Inputs/local-submodule-globaldelete/b.h test/Modules/Inputs/local-submodule-globaldelete/c.h test/Modules/Inputs/local-submodule-globaldelete/module.modulemap test/Modules/local-submodule-globaldelete.cpp Index: test/Modules/local-submodule-globaldelete.cpp =================================================================== --- /dev/null +++ test/Modules/local-submodule-globaldelete.cpp @@ -0,0 +1,23 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: cp -r %S/Inputs/local-submodule-globaldelete %t/local-submodule-globaldelete +// RUN: cd %t +// RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -verify -fmodules-cache-path=%t -fimplicit-module-maps -I local-submodule-globaldelete %s -H + +// expected-no-diagnostics + +// This tests that the global delete operator is not by accident assigned +// to a submodule in local-submodule-visibility mode. This could happen +// when the operator is created on demand when we discover a virtual destructor +// inside a module. + +// Build a module with submodules that each need the global delete operator. +#include "a.h" +// Build another module with another global delete operator to check that +// we didn't introduced ambiguity in the lookup. +#include "c.h" + +// Require a lookup of the global delete operator. +class T { + virtual ~T() {} +}; Index: test/Modules/Inputs/local-submodule-globaldelete/module.modulemap =================================================================== --- /dev/null +++ test/Modules/Inputs/local-submodule-globaldelete/module.modulemap @@ -0,0 +1,7 @@ +module M { + module a { header "a.h" export * } + module b { header "b.h" export * } +} +module Other { + module c { header "c.h" export * } +} Index: test/Modules/Inputs/local-submodule-globaldelete/c.h =================================================================== --- /dev/null +++ test/Modules/Inputs/local-submodule-globaldelete/c.h @@ -0,0 +1,6 @@ +#ifndef C_H +#define C_H +class C { + virtual ~C(){}; +}; +#endif Index: test/Modules/Inputs/local-submodule-globaldelete/b.h =================================================================== --- /dev/null +++ test/Modules/Inputs/local-submodule-globaldelete/b.h @@ -0,0 +1,6 @@ +#ifndef B_H +#define B_H +class B { + virtual ~B(){}; +}; +#endif Index: test/Modules/Inputs/local-submodule-globaldelete/a.h =================================================================== --- /dev/null +++ test/Modules/Inputs/local-submodule-globaldelete/a.h @@ -0,0 +1,6 @@ +#ifndef A_H +#define A_H +class A { + virtual ~A(){}; +}; +#endif Index: lib/Sema/SemaExprCXX.cpp =================================================================== --- lib/Sema/SemaExprCXX.cpp +++ lib/Sema/SemaExprCXX.cpp @@ -2658,6 +2658,15 @@ Context, GlobalCtx, SourceLocation(), SourceLocation(), Name, FnType, /*TInfo=*/nullptr, SC_None, false, true); Alloc->setImplicit(); + // If we're in local visibility mode, we reuse this allocation function + // in all submodules of the current module. To make sure that the other + // submodules can lookup this function, we unhide it and make sure it's + // not owned by the current submodule. + if (getLangOpts().ModulesLocalVisibility && + !getLangOpts().CurrentModule.empty()) { + Alloc->setLocalOwningModule(nullptr); + Alloc->setHidden(false); + } // Implicit sized deallocation functions always have default visibility. Alloc->addAttr(
Index: test/Modules/local-submodule-globaldelete.cpp =================================================================== --- /dev/null +++ test/Modules/local-submodule-globaldelete.cpp @@ -0,0 +1,23 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: cp -r %S/Inputs/local-submodule-globaldelete %t/local-submodule-globaldelete +// RUN: cd %t +// RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -verify -fmodules-cache-path=%t -fimplicit-module-maps -I local-submodule-globaldelete %s -H + +// expected-no-diagnostics + +// This tests that the global delete operator is not by accident assigned +// to a submodule in local-submodule-visibility mode. This could happen +// when the operator is created on demand when we discover a virtual destructor +// inside a module. + +// Build a module with submodules that each need the global delete operator. +#include "a.h" +// Build another module with another global delete operator to check that +// we didn't introduced ambiguity in the lookup. +#include "c.h" + +// Require a lookup of the global delete operator. +class T { + virtual ~T() {} +}; Index: test/Modules/Inputs/local-submodule-globaldelete/module.modulemap =================================================================== --- /dev/null +++ test/Modules/Inputs/local-submodule-globaldelete/module.modulemap @@ -0,0 +1,7 @@ +module M { + module a { header "a.h" export * } + module b { header "b.h" export * } +} +module Other { + module c { header "c.h" export * } +} Index: test/Modules/Inputs/local-submodule-globaldelete/c.h =================================================================== --- /dev/null +++ test/Modules/Inputs/local-submodule-globaldelete/c.h @@ -0,0 +1,6 @@ +#ifndef C_H +#define C_H +class C { + virtual ~C(){}; +}; +#endif Index: test/Modules/Inputs/local-submodule-globaldelete/b.h =================================================================== --- /dev/null +++ test/Modules/Inputs/local-submodule-globaldelete/b.h @@ -0,0 +1,6 @@ +#ifndef B_H +#define B_H +class B { + virtual ~B(){}; +}; +#endif Index: test/Modules/Inputs/local-submodule-globaldelete/a.h =================================================================== --- /dev/null +++ test/Modules/Inputs/local-submodule-globaldelete/a.h @@ -0,0 +1,6 @@ +#ifndef A_H +#define A_H +class A { + virtual ~A(){}; +}; +#endif Index: lib/Sema/SemaExprCXX.cpp =================================================================== --- lib/Sema/SemaExprCXX.cpp +++ lib/Sema/SemaExprCXX.cpp @@ -2658,6 +2658,15 @@ Context, GlobalCtx, SourceLocation(), SourceLocation(), Name, FnType, /*TInfo=*/nullptr, SC_None, false, true); Alloc->setImplicit(); + // If we're in local visibility mode, we reuse this allocation function + // in all submodules of the current module. To make sure that the other + // submodules can lookup this function, we unhide it and make sure it's + // not owned by the current submodule. + if (getLangOpts().ModulesLocalVisibility && + !getLangOpts().CurrentModule.empty()) { + Alloc->setLocalOwningModule(nullptr); + Alloc->setHidden(false); + } // Implicit sized deallocation functions always have default visibility. Alloc->addAttr(
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits