Skip to content

[HLSL] Make bool in hlsl i32 #122977

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
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/lib/Basic/TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
// HLSL explicitly defines the sizes and formats of some data types, and we
// need to conform to those regardless of what architecture you are targeting.
if (Opts.HLSL) {
BoolWidth = BoolAlign = 32;
LongWidth = LongAlign = 64;
if (!Opts.NativeHalfType) {
HalfFormat = &llvm::APFloat::IEEEsingle();
Expand Down
12 changes: 12 additions & 0 deletions clang/test/CodeGenHLSL/Bool.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-library -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s

// CHECK-LABEL: define noundef i1 {{.*}}fn{{.*}}(i1 noundef %x)
// CHECK: [[X:%.*]] = alloca i32, align 4
// CHECK-NEXT: [[Y:%.*]] = zext i1 {{%.*}} to i32
// CHECK-NEXT: store i32 [[Y]], ptr [[X]], align 4
// CHECK-NEXT: [[Z:%.*]] = load i32, ptr [[X]], align 4
// CHECK-NEXT: [[L:%.*]] = trunc i32 [[Z]] to i1
// CHECK-NEXT: ret i1 [[L]]
bool fn(bool x) {
return x;
}
9 changes: 0 additions & 9 deletions clang/test/SemaHLSL/BuiltIns/asfloat-errors.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,3 @@ float test_float_half(half p1) {
// expected-note@hlsl/hlsl_detail.h:* {{candidate template ignored: could not match 'vector<half, N>' against 'half'}}
// expected-note@hlsl/hlsl_detail.h:* {{candidate template ignored: substitution failure [with U = float, T = half]: no type named 'Type'}}
}


float test_float_half(bool p1) {
return asfloat(p1);
Copy link
Contributor

@bob80905 bob80905 Jan 14, 2025

Choose a reason for hiding this comment

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

Presumably, now that p1 is 32 bits, it can be cast to an int for asfloat, so this doesn't emit any errors, right?

Copy link
Contributor Author

@spall spall Jan 14, 2025

Choose a reason for hiding this comment

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

Yeah no errors were being emitted, causing the old test to fail (due to lack of errors).

// expected-error@hlsl/hlsl_intrinsics.h:* {{no matching function for call to 'bit_cast'}}
// expected-note@-2 {{in instantiation of function template specialization 'hlsl::asfloat<bool>'}}
// expected-note@hlsl/hlsl_detail.h:* {{candidate template ignored: could not match 'vector<bool, N>' against 'bool'}}
// expected-note@hlsl/hlsl_detail.h:* {{candidate template ignored: substitution failure [with U = float, T = bool]: no type named 'Type'}}
}
Loading