Skip to content

Emit error for user-defined conversion operators in HLSL#6

Draft
Copilot wants to merge 17 commits intomainfrom
copilot/fix-issue-5103-tests
Draft

Emit error for user-defined conversion operators in HLSL#6
Copilot wants to merge 17 commits intomainfrom
copilot/fix-issue-5103-tests

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 21, 2026

  • Understand the issue: user-defined conversion operators (e.g., operator float4()) are silently ignored in HLSL instead of producing an error
  • Add a new diagnostic err_hlsl_unsupported_conversion_operator in DiagnosticSemaKinds.td
  • Add HLSL check in CheckConversionDeclarator in SemaDeclCXX.cpp to emit error when a conversion operator is defined
  • Create test file tools/clang/test/SemaHLSL/conversion-operator-errors.hlsl following existing patterns
  • Build and verify the fix works (all new + existing operator tests pass)
  • Update diagnostic message to "conversion operator overloading is not allowed" for consistency with err_hlsl_overloading_operator_disallowed
  • Add release note entry in docs/ReleaseNotes.md
  • Add template-dependent conversion operator test case

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…soft#5103)

Add err_hlsl_unsupported_conversion_operator diagnostic and check in
CheckConversionDeclarator to reject conversion operators in HLSL.
Previously these were silently ignored, misleading users into thinking
their cast operator overloads were being used.

Co-authored-by: damyanp <8118402+damyanp@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue 5103 and add tests for validation Emit error for user-defined conversion operators in HLSL Feb 21, 2026
Copilot AI requested a review from damyanp February 21, 2026 00:58
Comment thread tools/clang/include/clang/Basic/DiagnosticSemaKinds.td Outdated
…oad is not allowed'

Co-authored-by: damyanp <8118402+damyanp@users.noreply.github.com>
Co-authored-by: damyanp <8118402+damyanp@users.noreply.github.com>
@damyanp
Copy link
Copy Markdown
Owner

damyanp commented Feb 23, 2026

@copilot add a short one-line description of this change to ReleaseNotes.md

Co-authored-by: damyanp <8118402+damyanp@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Feb 23, 2026

@copilot add a short one-line description of this change to ReleaseNotes.md

Added in ca5ca4f7 under the "Other Changes" section of the Upcoming Release.

Copilot AI requested a review from damyanp February 23, 2026 18:01
damyanp pushed a commit that referenced this pull request Mar 9, 2026
… for `vk::SampledTexture2D` type. (microsoft#8149)

Part of microsoft#7979

```hlsl
TemplateType GatherRed(float2 Location, int2 Offset1, int2 Offset2, int2 Offset3, int2 Offset4, uint Status);
TemplateType GatherGreen(float2 Location, int2 Offset1, int2 Offset2, int2 Offset3, int2 Offset4, uint Status);
TemplateType GatherBlue(float2 Location, int2 Offset1, int2 Offset2, int2 Offset3, int2 Offset4, uint Status);
TemplateType GatherAlpha(float2 Location, int2 Offset1, int2 Offset2, int2 Offset3, int2 Offset4, uint Status);
TemplateType GatherCmp(float Location, float CompareValue, int2 Offset, uint Status);
TemplateType GatherCmpRed(float Location, float CompareValue, int2 Offset1, int2 Offset2, int2 Offset3, int2 Offset4, uint Status);
```
GatherCmpGreen, GatherCmpBlue, GatherCmpAlpha, GatherRaw are not
supported.
// This test verifies that dxcompiler generates an error when defining
// a conversion operator (cast operator), which is not supported in HLSL.

struct MyStruct {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Should there be a test for the template-dependent case?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added a template-dependent test case (template<typename T> struct TemplateStruct { operator T() { ... } }) in 2fcaf368. The error is caught at parse time in CheckConversionDeclarator, so it fires even without template instantiation.

Co-authored-by: damyanp <8118402+damyanp@users.noreply.github.com>
Copilot AI requested a review from damyanp March 11, 2026 01:19
Keenuts and others added 10 commits March 26, 2026 09:36
This commit fixes 2 warnings showing on when building on MacOS:
 - CMP0135: setting which policy is applied on download freshness check
 - METAL_IRCONVERTER case not matching the FindPackage filename.
)

Update `DxilStructAnnotation` to be aware of target types. Otherwise the annotation would declare a struct with a single LinAlg Matrix type as empty, leading to invalid codegen.

Declaration names match the style of the surrounding code. 

Fixes microsoft#8279
Addresses outstanding cleanup requests from the initial LinAlg exec test
PR

---------

Co-authored-by: Damyan Pepper <damyanp@microsoft.com>
Updates the SPIR-V dependencies, and update an invalid test.
The experimental Cooperative Vector feature has been superseded by
LinAlg. This change removes the code supporting the old feature.

Fixes microsoft#8147

---------

Co-authored-by: Helena Kotas <hekotas@microsoft.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: damyanp <8118402+damyanp@users.noreply.github.com>
DxilCounters.cpp wasn't getting updated when HLSL_COPY_GENERATED_SOURCES
was set. This change fixes that, and includes the updated
DxilCounters.cpp.

add_hlsl_hctgen now adds the file extension to the target it creates,
which allows us to generate both DxilCounters.h and DxilCounters.cpp.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: damyanp <8118402+damyanp@users.noreply.github.com>
Previous docs were....misleading at best. This change makes them more
accurate.
…oft#8174) (microsoft#8177)

PR microsoft#7799 added debug info for global variables across all inlined
subprograms, creating O(subprograms x globals) debug instructions. This
caused 2-3x slower compilation for shaders with many globals and
deeply-inlined functions.

Fix: Instead of collecting ALL subprograms for a function (walking every
instruction), only collect subprograms from the alloca's actual users --
the instructions that reference the specific global variable. This
preserves the debug info feature (globals visible in inlined scopes that
use them) while eliminating work for unrelated scopes.

The 'Lower static global into Alloca' pass is 3.8x faster on a stress
test (41ms -> 11ms), and overall debug compilation is ~10% faster.

Fixes microsoft#8174

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…103-tests

# Conflicts:
#	docs/ReleaseNotes.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants