[clang] [clang] Fix a segfault when M is a nullptr (PR #130712)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 12 23:02:17 PDT 2025
https://github.com/matts1 updated https://github.com/llvm/llvm-project/pull/130712
>From cf5684b715efd0ac5348c1d17e86ad5afe87b193 Mon Sep 17 00:00:00 2001
From: Matt Stark <msta at google.com>
Date: Mon, 10 Mar 2025 13:07:29 +1100
Subject: [PATCH] [clang] Fix a segfault when M is a nullptr
---
clang/include/clang/Basic/Module.h | 2 +-
clang/test/Modules/pr130712.cppm | 35 ++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 1 deletion(-)
create mode 100644 clang/test/Modules/pr130712.cppm
diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h
index 62cc8acf9588b..3d035f0a5f787 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -888,7 +888,7 @@ class VisibleModuleSet {
/// Get the location at which the import of a module was triggered.
SourceLocation getImportLoc(const Module *M) const {
- return M->getVisibilityID() < ImportLocs.size()
+ return M && M->getVisibilityID() < ImportLocs.size()
? ImportLocs[M->getVisibilityID()]
: SourceLocation();
}
diff --git a/clang/test/Modules/pr130712.cppm b/clang/test/Modules/pr130712.cppm
new file mode 100644
index 0000000000000..28275a0145f65
--- /dev/null
+++ b/clang/test/Modules/pr130712.cppm
@@ -0,0 +1,35 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// There are two requirements here to result in the owner of a macro being null.
+// 1) There must be a configuration mismatch between a header and a file it depends on
+// 2) -fmodules-local-submodule-visibility must be enabled.
+
+// Unfortunately, libcxx is compiled with exceptions, but the sysroot it depends on is likely compiled without exceptions.
+
+// RUN: %clang_cc1 -I%t -emit-module -o %t/a.pcm -fmodules %t/module.modulemap -fmodule-name=a -fmodules-local-submodule-visibility
+// 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
+// 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
+
+//--- module.modulemap
+module a { header "a.h" }
+module b { header "b.h" }
+module c { header "c.h" }
+
+//--- a.h
+#ifndef A_H
+#define A_H
+#endif
+
+//--- b.h
+#ifndef B_H
+#define B_H
+
+#include <a.h>
+
+#endif
+
+//--- c.h
+#include <a.h>
+#include <b.h>
More information about the cfe-commits
mailing list