Skip to content

Make strings intangible types - #9108

Open
Chris B (llvm-beanz) wants to merge 6 commits into
microsoft:mainfrom
llvm-beanz:cbieneman/intangible-strings
Open

Chris B (llvm-beanz) wants to merge 6 commits into
microsoft:mainfrom
llvm-beanz:cbieneman/intangible-strings

Conversation

@llvm-beanz

Copy link
Copy Markdown
Collaborator

This updates the implementation of the built-in string type to be an intangible type. Aligning on the intangible semantics allows strings to be used in contexts that were allowed in FXC and some contexts supported by SPIRV.

This change does not expose any new things users can do with strings, but it is a neccessary basis for extending string operations.

Copilot AI balanced review requested due to automatic review settings November 10, 2026 01:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical issues remain: non-literal local string initializers crash the SPIR-V backend, and casts between structs containing strings generate invalid GEP indices during code generation.

2 open issues
What changed in this PR

This PR aligns HLSL string handling with intangible-type semantics, laying groundwork for broader string support while restricting use in externally visible storage.

Changes:

  • Allows string locals, fields, and parameters, with storage-context validation.
  • Updates code generation and type annotations to preserve string values in aggregates.
  • Adds regression tests, updates diagnostic expectations, and documents the change.
File Description
tools/​clang/​test/​SemaHLSL/​subobjects-syntax.hlsl Updates diagnostics to expect const string.
tools/​clang/​test/​SemaHLSL/​subobjects-ast-dump.hlsl Updates string field type expectations.
tools/​clang/​test/​SemaHLSL/​string.hlsl Revises accepted declarations and diagnostics.
tools/​clang/​test/​SemaHLSL/​string-storage.hlsl Tests string storage restrictions and private uses.
tools/​clang/​test/​HLSLFileCheckLit/​hlsl/​intrinsics/​string-empty-aggregates.hlsl Covers traversal of deeply nested shared aggregate types.
tools/​clang/​test/​HLSLFileCheckLit/​hlsl/​intrinsics/​string-constant-initializers.hlsl Tests string initialization, aggregate copies, and parameters.
tools/​clang/​lib/​Sema/​SemaHLSL.cpp Adjusts string declaration, conversion, and storage checks.
tools/​clang/​lib/​Sema/​SemaDecl.cpp Removes the blanket string-parameter rejection.
tools/​clang/​lib/​CodeGen/​CGHLSLMS.cpp Preserves string pointers during aggregate initialization.
tools/​clang/​lib/​CodeGen/​CGDecl.cpp Handles string pointer values in parameter emission.
tools/​clang/​lib/​AST/​ASTContext.cpp Represents strings as pointers to const characters.
tools/​clang/​include/​clang/​AST/​ASTContext.h Changes string type storage to QualType.
lib/​HLSL/​HLLegalizeParameter.cpp Exempts string pointers from input-parameter write patching.
lib/​DXIL/​DxilTypeSystem.cpp Prevents string-containing structs from being marked empty.
docs/​ReleaseNotes.md Documents intangible string semantics under the upcoming release.

Review effort: Balanced

Comment thread tools/clang/lib/CodeGen/CGHLSLMS.cpp Resolved
Comment thread tools/clang/lib/Sema/SemaHLSL.cpp Resolved
@llvm-beanz
Chris B (llvm-beanz) marked this pull request as draft November 10, 2026 15:54
This updates the implementation of the built-in `string` type to be an
intangible type. Aligning on the intangible semantics allows strings to
be used in contexts that were allowed in FXC and some contexts supported
by SPIRV.

This change does not expose any new things users can do with strings,
but it is a neccessary basis for extending string operations.

../tools/clang/test/CodeGenSPIRV/type.string.initializer.hlsl
../tools/clang/test/HLSLFileCheckLit/hlsl/intrinsics/string-constant-ini
tializers.hlsl
../tools/clang/test/HLSLFileCheckLit/hlsl/intrinsics/string-empty-aggreg
ates.hlsl
../tools/clang/test/SemaHLSL/subobjects-ast-dump.hlsl
Comment thread tools/clang/lib/CodeGen/CGDecl.cpp Resolved
Comment thread tools/clang/lib/CodeGen/CGDecl.cpp Resolved
Co-authored-by: Chris B <beanz@abolishcrlf.org>
@llvm-beanz
Chris B (llvm-beanz) marked this pull request as ready for review November 10, 2026 20:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

String-parameter calls can generate invalid SPIR-V, and referencing a rejected local can trigger a fatal unregistered-declaration error instead of recovering cleanly.

2 open issues
2 resolved since last review

Review effort: Balanced

Comment thread tools/clang/lib/Sema/SemaDecl.cpp Resolved
Copilot AI balanced review requested due to automatic review settings November 10, 2026 20:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

String parameters can now produce invalid SPIR-V, while scalar-string-to-aggregate casts can generate invalid GEPs, leaving critical correctness issues unresolved.

2 open issues
1 previously missed issue

In code that hasn't changed since last review

High severity Handle string leaves when splatting into aggregates

tools/​clang/​lib/​CodeGen/​CGHLSLMS.cpp:4163

For struct StringOnly { string Text; };, casting a string variable with (StringOnly)text now reaches the single-value splat path in EmitHLSLFlatConversion. EmitHLSLSplat descends into the field's i8* and builds an invalid GEP instead of copying the string value. Handle string leaves with a direct store before pointer recursion, bypassing the numeric conversion helper, and add a scalar-string-to-aggregate cast regression test.

Review effort: Balanced

../tools/clang/test/CodeGenSPIRV/type.string.initializer.hlsl
../tools/clang/test/CodeGenSPIRV/type.string.parameter.hlsl
../tools/clang/test/HLSLFileCheckLit/hlsl/intrinsics/string-constant-ini
tializers.hlsl
Copilot AI balanced review requested due to automatic review settings November 11, 2026 18:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed to evaluate string copy-in paths that can trigger assertions and SPIR-V error recovery that can produce fatal errors.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

../tools/clang/test/CodeGenSPIRV/type.string.uninitialized.hlsl
../tools/clang/test/HLSLFileCheckLit/hlsl/intrinsics/string-constant-ini
tializers.hlsl
Copilot AI balanced review requested due to automatic review settings November 11, 2026 18:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Casting a string literal to an aggregate with a string field flattens it into characters instead of a string pointer, causing an assertion failure or a type-mismatched store in release builds.

1 open issue

Review effort: Balanced

Comment on lines +5713 to +5715
if (hlsl::IsStringType(DstQualTy)) {
DXASSERT_NOMSG(hlsl::IsStringType(SrcQualTy));
CGF.Builder.CreateStore(SrcVal, DstPtr);
../tools/clang/test/HLSLFileCheckLit/hlsl/intrinsics/string-constant-ini
tializers.hlsl
Copilot AI balanced review requested due to automatic review settings November 13, 2026 17:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because the changes can produce invalid SPIR-V for string fields and reject previously accepted forward-declared buffer element types.

1 open issue

Review effort: Balanced

Disallow strings as fields when targeting spirv
Fix up handling of typedefs

../tools/clang/include/clang/Basic/DiagnosticSemaKinds.td
../tools/clang/test/CodeGenSPIRV/type.string.field.hlsl
../tools/clang/test/HLSLFileCheckLit/hlsl/intrinsics/structured-buffer-f
orward-declaration.hlsl
Copilot AI balanced review requested due to automatic review settings November 13, 2026 19:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because arrays of forward-declared resource aliases can bypass validation, leaving forbidden string elements undiagnosed.

1 open issue

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

2 participants