Skip to content

Conversation

@bob80905
Copy link
Contributor

@bob80905 bob80905 commented Dec 5, 2025

This PR updates the definition for CheckAccessFullyMapped in hlsl_intrinsics.h.
Previously, the whole uint would be cast to a bool, which means any value > 0 would be treated as true.
However, the DXC implementation actually casts just the LSB to bool and returns that. So all even values would result in false, and odd values would result in true after running CheckAccessFullyMapped on it.

This PR changes the implementation to match the DXC implementation.

@llvmbot llvmbot added clang Clang issues not falling into any other category backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics labels Dec 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Dec 5, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-x86

Author: Joshua Batista (bob80905)

Changes

This PR updates the definition for CheckAccessFullyMapped in hlsl_intrinsics.h.
Previously, the whole uint would be cast to a bool, which means any value > 0 would be treated as true.
However, the DXC implementation actually casts just the LSB to bool and returns that. So all even values would result in false, and odd values would result in true after running CheckAccessFullyMapped on it.

This PR changes the implementation to match the DXC implementation.


Full diff: https://github.com/llvm/llvm-project/pull/170949.diff

1 Files Affected:

  • (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+3-1)
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index a538be5ebd099..e8cda388b4ff4 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -667,7 +667,9 @@ smoothstep(__detail::HLSL_FIXED_VECTOR<float, N> Min,
 }
 
 inline bool CheckAccessFullyMapped(uint Status) {
-  return static_cast<bool>(Status);
+  // The bool cast should only apply to the LSB.
+  uint TruncStatus = Status % 2;
+  return static_cast<bool>(TruncStatus);
 }
 
 //===----------------------------------------------------------------------===//

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

Labels

backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants