Skip to content

Commit 9d29127

Browse files
committed
[clang] Fix a segfault when M is a nullptr
1 parent 69527b0 commit 9d29127

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

clang/include/clang/Basic/Module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ class VisibleModuleSet {
888888

889889
/// Get the location at which the import of a module was triggered.
890890
SourceLocation getImportLoc(const Module *M) const {
891-
return M->getVisibilityID() < ImportLocs.size()
891+
return M && M->getVisibilityID() < ImportLocs.size()
892892
? ImportLocs[M->getVisibilityID()]
893893
: SourceLocation();
894894
}

clang/test/Modules/pr130712.cppm

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: split-file %s %t
2+
3+
// There are two requirements here to result in the owner of a macro being null.
4+
// 1) There must be a configuration mismatch between a header and a file it depends on
5+
// 2) -fmodules-local-submodule-visibility must be enabled.
6+
7+
// Unfortunately, libcxx is compiled with exceptions, but the sysroot it depends on is likely compiled without exceptions.
8+
9+
// RUN: %clang_cc1 -I%t -emit-module -o %t/a.pcm -fmodules %t/module.modulemap -fmodule-name=a -fmodules-local-submodule-visibility
10+
// RUN: %clang_cc1 -fexceptions -Wno-module-file-config-mismatch -I%t -emit-module -o %t/b.pcm -fmodules %t/module.modulemap -fmodule-name=b -fmodules-local-submodule-visibility -fmodule-file=%t/a.pcm
11+
// RUN: %clang_cc1 -fexceptions -Wno-module-file-config-mismatch -I%t -emit-module -o %t/c.pcm -fmodules %t/module.modulemap -fmodule-name=c -fmodules-local-submodule-visibility -fmodule-file=%t/a.pcm -fmodule-file=%t/b.pcm
12+
13+
//--- module.modulemap
14+
module a { header "a.h" }
15+
module b { header "b.h" }
16+
module c { header "c.h" }
17+
18+
//--- a.h
19+
#ifndef A_H
20+
#define A_H
21+
#endif
22+
23+
//--- b.h
24+
#ifndef B_H
25+
#define B_H
26+
27+
#include <a.h>
28+
29+
#endif
30+
31+
//--- c.h
32+
#include <a.h>
33+
#include <b.h>

0 commit comments

Comments
 (0)