File tree Expand file tree Collapse file tree 2 files changed +88
-0
lines changed Expand file tree Collapse file tree 2 files changed +88
-0
lines changed Original file line number Diff line number Diff line change @@ -938,6 +938,20 @@ void DumpModuleInfoAction::ExecuteAction() {
938938 }
939939 }
940940 }
941+
942+ // Emit the macro definitions in the module file so that we can know how
943+ // much definitions in the module file quickly.
944+ // TODO: Emit the macro definition bodies completely.
945+ if (auto FilteredMacros = llvm::make_filter_range (
946+ R->getPreprocessor ().macros (),
947+ [](const auto &Macro) { return Macro.first ->isFromAST (); });
948+ !FilteredMacros.empty ()) {
949+ Out << " Macro Definitions:\n " ;
950+ for (/* <IdentifierInfo *, MacroState> pair*/ const auto &Macro :
951+ FilteredMacros)
952+ Out << " " << Macro.first ->getName () << " \n " ;
953+ }
954+
941955 // Now let's print out any modules we did not see as part of the Primary.
942956 for (auto SM : SubModMap) {
943957 if (!SM.second .Seen && SM.second .Mod ) {
Original file line number Diff line number Diff line change 1+ // Test the output from -module-file-info about C++20 Modules
2+ // can reflect macros definitions correctly.
3+ // RUN: rm -rf %t
4+ // RUN: mkdir -p %t
5+ // RUN: split-file %s %t
6+ //
7+ // RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/foo.h -o %t/foo.pcm
8+ // RUN: %clang_cc1 -module-file-info %t/foo.pcm | FileCheck %t/foo.h
9+ //
10+ // RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/include_foo.h -o %t/include_foo.pcm
11+ // RUN: %clang_cc1 -module-file-info %t/include_foo.pcm | FileCheck %t/include_foo.h
12+
13+ // RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header -fmodule-file=%t/foo.pcm \
14+ // RUN: %t/import_foo.h -o %t/import_foo.pcm
15+ // RUN: %clang_cc1 -module-file-info %t/import_foo.pcm | FileCheck %t/import_foo.h
16+ //
17+ // RUN: %clang_cc1 -std=c++20 %t/named_module.cppm -emit-module-interface -o %t/M.pcm
18+ // RUN: %clang_cc1 -module-file-info %t/M.pcm | FileCheck %t/named_module.cppm
19+
20+ // --- foo.h
21+ #pragma once
22+ #define FOO
23+ #define CONSTANT 43
24+ #define FUNC_Macro (X ) (X+1 )
25+ #define TO_BE_UNDEF
26+ #undef TO_BE_UNDEF
27+
28+ #ifndef FOO
29+ #define CONDITIONAL_DEF
30+ #endif
31+
32+ #define REDEFINE
33+ #define REDEFINE
34+
35+ // CHECK: Macro Definitions:
36+ // CHECK-DAG: REDEFINE
37+ // CHECK-DAG: FUNC_Macro
38+ // CHECK-DAG: CONSTANT
39+ // CHECK-DAG: FOO
40+ // CHECK-NEXT: ===
41+
42+ // --- include_foo.h
43+ #include " foo.h"
44+ #undef REDEFINE
45+ // CHECK: Macro Definitions:
46+ // CHECK-DAG: CONSTANT
47+ // CHECK-DAG: FUNC_Macro
48+ // CHECK-DAG: FOO
49+ // CHECK-NEXT: ===
50+
51+ // --- import_foo.h
52+ import " foo.h" ;
53+ #undef REDEFINE
54+ // CHECK: Macro Definitions:
55+ // CHECK-DAG: CONSTANT
56+ // CHECK-DAG: FUNC_Macro
57+ // CHECK-DAG: FOO
58+ // CHECK-NEXT: ===
59+
60+ // --- named_module.cppm
61+ module ;
62+ #include " foo.h"
63+ export module M;
64+ #define M_Module 43
65+ // FIXME: It is meaningless for named modules to emit macro definitions.
66+ // It wastes the time and spaces completely.
67+ // CHECK: Macro Definitions:
68+ // CHECK-DAG: M_Module
69+ // CHECK-DAG: REDEFINE
70+ // CHECK-DAG: FUNC_Macro
71+ // CHECK-DAG: TO_BE_UNDEF
72+ // CHECK-DAG: FOO
73+ // CHECK-DAG: CONSTANT
74+ // CHECK-NEXT: ===
You can’t perform that action at this time.
0 commit comments