LLVM/project c7317d7clang/lib/CIR/Lowering/DirectToLLVM LowerToLLVM.cpp, clang/test/CIR/CodeGen tls-model.cpp

[CIR][MLIR-LLVM] Add 'thread local mode/model' attribute support (#214337)

The main purpose of this patch is to implement the 'tls_model' attribute
for ClangIR. However, this required updating the LLVM-IR dialect to ALSO
support this, not just as a bool. This patch threads it into both sides.

CIR tries to refer to it as "TLS_Model" to match the C/C++ attribute
closely, the LLVM Dialect refers to it as ThreadLocalMode to reflect
better what LLVM does.

Left as still 'not done' (in CIR only!) is the lowering of the 'other'
kinds of thread-local settings, which are intended to do various levels
of locking/initialization. Those are left for a future implementation
effort. The C++ test itself is taken directly from classic codegen.
DeltaFile
+131-0clang/test/CIR/CodeGen/tls-model.cpp
+45-19mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+56-0mlir/test/Dialect/LLVMIR/alias.mlir
+29-8clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+27-0mlir/test/Dialect/LLVMIR/invalid.mlir
+20-0mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td
+308-2710 files not shown
+385-5216 files

LLVM/project b51765dllvm/lib/Transforms/Vectorize VPlan.h VPlanRecipes.cpp, llvm/test/Transforms/LoopVectorize compress-idioms.ll

[LoopVectorize] Support vectorization of compressing patterns in VPlan

RFC link: https://discourse.llvm.org/t/rfc-loop-vectorization-of-compress-store-expand-load-patterns/86442

This adds loop vectorizer support for "compressing" patterns,
for example:

```
int dst_idx = 0;
for (int i = 0; i < n; i++) {
  if (cond[i])
    dst[dst_idx++] = src[i];
}
```

Can be vectorized with a `llvm.masked.compressstore` as:

```
int dst_idx = 0;

    [52 lines not shown]
DeltaFile
+424-0llvm/test/Transforms/LoopVectorize/compress-idioms.ll
+157-0llvm/test/Transforms/LoopVectorize/VPlan/compress-idioms.ll
+132-0llvm/test/Transforms/LoopVectorize/AArch64/compress-idioms.ll
+111-14llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+70-4llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+60-4llvm/lib/Transforms/Vectorize/VPlan.h
+954-2213 files not shown
+1,096-2719 files

LLVM/project a7cdf80llvm/lib/Transforms/Vectorize LoopVectorize.cpp VPlan.h, llvm/test/Transforms/LoopVectorize compress-store-vec-epilogue.ll

Fix epilogue resume handling
DeltaFile
+98-0llvm/test/Transforms/LoopVectorize/compress-store-vec-epilogue.ll
+5-5llvm/lib/Transforms/Vectorize/VPlan.h
+2-1llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+105-63 files

LLVM/project 530dd70llvm/include/llvm/Analysis IVDescriptors.h, llvm/lib/Analysis IVDescriptors.cpp

[IVDescriptors] Implement MonotonicDescriptor

RFC link: https://discourse.llvm.org/t/rfc-loop-vectorization-of-compress-store-expand-load-patterns/86442

"Monotonic" variable is similar to induction variable, but its value is updated under some condition, e.g.:
```
int idx = 0;
for(int i = 0; i < n; ++i) {
  // some uses of idx
  if (cond)
    ++idx;
}
```
In this example, `i` is induction variable and `idx` is monotonic variable: it's updated only when cond == true. In LLVM IR, this looks like:
```
loop_header:
  %monotonic_phi = [%start, %prehader], [ %chain_phi0, %latch]

step_bb:

    [26 lines not shown]
DeltaFile
+153-0llvm/unittests/Analysis/IVDescriptorsTest.cpp
+121-0llvm/lib/Analysis/IVDescriptors.cpp
+39-0llvm/include/llvm/Analysis/IVDescriptors.h
+313-03 files

LLVM/project 11ba1b7clang-tools-extra/docs/clang-tidy/checks/bugprone chained-comparison.md exception-escape.md

[clang-tidy][docs] Rewrite bugprone check docs to Markdown [1/4] (#214413)

Tracking issue: #201242

See the [migration guide] for more information.

[migration guide]:

https://llvm.org/docs/SphinxQuickstartTemplate.html#markdown-migration-guidelines

This rewrites part 1/4 of the remaining bugprone check documentation
from reST to MyST Markdown.

AI Usage: This was prepared with rst2myst and GPT5.6-assisted cleanup.
I manually verified that the documentation renders as expected.

Preview site:
https://broken.life/llvm-staging/bugprone-markdown-port/
DeltaFile
+180-182clang-tools-extra/docs/clang-tidy/checks/bugprone/easily-swappable-parameters.md
+165-166clang-tools-extra/docs/clang-tidy/checks/bugprone/argument-comment.md
+74-78clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.md
+72-74clang-tools-extra/docs/clang-tidy/checks/bugprone/branch-clone.md
+71-66clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.md
+47-51clang-tools-extra/docs/clang-tidy/checks/bugprone/chained-comparison.md
+609-61714 files not shown
+1,020-1,04720 files

LLVM/project ac9e7f5clang-tools-extra/docs/clang-tidy/checks/bugprone empty-catch.rst empty-catch.md

[clang-tidy][docs] Rename bugprone check docs to Markdown [1/4] (#214412)

Tracking issue: #201242

See the [migration guide] for more information.

[migration guide]:

https://llvm.org/docs/SphinxQuickstartTemplate.html#markdown-migration-guidelines

This is the mechanical rename for part 1/4 of the remaining `bugprone`
check documentation.
The rewrite is provided by the next PR in this stack.
DeltaFile
+0-276clang-tools-extra/docs/clang-tidy/checks/bugprone/easily-swappable-parameters.rst
+276-0clang-tools-extra/docs/clang-tidy/checks/bugprone/easily-swappable-parameters.md
+0-275clang-tools-extra/docs/clang-tidy/checks/bugprone/argument-comment.rst
+275-0clang-tools-extra/docs/clang-tidy/checks/bugprone/argument-comment.md
+0-149clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
+149-0clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.md
+700-70034 files not shown
+1,741-1,74140 files

LLVM/project 629919dllvm/unittests/Analysis IVDescriptorsTest.cpp

Remove deleted test (rebase error)
DeltaFile
+0-45llvm/unittests/Analysis/IVDescriptorsTest.cpp
+0-451 files

LLVM/project 492fb50llvm/unittests/Analysis IVDescriptorsTest.cpp

Restore deleted test (rebase error)
DeltaFile
+45-0llvm/unittests/Analysis/IVDescriptorsTest.cpp
+45-01 files

LLVM/project 92fa322clang/lib/StaticAnalyzer/Core SarifDiagnostics.cpp, clang/test/Analysis/diagnostics sarif-macro-expansion.c

[analyzer] Fix -analyzer-output=sarif crash on macro-expanded ranges

A path piece whose range ends inside a macro expansion aborted the whole
document: https://godbolt.org/z/61vWYcsWj

  Cannot create a physicalLocation from invalid SourceRange!

convertTokenRangeToCharRange() built the end with
Lexer::getLocForEndOfToken(), which returns an invalid location for a macro
ID that is not at the end of its expansion, and used it unchecked. The
analyzer's own test corpus hits this in nine files; text and plist output
were unaffected because both already map such ranges to the expansion.

- Use getExpansionRangeInFile(), so the region covers the macro use like the
  other two outputs.
- Fall back to a caret when the range is unusable. A thread flow needs a
  location per piece, so dropping one would truncate the reported path. This
  also stops reversed ranges producing regions with endColumn < startColumn.


    [4 lines not shown]
DeltaFile
+22-21clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
+35-0clang/test/Analysis/diagnostics/sarif-macro-expansion.c
+57-212 files

LLVM/project 7ed751cclang/lib/StaticAnalyzer/Core HTMLDiagnostics.cpp, clang/test/Analysis/html_diagnostics highlight-range-mapping.cpp

[analyzer] Fix -analyzer-output=html assert on reversed and macro ranges

HTMLDiagnostics::HighlightRange guarded against a reversed range by
comparing line numbers, so a same-line reversal - which is what the piece for
an implicit copy constructor carries - reached html::HighlightRange.
Its scan walks from begin to end, ran off the end of the buffer, and asserted:
https://godbolt.org/z/sTb5qfjjd

  Invalid position to insert! (RewriteRope.h)

It also added the end token's length itself and then passed a token range to
html::HighlightRange, which measured the token again, this time from the
interior. For most tokens the two cancel, but where the tail re-lexes longer
the highlight reached past the end of the range, e.g. over a trailing ';'.

Use getExpansionRangeInFile(), which rejects reversed and cross-file ranges,
then convert once and tell html::HighlightRange the range is already
char-granular.


    [4 lines not shown]
DeltaFile
+43-0clang/test/Analysis/html_diagnostics/highlight-range-mapping.cpp
+8-27clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
+51-272 files

LLVM/project b7cf426clang/include/clang/Frontend DiagnosticRenderer.h, clang/lib/Frontend DiagnosticRenderer.cpp

[clang] Reject ranges getExpansionRangeInFile cannot represent

getExpansionRangeInFile was extracted verbatim and inherited two shortcomings
of the original loop, fixed here before the analyzer's SARIF and HTML consumers
depend on it:

- It mapped the end with getExpansionRange(SourceLocation), which always
  reports a token range, so a char-range input was widened by a whole token.
  Now using the getExpansionRange(CharSourceRange) overload, which keeps the flag.
- It passed reversed ranges through. Consumers walk begin->end; now returning
  nullopt for those, as Lexer::makeFileCharRange already does.

Separate from the extraction so that stays NFC, and out of the consumer fixes
because it changes the shared helper's contract rather than one output.

Both contract changes, plus the invalid- and cross-file-range guards, are
covered by a GetExpansionRangeInFile unit test in
clang/unittests/Frontend/TextDiagnosticTest.cpp.

Assisted-By: claude
DeltaFile
+89-0clang/unittests/Frontend/TextDiagnosticTest.cpp
+11-6clang/lib/Frontend/DiagnosticRenderer.cpp
+10-0clang/include/clang/Frontend/DiagnosticRenderer.h
+110-63 files

LLVM/project a9207acclang/include/clang/Frontend DiagnosticRenderer.h, clang/lib/Frontend DiagnosticRenderer.cpp TextDiagnostic.cpp

[clang][NFC] Extract getExpansionRangeInFile out of the diagnostic renderers

Prep for the following commits, which fix crashes in the analyzer's SARIF and
HTML output on ranges that end inside a macro expansion. Fixing them means
mapping such a range into the reported file - the normalization the frontend
text and SARIF renderers already do, and that the two analyzer consumers each
do differently and incorrectly.

Hoist that logic into getExpansionRangeInFile, beside the DiagnosticRenderer
base both frontend renderers derive from, so the fixes reuse one
implementation instead of adding two more copies. TextDiagnostic and
SARIFDiagnostic move onto it here with no behavior change; the analyzer
consumers follow in later commits.

getFileID() replaces SARIFDiagnostic's getDecomposedLoc(...).first - equivalent
here, and what TextDiagnostic has used since c113cbb51005.

Assisted-By: claude
DeltaFile
+7-17clang/lib/Frontend/SARIFDiagnostic.cpp
+6-11clang/lib/Frontend/TextDiagnostic.cpp
+16-0clang/lib/Frontend/DiagnosticRenderer.cpp
+7-0clang/include/clang/Frontend/DiagnosticRenderer.h
+36-284 files

LLVM/project 708dafbllvm/tools/spirv-tools CMakeLists.txt

[SPIR-V] Build vendored SPIRV-Tools in Release mode (#214159)

Default build mode in SPIRV-Tools is Debug
DeltaFile
+1-0llvm/tools/spirv-tools/CMakeLists.txt
+1-01 files

LLVM/project 7ecbf7cllvm/test/Analysis/CostModel/AArch64 masked_ldst.ll

Avoid new undef in IR
DeltaFile
+14-14llvm/test/Analysis/CostModel/AArch64/masked_ldst.ll
+14-141 files

LLVM/project f380f45llvm/lib/Target/AArch64 AArch64TargetTransformInfo.cpp, llvm/test/Analysis/CostModel/AArch64 sve-arith.ll sve-ldst.ll

[AArch64][CostModel] Consider some nxv1 operations as legal

This is allowing some operations on vscale x 1 types, namely:
 - load/store
 - masked load/store
 - arithmetic instructions like add/sub/mul

For those, there is already codegen coverage. See e.g.
 - llvm/test/CodeGen/AArch64/sve-int-arith.ll
 - llvm/test/CodeGen/AArch64/sve-load-store-legalisation.ll
 - llvm/test/CodeGen/AArch64/sve-masked-gather.ll
 - llvm/test/CodeGen/AArch64/sve-masked-scatter.ll
DeltaFile
+22-41llvm/test/Analysis/CostModel/AArch64/masked_ldst.ll
+30-20llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+4-4llvm/test/Analysis/CostModel/AArch64/sve-ldst.ll
+0-6llvm/test/Transforms/LoopVectorize/AArch64/scalable-call.ll
+3-3llvm/test/Transforms/LoopVectorize/AArch64/scalable-vectorization-cost-tuning.ll
+3-3llvm/test/Analysis/CostModel/AArch64/sve-arith.ll
+62-773 files not shown
+65-809 files

LLVM/project bc00b3allvm/lib/Target/AArch64 AArch64TargetTransformInfo.cpp, llvm/test/Analysis/CostModel/AArch64 histograms.ll

[AArch64][CostModel] Explicitly disable histograms for nxv1 types (#214470)

Currently, histograms are not disabled for vscale x 1 types, but LV will
implicitly not generate them because surrounding arithmetic instructions
are invalid for vscale x 1.

SDAG does not implement operand widening for histograms, so this patch
explicitly disables those cases.
DeltaFile
+16-0llvm/test/Analysis/CostModel/AArch64/histograms.ll
+1-1llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+17-12 files

LLVM/project a33bbb8libc/test/src/math ceilf128_test.cpp

nit
DeltaFile
+1-1libc/test/src/math/ceilf128_test.cpp
+1-11 files

LLVM/project d1ea867llvm/lib/Transforms/Vectorize LoopVectorize.cpp VPlan.h, llvm/test/Transforms/LoopVectorize compress-store-vec-epilogue.ll

Fix epilogue resume handling
DeltaFile
+98-0llvm/test/Transforms/LoopVectorize/compress-store-vec-epilogue.ll
+5-5llvm/lib/Transforms/Vectorize/VPlan.h
+2-1llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+105-63 files

LLVM/project 9fd1052llvm/lib/Target/AArch64 AArch64ISelLowering.cpp, llvm/test/CodeGen/AArch64 test_tbx.ll

[AArch64][CodeGen] Fold tbx(splat(0), table, idxs) to tbl(table, idxs) (#214268)

When the destination/background vector of a TBX instruction is a splat
of zero, the operation is equivalent to a TBL instruction. TBL
implicitly zeroes out any elements where the index is out of bounds,
matching the behavior of TBX with a zero background vector.

This patch adds a DAG combine to optimize this case, reducing
instruction latency and register pressure.

Fixes #214077
DeltaFile
+92-0llvm/test/CodeGen/AArch64/test_tbx.ll
+33-0llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+125-02 files

LLVM/project 7989842libc/include CMakeLists.txt, libc/include/llvm-libc-macros CMakeLists.txt

[libc] Add missing type/macro headers for generated public headers (#213395)
DeltaFile
+16-0libc/include/CMakeLists.txt
+2-0libc/include/llvm-libc-macros/CMakeLists.txt
+18-02 files

LLVM/project b663796llvm/lib/Transforms/Vectorize SLPVectorizer.cpp

Update for comments
DeltaFile
+1-1llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+1-11 files

LLVM/project 27f1aa4llvm/lib/Target/X86/AsmParser X86AsmParser.cpp, llvm/test/MC/X86 intel-syntax-invalid-scale.s intel-syntax-scale-register-parentheses-error.s

[X86][AsmParser] Support parentheses around scale and index register in Intel syntax (#211003)

Old patterns and why they broke
 
- Decisions matching (CurrState, PrevState) tuples (e.g. CurrState ==
IES_REGISTER && PrevState != IES_MULTIPLY)
to gate committing a register to Base/Index aren't paren-transparent:
any (...) turns CurrState into IES_RPAREN, so the tuple stops matching
and
`[reg + (reg)]`, `[reg + (reg*2)]`, `[reg + 2*(reg)]` fell through the
guards.
- Duplicated commit blocks. Recognizing whether a register is Base or
Scale was placed in four
handlers (onPlus, onMinus, onRBrac, onRParen), forcing onRParen to
replay it just to catch (reg).
- Scale was committed immediately in onInteger; a parenthesized scale
like (2) * 4 or 2 * (4)
    had nowhere to accumulate.
 

    [19 lines not shown]
DeltaFile
+122-77llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+20-0llvm/test/MC/X86/intel-syntax-scale-register-parentheses.s
+18-0llvm/test/MC/X86/intel-syntax-scale-register-parentheses-error.s
+3-1llvm/test/MC/X86/intel-syntax-invalid-scale.s
+163-784 files

LLVM/project 75f7825clang/lib/StaticAnalyzer/Core HTMLDiagnostics.cpp, clang/test/Analysis/html_diagnostics highlight-range-mapping.cpp

[analyzer] Fix -analyzer-output=html assert on reversed and macro ranges

HTMLDiagnostics::HighlightRange guarded against a reversed range by
comparing line numbers, so a same-line reversal - which is what the piece for
an implicit copy constructor carries - reached html::HighlightRange.
Its scan walks from begin to end, ran off the end of the buffer, and asserted:
https://godbolt.org/z/sTb5qfjjd

  Invalid position to insert! (RewriteRope.h)

It also added the end token's length itself and then passed a token range to
html::HighlightRange, which measured the token again, this time from the
interior. For most tokens the two cancel, but where the tail re-lexes longer
the highlight reached past the end of the range, e.g. over a trailing ';'.

Use getExpansionRangeInFile(), which rejects reversed and cross-file ranges,
then convert once and tell html::HighlightRange the range is already
char-granular.


    [4 lines not shown]
DeltaFile
+43-0clang/test/Analysis/html_diagnostics/highlight-range-mapping.cpp
+8-27clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
+51-272 files

LLVM/project 05f47felibc/src/math ceilf128.h, libc/src/math/generic ceilf128.cpp

nits
DeltaFile
+4-2libc/src/math/ceilf128.h
+1-1libc/test/src/math/smoke/ceilf128_test.cpp
+1-1libc/src/math/generic/ceilf128.cpp
+6-43 files

LLVM/project a6b0af7llvm/tools/llvm-dwarfdump Statistics.cpp, llvm/tools/llvm-exegesis/lib SchedClassResolution.cpp ResultAggregator.cpp

[NFC] Add missing <cmath> and <limits> includes across llvm, mlir, lldb, flang, and bolt (#214410)

This is basically a continuation of
https://github.com/llvm/llvm-project/pull/214349...

This change adds missing `#include <cmath>` and `#include <limits>`
headers to several files across `llvm`, `mlir`, `lldb`, `flang`, and
`bolt`.

In commit
https://github.com/llvm/llvm-project/commit/ada3786e91ca2058f3ac8255a024c12ae7d263ee,
`<random>` stopped transitively pulling in the top-level `<cmath>`
header in favor of internal granular `<__math/...>` headers.
Multiple files across the codebase were implicitly relying on transitive
`<cmath>` inclusions from headers like
`llvm/Support/RandomNumberGenerator.h` and other headers that pull in
`<random>`. I'm explicitly adding the missing dependency.

### Affected Files

    [16 lines not shown]
DeltaFile
+2-0llvm/tools/llvm-dwarfdump/Statistics.cpp
+1-0mlir/lib/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.cpp
+1-0mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
+1-0mlir/include/mlir/Dialect/Quant/Utils/UniformSupport.h
+1-0llvm/tools/llvm-exegesis/lib/SchedClassResolution.cpp
+1-0llvm/tools/llvm-exegesis/lib/ResultAggregator.cpp
+7-06 files not shown
+13-012 files

LLVM/project a6a578bllvm/test/CodeGen/AMDGPU/GlobalISel regbankcombiner-merge-readanylane.mir

[AMDGPU][GlobalISel] Pre-commit tests for readanylane merge regbank combine (NFC)

Add regbank-combiner tests covering a copy to vgpr whose source is a
merge or build_vector of G_AMDGPU_READANYLANE results and uniform
values. These currently keep the round trip through sgprs, and also
cover the cases where the merge has another user and where all merge
sources are uniform.

Co-authored-by: Cursor <cursoragent at cursor.com>
DeltaFile
+103-0llvm/test/CodeGen/AMDGPU/GlobalISel/regbankcombiner-merge-readanylane.mir
+103-01 files

LLVM/project e631919llvm/test/CodeGen/AMDGPU/GlobalISel regbankcombiner-merge-readanylane.mir

Update llvm/test/CodeGen/AMDGPU/GlobalISel/regbankcombiner-merge-readanylane.mir

Co-authored-by: Matt Arsenault <Matthew.Arsenault at amd.com>
DeltaFile
+1-1llvm/test/CodeGen/AMDGPU/GlobalISel/regbankcombiner-merge-readanylane.mir
+1-11 files

LLVM/project 67fcb4dllvm/lib/Transforms/Utils LoopUnroll.cpp

Revert "revert fix in #208874, keep test"

This reverts commit 89e43e35f9d4e4f68234767bc5d46c5736150bc6.
DeltaFile
+4-0llvm/lib/Transforms/Utils/LoopUnroll.cpp
+4-01 files

LLVM/project 9698a7bclang/lib/StaticAnalyzer/Core SarifDiagnostics.cpp, clang/test/Analysis/diagnostics sarif-macro-expansion.c

[analyzer] Fix -analyzer-output=sarif crash on macro-expanded ranges

A path piece whose range ends inside a macro expansion aborted the whole
document: https://godbolt.org/z/61vWYcsWj

  Cannot create a physicalLocation from invalid SourceRange!

convertTokenRangeToCharRange() built the end with
Lexer::getLocForEndOfToken(), which returns an invalid location for a macro
ID that is not at the end of its expansion, and used it unchecked. The
analyzer's own test corpus hits this in nine files; text and plist output
were unaffected because both already map such ranges to the expansion.

- Use getExpansionRangeInFile(), so the region covers the macro use like the
  other two outputs.
- Fall back to a caret when the range is unusable. A thread flow needs a
  location per piece, so dropping one would truncate the reported path. This
  also stops reversed ranges producing regions with endColumn < startColumn.


    [4 lines not shown]
DeltaFile
+22-21clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
+35-0clang/test/Analysis/diagnostics/sarif-macro-expansion.c
+57-212 files

LLVM/project 5522034clang/include/clang/Frontend DiagnosticRenderer.h, clang/lib/Frontend DiagnosticRenderer.cpp

[clang] Reject ranges getExpansionRangeInFile cannot represent

getExpansionRangeInFile was extracted verbatim and inherited two shortcomings
of the original loop, fixed here before the analyzer's SARIF and HTML consumers
depend on it:

- It mapped the end with getExpansionRange(SourceLocation), which always
  reports a token range, so a char-range input was widened by a whole token.
  Now using the getExpansionRange(CharSourceRange) overload, which keeps the flag.
- It passed reversed ranges through. Consumers walk begin->end; now returning
  nullopt for those, as Lexer::makeFileCharRange already does.

Separate from the extraction so that stays NFC, and out of the consumer fixes
because it changes the shared helper's contract rather than one output.

Both contract changes, plus the invalid- and cross-file-range guards, are
covered by a GetExpansionRangeInFile unit test in
clang/unittests/Frontend/TextDiagnosticTest.cpp.

Assisted-By: claude
DeltaFile
+89-0clang/unittests/Frontend/TextDiagnosticTest.cpp
+11-6clang/lib/Frontend/DiagnosticRenderer.cpp
+3-2clang/include/clang/Frontend/DiagnosticRenderer.h
+103-83 files