Skip to content

Commit 4630d46

Browse files
authored
[clang] Fix a segfault when M is a nullptr (#130712)
If `MM->getOwningModule` returns nullptr, then `isVisible` is called with nullptr, which then calls `getImportLoc(nullptr)` https://github.com/llvm/llvm-project/blob/077e0c134a31cc16c432ce685458b1de80bfbf84/clang/lib/Lex/PPMacroExpansion.cpp#L208
1 parent ee78697 commit 4630d46

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,12 +520,12 @@ Improvements to Clang's diagnostics
520520
- Several compatibility diagnostics that were incorrectly being grouped under
521521
``-Wpre-c++20-compat`` are now part of ``-Wc++20-compat``. (#GH138775)
522522

523-
- Improved the ``-Wtautological-overlap-compare`` diagnostics to warn about overlapping and non-overlapping ranges involving character literals and floating-point literals.
523+
- Improved the ``-Wtautological-overlap-compare`` diagnostics to warn about overlapping and non-overlapping ranges involving character literals and floating-point literals.
524524
The warning message for non-overlapping cases has also been improved (#GH13473).
525525

526526
- Fixed a duplicate diagnostic when performing typo correction on function template
527527
calls with explicit template arguments. (#GH139226)
528-
528+
529529
- Explanatory note is printed when ``assert`` fails during evaluation of a
530530
constant expression. Prior to this, the error inaccurately implied that assert
531531
could not be used at all in a constant expression (#GH130458)
@@ -709,6 +709,7 @@ Bug Fixes to C++ Support
709709
- Fixed the handling of pack indexing types in the constraints of a member function redeclaration. (#GH138255)
710710
- Clang now correctly parses arbitrary order of ``[[]]``, ``__attribute__`` and ``alignas`` attributes for declarations (#GH133107)
711711
- Fixed a crash when forming an invalid function type in a dependent context. (#GH138657) (#GH115725) (#GH68852)
712+
- Clang no longer segfaults when there is a configuration mismatch between modules and their users (http://crbug.com/400353616).
712713

713714
Bug Fixes to AST Handling
714715
^^^^^^^^^^^^^^^^^^^^^^^^^

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+
// In the following example, when compiling module C, A_H has no owning module.
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)