[all-commits] [llvm/llvm-project] 3dec46: [HLSL][RootSignature] Correct `RootSignatureParser...

Finn Plummer via All-commits all-commits at lists.llvm.org
Tue Jul 8 09:56:12 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3dec46d9bfbad045cfeb66c8a5a96d32c4dd09bb
      https://github.com/llvm/llvm-project/commit/3dec46d9bfbad045cfeb66c8a5a96d32c4dd09bb
  Author: Finn Plummer <finn.c.plum at gmail.com>
  Date:   2025-07-08 (Tue, 08 Jul 2025)

  Changed paths:
    M clang/include/clang/Lex/LexHLSLRootSignature.h
    M clang/include/clang/Parse/ParseHLSLRootSignature.h
    M clang/lib/Lex/LexHLSLRootSignature.cpp
    M clang/lib/Parse/ParseDeclCXX.cpp
    M clang/lib/Parse/ParseHLSLRootSignature.cpp
    M clang/test/SemaHLSL/RootSignature-err.hlsl
    M clang/unittests/Lex/LexHLSLRootSignatureTest.cpp
    M clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

  Log Message:
  -----------
  [HLSL][RootSignature] Correct `RootSignatureParser` to use correct `SourceLocation` in diagnostics (#147084)

The `SourceLocation` of a `RootSignatureToken` is incorrectly set to be
the "offset" into the concatenated string that denotes the
rootsignature. This causes an issue when the `StringLiteral` is a
multi-line expansion macro, since the offset will not account for the
characters between `StringLiteral` tokens.

This pr resolves this by retaining the `SourceLocation` information that
is kept in `StringLiteral` and then converting the offset in the
concatenated string into the proper `SourceLocation` using the
`StringLiteral::getLocationOfByte` interface. To do so, we will need to
adjust the `RootSignatureToken` to only hold its offset into the root
signature string. Then when the parser will use the token, it will need
to compute its actual `SourceLocation`.

See linked issue for more context.

For example:

```
#define DemoRootSignature \
 "CBV(b0)," \
 "RootConstants(num32BitConstants = 3, b0, invalid)"
  expected caret location ---------------^
  actual caret location ------------^
```

The caret points 5 characters early because the current offset did not
account for the characters:
```
'"' ' ' '\' ' ' '"'
 1   2   3   4   5
```

- Updates `RootSignatureParser` to retain `SourceLocation` information
by retaining the `StringLiteral` and passing the underlying `StringRef`
to the `Lexer`
- Updates `RootSignatureLexer` so that the constructed tokens only
reflect an offset into the `StringRef`
- Updates `RootSignatureParser` to directly construct its used `Lexer`
so that the `StringLiteral` is directly tied with the string used in the
`RootSignatureLexer`
- Updates `RootSignatureParser` to use
`StringLiteral::getLocationOfByte` to get the actual token location for
diagnostics
- Updates `ParseHLSLRootSignatureTest` to construct a phony
`AST`/`StringLiteral` for the test cases
- Adds a test to `RootSignature-err.hlsl` showing that the
`SourceLocation` is correctly set for diagnostics in a multi-line macro
expansion

Resolves: https://github.com/llvm/llvm-project/issues/146967



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list