Skip to content

Commit 0a42c7c

Browse files
authored
[clang] fix assert in ADL finding entity in the implicit global module (#109882)
This adds to the assert the implicit global module case as in module purview. Fixes #109879
1 parent 3da5e82 commit 0a42c7c

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ code bases.
4343
still supporting SPARC V8 CPUs need to specify ``-mcpu=v8`` with a
4444
`config file
4545
<https://clang.llvm.org/docs/UsersManual.html#configuration-files>`_.
46-
46+
4747
- The ``clang-rename`` tool has been removed.
4848

4949
C/C++ Language Potentially Breaking Changes
@@ -115,7 +115,7 @@ C++ Language Changes
115115
- Allow single element access of GCC vector/ext_vector_type object to be
116116
constant expression. Supports the `V.xyzw` syntax and other tidbits
117117
as seen in OpenCL. Selecting multiple elements is left as a future work.
118-
- Implement `CWG1815 <https://wg21.link/CWG1815>`_. Support lifetime extension
118+
- Implement `CWG1815 <https://wg21.link/CWG1815>`_. Support lifetime extension
119119
of temporary created by aggregate initialization using a default member
120120
initializer.
121121

@@ -452,6 +452,9 @@ Miscellaneous Clang Crashes Fixed
452452

453453
- Fixed ``-ast-dump`` crashes on codes involving ``concept`` with ``-ast-dump-decl-types``. (#GH94928)
454454

455+
- Fixed internal assertion firing when a declaration in the implicit global
456+
module is found through ADL. (GH#109879)
457+
455458
OpenACC Specific Changes
456459
------------------------
457460

clang/lib/Sema/SemaLookup.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3850,8 +3850,9 @@ void Sema::ArgumentDependentLookup(DeclarationName Name, SourceLocation Loc,
38503850
// exports are only valid in module purview and outside of any
38513851
// PMF (although a PMF should not even be present in a module
38523852
// with an import).
3853-
assert(FM && FM->isNamedModule() && !FM->isPrivateModule() &&
3854-
"bad export context");
3853+
assert(FM &&
3854+
(FM->isNamedModule() || FM->isImplicitGlobalModule()) &&
3855+
!FM->isPrivateModule() && "bad export context");
38553856
// .. are attached to a named module M, do not appear in the
38563857
// translation unit containing the point of the lookup..
38573858
if (D->isInAnotherModuleUnit() &&

clang/test/Modules/GH109879-1.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
// RUN: split-file %s %t
4+
//
5+
// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
6+
// RUN: %clang_cc1 -std=c++20 %t/B.cppm -fprebuilt-module-path=%t -emit-module-interface -o %t/B.pcm
7+
// RUN: %clang_cc1 -fsyntax-only -std=c++20 -fprebuilt-module-path=%t -verify %t/C.cpp
8+
9+
//--- A.cppm
10+
export module A;
11+
export extern "C" void foo(struct Bar);
12+
13+
//--- B.cppm
14+
module;
15+
import A;
16+
export module B;
17+
18+
//--- C.cpp
19+
import B;
20+
struct Bar {};
21+
void test() {
22+
foo(Bar());
23+
// expected-error@-1 {{declaration of 'foo' must be imported}}
24+
// [email protected]:2 {{declaration here is not visible}}
25+
}

clang/test/Modules/GH109879-2.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
// RUN: split-file %s %t
4+
//
5+
// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
6+
// RUN: %clang_cc1 -std=c++20 %t/B.cppm -fprebuilt-module-path=%t -emit-module-interface -o %t/B.pcm
7+
// RUN: %clang_cc1 -fsyntax-only -std=c++20 -fprebuilt-module-path=%t -verify %t/C.cpp
8+
9+
//--- foo.h
10+
struct Bar {};
11+
extern "C" void foo(struct Bar);
12+
13+
//--- A.cppm
14+
module;
15+
#include "foo.h"
16+
export module A;
17+
export extern "C" using ::foo;
18+
//--- B.cppm
19+
module;
20+
import A;
21+
export module B;
22+
23+
//--- C.cpp
24+
// expected-no-diagnostics
25+
import B;
26+
#include "foo.h"
27+
void test() {
28+
foo(Bar());
29+
}

0 commit comments

Comments
 (0)