diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -837,7 +837,9 @@ E = ImpCastExprToType(E, PTy, CK_IntegralCast).get(); return E; } - if (Ty->isPromotableIntegerType()) { + if (Ty->isPromotableIntegerType() && + // Avoid promote integer type to int. + !getLangOpts().HLSL) { QualType PT = Context.getPromotedIntegerType(Ty); E = ImpCastExprToType(E, PT, CK_IntegralCast).get(); return E; diff --git a/clang/test/CodeGenHLSL/basic_types.hlsl b/clang/test/CodeGenHLSL/basic_types.hlsl --- a/clang/test/CodeGenHLSL/basic_types.hlsl +++ b/clang/test/CodeGenHLSL/basic_types.hlsl @@ -4,7 +4,7 @@ // CHECK:"?uint16_t_Val@@3GA" = global i16 0, align 2 -// CHECK:"?int16_t_Val@@3FA" = global i16 0, align 2 +// CHECK:"?int16_t_Val@@3FA" = global i16 0 // CHECK:"?uint_Val@@3IA" = global i32 0, align 4 // CHECK:"?uint64_t_Val@@3KA" = global i64 0, align 8 // CHECK:"?int64_t_Val@@3JA" = global i64 0, align 8 diff --git a/clang/test/CodeGenHLSL/builtins/abs.hlsl b/clang/test/CodeGenHLSL/builtins/abs.hlsl --- a/clang/test/CodeGenHLSL/builtins/abs.hlsl +++ b/clang/test/CodeGenHLSL/builtins/abs.hlsl @@ -7,8 +7,7 @@ // CHECK: define noundef signext i16 @ -// FIXME: int16_t is promoted to i32 now. Change to abs.i16 once it is fixed. -// CHECK: call i32 @llvm.abs.i32( +// CHECK: call i16 @llvm.abs.i16( int16_t test_abs_int16_t ( int16_t p0 ) { return abs ( p0 ); } diff --git a/clang/test/CodeGenHLSL/int16_t_add.hlsl b/clang/test/CodeGenHLSL/int16_t_add.hlsl new file mode 100644 --- /dev/null +++ b/clang/test/CodeGenHLSL/int16_t_add.hlsl @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ +// RUN: dxil-pc-shadermodel6.3-library %s -D__HLSL_ENABLE_16_BIT \ +// RUN: -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s + +// Make sure generate i16 add. +// CHECK: add nsw i16 % +int16_t add(int16_t a, int16_t b) { + return a + b; +} +// CHECK: define noundef <2 x i16> @ +// CHECK: add <2 x i16> +int16_t2 add(int16_t2 a, int16_t2 b) { + return a + b; +} +// CHECK: define noundef <3 x i16> @ +// CHECK: add <3 x i16> +int16_t3 add(int16_t3 a, int16_t3 b) { + return a + b; +} +// CHECK: define noundef <4 x i16> @ +// CHECK: add <4 x i16> +int16_t4 add(int16_t4 a, int16_t4 b) { + return a + b; +} diff --git a/clang/test/SemaHLSL/BitInt128.hlsl b/clang/test/SemaHLSL/BitInt128.hlsl new file mode 100644 --- /dev/null +++ b/clang/test/SemaHLSL/BitInt128.hlsl @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -ast-dump -o - %s -verify + +// expected-error@+1 {{_BitInt is not supported on this target}} +_BitInt(128) i128; + +// expected-error@+1 {{_BitInt is not supported on this target}} +unsigned _BitInt(128) u128;