[PATCH] D144074: [clangd] Hide inlay hints when using a macro as a calling argument that with a param comment

Younan Zhang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 25 01:06:03 PST 2023


zyounan added inline comments.


================
Comment at: clang-tools-extra/clangd/InlayHints.cpp:520
     auto ExprStartLoc = SM.getTopMacroCallerLoc(E->getBeginLoc());
-    auto Decomposed = SM.getDecomposedLoc(ExprStartLoc);
+    auto Decomposed = SM.getDecomposedExpansionLoc(ExprStartLoc);
     if (Decomposed.first != MainFileID)
----------------
nridge wrote:
> I admit I struggle with this spelling/expansion loc stuff. But having spent a bit of time reading the implementations of these functions, would I be correct to say that another, perhaps easier to follow, way to express the same thing would be:
> 
> ```
> auto Decomposed = SM.getDecomposedLoc(SM.getFileLoc(E->getBeginLoc()));
> ```
> 
> ?
Yes, indeed. `SM.getFileLoc` performs exactly the same function as `getTopMacroCallerLoc` and `getDecomposedExpansionLoc`: 
If Loc is a FileID, just return Loc. 
In another case it falls into a loop until the result is a FileID: First obtain the "top macro caller" location, then the beginning expansion location.


================
Comment at: clang-tools-extra/clangd/InlayHints.cpp:521
+    auto Decomposed = SM.getDecomposedExpansionLoc(ExprStartLoc);
     if (Decomposed.first != MainFileID)
       return false;
----------------
nridge wrote:
> zyounan wrote:
> > stupid question: I was suspicious with this check that when would `Decomposed.first` not being the same as MainFileID? Should the "top-caller" of the macro always be in main file? I didn't find a case that differs, except when `getDecomposedLoc` provides wrong FileID.
> I tried adding an assertion in this early-return branch, and it tripped in `ParameterHints.IncludeAtNonGlobalScope`.
> 
> The code there is:
> 
> ```
>   Annotations FooInc(R"cpp(
>     void bar() { foo(42); }
>   )cpp");
>   Annotations FooCC(R"cpp(
>     struct S {
>       void foo(int param);
>       #include "foo.inc"
>     };
>   )cpp");
> ```
> 
> so I guess the decomposed loc there is a file loc, but not in the main file (but rather in `foo.inc`).
Ah, I see. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144074



More information about the cfe-commits mailing list