[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 6 05:39:25 PDT 2023


hokein added a comment.

In D147686#4248330 <https://reviews.llvm.org/D147686#4248330>, @kadircet wrote:

> could you give some more details about the crash, so that we actually now where to fix it? e.g. is it token buffers missing the spelled token at that offset somehow ? or is it AST reporting a weird source locations for user-defined literals and we need to do some sort of post processing (or maybe it should've been filtered all together). as doing it like this will imply us completely eating such diagnostics.

sorry, for not giving more details. See the other comment.



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


================
Comment at: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp:458
+  auto Findings = computeIncludeCleanerFindings(AST);
+  EXPECT_THAT(Findings.MissingIncludes, IsEmpty());
+}
----------------
T


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