Skip to content

[clang] Add #pragma clang __debug module_lookup #129158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticLexKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,8 @@ def warn_pragma_debug_unexpected_command : Warning<
"unexpected debug command '%0'">, InGroup<IgnoredPragmas>;
def warn_pragma_debug_unknown_module : Warning<
"unknown module '%0'">, InGroup<IgnoredPragmas>;
def warn_pragma_debug_unable_to_find_module : Warning<
"unable to find module '%0'">, InGroup<IgnoredPragmas>;
// #pragma module
def err_pp_expected_module_name : Error<
"expected %select{identifier after '.' in |}0module name">;
Expand Down
18 changes: 17 additions & 1 deletion clang/lib/Lex/Pragma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1119,11 +1119,27 @@ struct PragmaDebugHandler : public PragmaHandler {
M = MM.lookupModuleQualified(IIAndLoc.first->getName(), M);
if (!M) {
PP.Diag(IIAndLoc.second, diag::warn_pragma_debug_unknown_module)
<< IIAndLoc.first;
<< IIAndLoc.first->getName();
return;
}
}
M->dump();
} else if (II->isStr("module_lookup")) {
Token MName;
PP.LexUnexpandedToken(MName);
auto *MNameII = MName.getIdentifierInfo();
if (!MNameII) {
PP.Diag(MName, diag::warn_pragma_debug_missing_argument)
<< II->getName();
return;
}
Module *M = PP.getHeaderSearchInfo().lookupModule(MNameII->getName());
if (!M) {
PP.Diag(MName, diag::warn_pragma_debug_unable_to_find_module)
<< MNameII->getName();
return;
}
M->dump();
} else if (II->isStr("overflow_stack")) {
if (!PP.getPreprocessorOpts().DisablePragmaDebugCrash)
DebugOverflowStack();
Expand Down
22 changes: 22 additions & 0 deletions clang/test/Modules/clang-pragmas.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// RUN: rm -rf %t
// RUN: split-file %s %t
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -I%t %t/tu.c -fsyntax-only \
// RUN: -verify 2>&1 | FileCheck %s

//--- module.modulemap

module A {
header "A.h"
}

//--- A.h

//--- tu.c

#pragma clang __debug module_map A // expected-warning{{unknown module 'A'}}
#pragma clang __debug module_lookup B // expected-warning{{unable to find module 'B'}}
#pragma clang __debug module_lookup A // does header search for A
#pragma clang __debug module_map A // now finds module A

// CHECK: module A
// CHECK: module A