[all-commits] [llvm/llvm-project] 67268e: [Syntax] Fix macro-arg handling in TokenBuffer::sp...

Sam McCall via All-commits all-commits at lists.llvm.org
Wed Oct 5 09:04:58 PDT 2022

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 67268ee11c220b1dfdf84afb10a12371c5ae6400
  Author: Sam McCall <sam.mccall at gmail.com>
  Date:   2022-10-05 (Wed, 05 Oct 2022)

  Changed paths:
    M clang/lib/Tooling/Syntax/Tokens.cpp
    M clang/unittests/Tooling/Syntax/TokensTest.cpp

  Log Message:
  [Syntax] Fix macro-arg handling in TokenBuffer::spelledForExpanded

A few cases were not handled correctly. Notably:
  #define ID(X) X
  #define HIDE a ID(b)
spelledForExpanded() would claim HIDE is an equivalent range of the 'b' it
contains, despite the fact that HIDE also covers 'a'.

While trying to fix this bug, I found findCommonRangeForMacroArgs hard
to understand (both the implementation and how it's used in spelledForExpanded).
It relies on details of the SourceLocation graph that are IMO fairly obscure.
So I've added/revised quite a lot of comments and made some naming tweaks.

Fixes https://github.com/clangd/clangd/issues/1289

Differential Revision: https://reviews.llvm.org/D134618

More information about the All-commits mailing list