Author: Sarah Spall Date: 2025-01-15T08:39:23-08:00 New Revision: 07a184768cb8df4b43fcf0a9c45b1aa996888160
URL: https://github.com/llvm/llvm-project/commit/07a184768cb8df4b43fcf0a9c45b1aa996888160 DIFF: https://github.com/llvm/llvm-project/commit/07a184768cb8df4b43fcf0a9c45b1aa996888160.diff LOG: [HLSL] Make bool in hlsl i32 (#122977) make a bool's memory representation i32 in hlsl add new test fix broken test Closes #122932 Added: clang/test/CodeGenHLSL/Bool.hlsl Modified: clang/lib/Basic/TargetInfo.cpp clang/test/SemaHLSL/BuiltIns/asfloat-errors.hlsl Removed: ################################################################################ diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp index 86befb1cbc74fc..c0bf4e686cf03c 100644 --- a/clang/lib/Basic/TargetInfo.cpp +++ b/clang/lib/Basic/TargetInfo.cpp @@ -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(); diff --git a/clang/test/CodeGenHLSL/Bool.hlsl b/clang/test/CodeGenHLSL/Bool.hlsl new file mode 100644 index 00000000000000..fb0f32b11241d4 --- /dev/null +++ b/clang/test/CodeGenHLSL/Bool.hlsl @@ -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; +} diff --git a/clang/test/SemaHLSL/BuiltIns/asfloat-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/asfloat-errors.hlsl index c2dd9e272e0937..f5f223943b4cdd 100644 --- a/clang/test/SemaHLSL/BuiltIns/asfloat-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/asfloat-errors.hlsl @@ -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); - // 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'}} -} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits