Skip to content

Remove hlsl namespace from SemaHLSL #7656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

llvm-beanz
Copy link
Collaborator

HLSL intrinsics were previously being added to the translation unit decl but assigned a namespace decl context which was then used only in codegen to determine if special handling was needed for the namespace. This causes an odd array of behaviors including strange mangling and confusing diagnostics.

This PR removes the HLSL namespace and properly adds intrinsics to namespaces when appropriate for the vk and dx namespaces. This should allow qualified and unqualified name lookup to behave as expected, correct odd mangling, and improve the confusing diagnostics.

The PR introduces a new HLSLBuiltinCallAttr to replace the use of the hlsl namespace. This attribute denotes when a function declaration should be emitted in codegen as an HLSL builtin. It is subtly different from HLSLIntrinsicAttr which is attached to all intrinsic functions and allows the AST to track the HL OpCode.

HLSL intrinsics were previously being added to the translation unit decl
but assigned a namespace decl context which was then used only in
codegen to determine if special handling was needed for the namespace.
This causes an odd array of behaviors including strange mangling and
confusing diagnostics.

This PR removes the HLSL namespace and properly adds intrinsics to
namespaces when appropriate for the `vk` and `dx` namespaces. This
should allow qualified and unqualified name lookup to behave as
expected, correct odd mangling, and improve the confusing diagnostics.

The PR introduces a new HLSLBuiltinCallAttr to replace the use of the
hlsl namespace. This attribute denotes when a function declaration
should be emitted in codegen as an HLSL builtin. It is subtly different
from HLSLIntrinsicAttr which is attached to all intrinsic functions and
allows the AST to track the HL OpCode.

../tools/clang/test/HLSLFileCheck/hlsl/intrinsics/atomic/atomic.hlsl
../tools/clang/test/HLSLFileCheck/hlsl/intrinsics/atomic/atomic_float.hl
sl
../tools/clang/test/SemaHLSL/hlsl/linalg/unavailable-pre-sm69.hlsl
../tools/clang/test/SemaHLSL/using-namespace-dx-errors.hlsl
Co-authored-by: Ashley Coleman <ascoleman@microsoft.com>
Copy link
Member

@hekota hekota left a comment

Choose a reason for hiding this comment

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

LGTM!

@llvm-beanz llvm-beanz merged commit bd18344 into microsoft:main Jul 29, 2025
12 checks passed
@llvm-beanz llvm-beanz deleted the cbieneman/remove-hlsl-namespace-final branch July 29, 2025 17:47
@github-project-automation github-project-automation bot moved this from New to Done in HLSL Roadmap Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants