[clang] ab0116e - [Clang] Improve error message for violations of -fmodules-decluse.
James Y Knight via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 31 06:57:30 PST 2023
Author: James Y Knight
Date: 2023-01-31T09:57:23-05:00
New Revision: ab0116e2f05c6156c4bc3d35986de1e98cc27016
URL: https://github.com/llvm/llvm-project/commit/ab0116e2f05c6156c4bc3d35986de1e98cc27016
DIFF: https://github.com/llvm/llvm-project/commit/ab0116e2f05c6156c4bc3d35986de1e98cc27016.diff
LOG: [Clang] Improve error message for violations of -fmodules-decluse.
Now it reports the name of the indirectly-used module which is
missing.
Reviewed By: ChuanqiXu
Differential Revision: https://reviews.llvm.org/D142925
Added:
Modified:
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/ModuleMap.cpp
clang/test/Modules/Inputs/declare-use/h.h
clang/test/Modules/declare-use-textual.cpp
clang/test/Modules/declare-use1.cpp
clang/test/Modules/declare-use2.cpp
clang/test/Modules/declare-use3.cpp
clang/test/Modules/strict-decluse.cpp
clang/test/Modules/string_names.cpp
clang/test/Modules/textual-headers.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 3b1b466e7602b..0fb8d196dd6a5 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -888,6 +888,8 @@ def warn_use_of_private_header_outside_module : Warning<
InGroup<DiagGroup<"private-header">>, DefaultError;
def err_undeclared_use_of_module : Error<
"module %0 does not depend on a module exporting '%1'">;
+def err_undeclared_use_of_module_indirect : Error<
+ "module %0 does not directly depend on a module exporting '%1', which is part of indirectly-used module %2">;
def warn_non_modular_include_in_framework_module : Warning<
"include of non-modular header inside framework module '%0': '%1'">,
InGroup<NonModularIncludeInFrameworkModule>, DefaultIgnore;
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index ee2cca4e0814e..15f4377541b48 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -528,8 +528,9 @@ void ModuleMap::diagnoseHeaderInclusion(Module *RequestingModule,
// We have found a module, but we don't use it.
if (NotUsed) {
- Diags.Report(FilenameLoc, diag::err_undeclared_use_of_module)
- << RequestingModule->getTopLevelModule()->Name << Filename;
+ Diags.Report(FilenameLoc, diag::err_undeclared_use_of_module_indirect)
+ << RequestingModule->getTopLevelModule()->Name << Filename
+ << NotUsed->Name;
return;
}
diff --git a/clang/test/Modules/Inputs/declare-use/h.h b/clang/test/Modules/Inputs/declare-use/h.h
index 8984727c565e7..4f63ec24cf8e9 100644
--- a/clang/test/Modules/Inputs/declare-use/h.h
+++ b/clang/test/Modules/Inputs/declare-use/h.h
@@ -1,7 +1,7 @@
#ifndef H_H
#define H_H
#include "c.h"
-#include "d.h" // expected-error {{module XH does not depend on a module exporting}}
+#include "d.h" // expected-error {{module XH does not directly depend on a module exporting 'd.h', which is part of indirectly-used module XD}}
#include "h1.h"
const int h1 = aux_h*c*7*d;
#endif
diff --git a/clang/test/Modules/declare-use-textual.cpp b/clang/test/Modules/declare-use-textual.cpp
index 0cb8c4b18275c..a8b01702794f7 100644
--- a/clang/test/Modules/declare-use-textual.cpp
+++ b/clang/test/Modules/declare-use-textual.cpp
@@ -2,5 +2,5 @@
// RUN: %clang_cc1 -fimplicit-module-maps -fmodules-cache-path=%t -fmodules-decluse -fmodule-name=Textual -I %S/Inputs/declare-use %s -verify
// RUN: %clang_cc1 -fimplicit-module-maps -fmodules-cache-path=%t -fmodules-decluse -fmodule-name=Textual -I %S/Inputs/declare-use %s -fno-modules-validate-textual-header-includes
-// expected-error at textual.h:* {{module Textual does not depend on a module exporting 'a.h'}}
+// expected-error at textual.h:* {{module Textual does not directly depend on a module exporting 'a.h', which is part of indirectly-used module XA}}
#include "textual.h"
diff --git a/clang/test/Modules/declare-use1.cpp b/clang/test/Modules/declare-use1.cpp
index 58eb317afc09b..0c8a01be36e4f 100644
--- a/clang/test/Modules/declare-use1.cpp
+++ b/clang/test/Modules/declare-use1.cpp
@@ -6,7 +6,7 @@
#include "g.h"
#include "e.h"
-#include "f.h" // expected-error {{module XG does not depend on a module exporting 'f.h'}}
+#include "f.h" // expected-error {{module XG does not directly depend on a module exporting 'f.h', which is part of indirectly-used module XF}}
#include "i.h"
#include "sub.h"
const int g2 = g1 + e + f + aux_i + sub;
diff --git a/clang/test/Modules/declare-use2.cpp b/clang/test/Modules/declare-use2.cpp
index 12689e9d9683e..1999224fcfa06 100644
--- a/clang/test/Modules/declare-use2.cpp
+++ b/clang/test/Modules/declare-use2.cpp
@@ -3,5 +3,5 @@
#include "h.h"
#include "e.h"
-#include "f.h" // expected-error {{module XH does not depend on a module exporting 'f.h'}}
+#include "f.h" // expected-error {{module XH does not directly depend on a module exporting 'f.h', which is part of indirectly-used module XF}}
const int h2 = h1+e+f;
diff --git a/clang/test/Modules/declare-use3.cpp b/clang/test/Modules/declare-use3.cpp
index baa6c77bad13e..b03313af779e2 100644
--- a/clang/test/Modules/declare-use3.cpp
+++ b/clang/test/Modules/declare-use3.cpp
@@ -1,4 +1,4 @@
// RUN: rm -rf %t
// RUN: %clang_cc1 -include "g.h" -include "e.h" -include "f.h" -include "i.h" -fimplicit-module-maps -fmodules-cache-path=%t -fmodules-decluse -fmodule-name=XG -I %S/Inputs/declare-use %s -verify
-// expected-error {{module XG does not depend on a module exporting 'f.h'}}
+// expected-error {{module XG does not directly depend on a module exporting 'f.h', which is part of indirectly-used module XF}}
const int g2 = g1 + e + f + aux_i;
diff --git a/clang/test/Modules/strict-decluse.cpp b/clang/test/Modules/strict-decluse.cpp
index a8b5248b85166..2b04fe999214f 100644
--- a/clang/test/Modules/strict-decluse.cpp
+++ b/clang/test/Modules/strict-decluse.cpp
@@ -3,7 +3,7 @@
#include "g.h"
#include "e.h"
-#include "f.h" // expected-error {{module XG does not depend on a module exporting 'f.h'}}
+#include "f.h" // expected-error {{module XG does not directly depend on a module exporting 'f.h', which is part of indirectly-used module XF}}
#include "i.h" // expected-error {{module XG does not depend on a module exporting 'i.h'}}
const int g2 = g1 + e + f + aux_i;
diff --git a/clang/test/Modules/string_names.cpp b/clang/test/Modules/string_names.cpp
index a6503d048d6b8..a2b4e0362cda2 100644
--- a/clang/test/Modules/string_names.cpp
+++ b/clang/test/Modules/string_names.cpp
@@ -6,5 +6,5 @@
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-decluse -I %S/Inputs/string_names %t/test.ii -fmodule-name="my/module-a"
#include "a.h"
-#include "b.h" // expected-error {{does not depend on a module exporting}}
+#include "b.h" // expected-error {{module my/module-a does not directly depend on a module exporting 'b.h', which is part of indirectly-used module my/module-b}}
#include "c.h"
diff --git a/clang/test/Modules/textual-headers.cpp b/clang/test/Modules/textual-headers.cpp
index 4df741cfe4a33..006ae9686f345 100644
--- a/clang/test/Modules/textual-headers.cpp
+++ b/clang/test/Modules/textual-headers.cpp
@@ -6,9 +6,9 @@
#include "k.h"
#define GIMME_AN_L
-#include "l.h" // expected-error {{module XG does not depend on a module exporting 'l.h'}}
+#include "l.h" // expected-error {{module XG does not directly depend on a module exporting 'l.h', which is part of indirectly-used module XL}}
-#include "m2.h" // expected-error {{module XG does not depend on a module exporting 'm2.h'}}
+#include "m2.h" // expected-error {{module XG does not directly depend on a module exporting 'm2.h', which is part of indirectly-used module XM}}
const int use_m = m; // expected-error {{undeclared identifier}}
#define GIMME_AN_M
More information about the cfe-commits
mailing list