Skip to content

Commit 07a1847

Browse files
authored
[HLSL] Make bool in hlsl i32 (#122977)
make a bool's memory representation i32 in hlsl add new test fix broken test Closes #122932
1 parent 2570e35 commit 07a1847

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

clang/lib/Basic/TargetInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
425425
// HLSL explicitly defines the sizes and formats of some data types, and we
426426
// need to conform to those regardless of what architecture you are targeting.
427427
if (Opts.HLSL) {
428+
BoolWidth = BoolAlign = 32;
428429
LongWidth = LongAlign = 64;
429430
if (!Opts.NativeHalfType) {
430431
HalfFormat = &llvm::APFloat::IEEEsingle();

clang/test/CodeGenHLSL/Bool.hlsl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-library -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
2+
3+
// CHECK-LABEL: define noundef i1 {{.*}}fn{{.*}}(i1 noundef %x)
4+
// CHECK: [[X:%.*]] = alloca i32, align 4
5+
// CHECK-NEXT: [[Y:%.*]] = zext i1 {{%.*}} to i32
6+
// CHECK-NEXT: store i32 [[Y]], ptr [[X]], align 4
7+
// CHECK-NEXT: [[Z:%.*]] = load i32, ptr [[X]], align 4
8+
// CHECK-NEXT: [[L:%.*]] = trunc i32 [[Z]] to i1
9+
// CHECK-NEXT: ret i1 [[L]]
10+
bool fn(bool x) {
11+
return x;
12+
}

clang/test/SemaHLSL/BuiltIns/asfloat-errors.hlsl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,3 @@ float test_float_half(half p1) {
2424
// expected-note@hlsl/hlsl_detail.h:* {{candidate template ignored: could not match 'vector<half, N>' against 'half'}}
2525
// expected-note@hlsl/hlsl_detail.h:* {{candidate template ignored: substitution failure [with U = float, T = half]: no type named 'Type'}}
2626
}
27-
28-
29-
float test_float_half(bool p1) {
30-
return asfloat(p1);
31-
// expected-error@hlsl/hlsl_intrinsics.h:* {{no matching function for call to 'bit_cast'}}
32-
// expected-note@-2 {{in instantiation of function template specialization 'hlsl::asfloat<bool>'}}
33-
// expected-note@hlsl/hlsl_detail.h:* {{candidate template ignored: could not match 'vector<bool, N>' against 'bool'}}
34-
// expected-note@hlsl/hlsl_detail.h:* {{candidate template ignored: substitution failure [with U = float, T = bool]: no type named 'Type'}}
35-
}

0 commit comments

Comments
 (0)