[PATCH] D147686: [clangd] Fix a nullptr-dereference crash in computeIncludeCleanerFindings.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 13 02:40:13 PDT 2023


hokein added inline comments.


================
Comment at: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp:450
+    void test() {
+      1s;
+    }
----------------
kadircet wrote:
> hokein wrote:
> > here is the `UserDefinedLiteral` AST node:
> > 
> > ```
> > `-UserDefinedLiteral 0x5556682e4500 <line:46:3> 'int'
> >       |-ImplicitCastExpr 0x5556682e44e8 <col:4> 'int (*)(unsigned long long)' <FunctionToPointerDecay>
> >       | `-DeclRefExpr 0x5556682e44a0 <col:4> 'int (unsigned long long)' lvalue Function 0x5556682e4290 'operator""s' 'int (unsigned long long)'
> >       `-IntegerLiteral 0x5556682e4480 <col:3> 'unsigned long long' 1
> > ```
> > 
> > The source location of the `UserDefinedLiteral` points to `^1s`, while the source location of the inner `DeclRefExpr` points to `1^s` (1 offset shift). In the token buffer, we only have a single spelled token `1s`, thus `AST.getTokens().spelledTokenAt` can not find any token that starts at `1^s` source loc.
> thanks, that makes sense!
> 
> then instead of "suppressing" these, can we use `spelledTokensTouching().front()` (and asserting that it isn't empty?)
Thanks, this is a good idea.

But we have to use the `back()`, for the case `ns::^abc` (we want to point to `abc`, not the `::`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147686



More information about the cfe-commits mailing list