[PATCH] D144115: [clang] Extend pragma dump to support expressions
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 21 12:11:59 PDT 2023
aaron.ballman added a comment.
You should also add a release note to clang/docs/ReleaseNotes.rst so users know about the new functionality.
================
Comment at: clang/docs/LanguageExtensions.rst:4884
+Syntax is the following: `#pragma clang __debug <command> <arguments>`.
+Note that all of them are a subject to change.
+
----------------
================
Comment at: clang/docs/LanguageExtensions.rst:4888-4895
+Accepts a single identifier or an expression. When a single identifier is passed,
+prints name lookup results. When an expression is passed, prints its AST.
+Expression is evaluated as if it appears in the program.
+Type- and value-dependent expressions are not supported yet.
+
+This facility is designed to aid with testing name lookup machinery.
+Expression form addresses some of shortcomings of single identifier form,
----------------
================
Comment at: clang/include/clang/Basic/DiagnosticLexKinds.td:662-665
+def warn_pragma_debug_type_dependent_argument : Warning<
+ "type-dependent expression passed as an argument to debug command">, InGroup<IgnoredPragmas>;
+def warn_pragma_debug_value_dependent_argument : Warning<
+ "value-dependent expression passed as an argument to debug command">, InGroup<IgnoredPragmas>;
----------------
We can use a `select` here so we only need one new diagnostic.
This should be moved to `DiagnosticParseKinds.td` because it's emitted from the parser, not the lexer.
================
Comment at: clang/lib/Parse/ParsePragma.cpp:15-17
#include "clang/Basic/TargetInfo.h"
+#include "clang/Lex/LexDiagnostic.h"
#include "clang/Lex/Preprocessor.h"
----------------
================
Comment at: clang/lib/Parse/ParsePragma.cpp:731-736
+ } else if (E.get()->isTypeDependent()) {
+ PP.Diag(StartLoc, diag::warn_pragma_debug_type_dependent_argument)
+ << SourceRange(StartLoc, Tok.getLocation());
+ } else if (E.get()->isValueDependent()) {
+ PP.Diag(StartLoc, diag::warn_pragma_debug_value_dependent_argument)
+ << SourceRange(StartLoc, Tok.getLocation());
----------------
================
Comment at: clang/test/AST/ast-dump-lookups.cpp:83
+#endif
\ No newline at end of file
----------------
You should add the newline back to the end of the file.
I'd also like to see a test case where the expression has errors, like:
```
#pragma clang __debug dump this is nonsense
```
and where the expression causes an instantiation:
```
template <typename T>
struct S {
static constexpr const T *str = "string";
};
template <>
struct S<wchar_t> {
static constexpr const wchar_t *str = L"wide string";
};
void func() {
#pragma clang __debug dump S<wchar_t>::str;
}
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D144115/new/
https://reviews.llvm.org/D144115
More information about the cfe-commits
mailing list