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

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 13 00:03:49 PDT 2023


kadircet added inline comments.


================
Comment at: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp:450
+    void test() {
+      1s;
+    }
----------------
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?)


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