[PATCH] D56753: [ASTDump] Mark null params with a tag rather than a child node

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 17 07:21:11 PST 2019


aaron.ballman added inline comments.


================
Comment at: lib/AST/ASTDumper.cpp:642
 
-  if (!D->param_begin() && D->getNumParams())
-    dumpChild([=] { OS << "<<NULL params x " << D->getNumParams() << ">>"; });
-  else
-    for (const ParmVarDecl *Parameter : D->parameters())
+  if (D->param_begin() || !D->getNumParams())
+    for (const auto *Parameter : D->parameters())
----------------
aaron.ballman wrote:
> You can drop `getNumParams()` here -- if `param_begin()` returns a non-null value, `getNumParams()` must return a non-zero value.
> 
> (`param_begin()` is implemented in terms of `parameters()`, which calls `getNumParams()` when setting up the returned `ArrayRef`.)
It seems that this is needed because the situation can arise when the function is not fully constructed yet, such as when calling `dump()` under the debugger.

I think this can be more clearly expressed as `if (!D->param_empty() && !D->param_begin())`, but should also have some comments explaining that this is guarding against a situation that only comes up while debugging, and thus is not covered by any existing test cases.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56753/new/

https://reviews.llvm.org/D56753





More information about the cfe-commits mailing list