diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Frontend/fixed_point_add.c | 47 | ||||
-rw-r--r-- | test/Frontend/fixed_point_conversions.c | 38 | ||||
-rw-r--r-- | test/Frontend/fixed_point_errors.c | 6 |
3 files changed, 87 insertions, 4 deletions
diff --git a/test/Frontend/fixed_point_add.c b/test/Frontend/fixed_point_add.c index ff3cdb9d4e..be3d5a8f5e 100644 --- a/test/Frontend/fixed_point_add.c +++ b/test/Frontend/fixed_point_add.c @@ -1,5 +1,48 @@ -// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED -// RUN: %clang_cc1 -ffixed-point -fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED +// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED +// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED + +// Addition between different fixed point types +short _Accum sa_const = 1.0hk + 2.0hk; // CHECK-DAG: @sa_const = {{.*}}global i16 384, align 2 +_Accum a_const = 1.0hk + 2.0k; // CHECK-DAG: @a_const = {{.*}}global i32 98304, align 4 +long _Accum la_const = 1.0hk + 2.0lk; // CHECK-DAG: @la_const = {{.*}}global i64 6442450944, align 8 +short _Accum sa_const2 = 0.5hr + 2.0hk; // CHECK-DAG: @sa_const2 = {{.*}}global i16 320, align 2 +short _Accum sa_const3 = 0.5r + 2.0hk; // CHECK-DAG: @sa_const3 = {{.*}}global i16 320, align 2 +short _Accum sa_const4 = 0.5lr + 2.0hk; // CHECK-DAG: @sa_const4 = {{.*}}global i16 320, align 2 + +// Unsigned addition +unsigned short _Accum usa_const = 1.0uhk + 2.0uhk; +// CHECK-SIGNED-DAG: @usa_const = {{.*}}global i16 768, align 2 +// CHECK-UNSIGNED-DAG: @usa_const = {{.*}}global i16 384, align 2 + +// Unsigned + signed +short _Accum sa_const5 = 1.0uhk + 2.0hk; +// CHECK-DAG: @sa_const5 = {{.*}}global i16 384, align 2 + +// Addition with negative number +short _Accum sa_const6 = 0.5hr + (-2.0hk); +// CHECK-DAG: @sa_const6 = {{.*}}global i16 -192, align 2 + +// Int addition +unsigned short _Accum usa_const2 = 2 + 0.5uhk; +// CHECK-SIGNED-DAG: @usa_const2 = {{.*}}global i16 640, align 2 +// CHECK-UNSIGNED-DAG: @usa_const2 = {{.*}}global i16 320, align 2 +short _Accum sa_const7 = 2 + (-0.5hk); // CHECK-DAG: @sa_const7 = {{.*}}global i16 192, align 2 +short _Accum sa_const8 = 257 + (-2.0hk); // CHECK-DAG: @sa_const8 = {{.*}}global i16 32640, align 2 +long _Fract lf_const = -0.5lr + 1; // CHECK-DAG: @lf_const = {{.*}}global i32 1073741824, align 4 + +// Saturated addition +_Sat short _Accum sat_sa_const = (_Sat short _Accum)128.0hk + 128.0hk; +// CHECK-DAG: @sat_sa_const = {{.*}}global i16 32767, align 2 +_Sat unsigned short _Accum sat_usa_const = (_Sat unsigned short _Accum)128.0uhk + 128.0uhk; +// CHECK-SIGNED-DAG: @sat_usa_const = {{.*}}global i16 65535, align 2 +// CHECK-UNSIGNED-DAG: @sat_usa_const = {{.*}}global i16 32767, align 2 +_Sat short _Accum sat_sa_const2 = (_Sat short _Accum)128.0hk + 128; +// CHECK-DAG: @sat_sa_const2 = {{.*}}global i16 32767, align 2 +_Sat unsigned short _Accum sat_usa_const2 = (_Sat unsigned short _Accum)128.0uhk + 128; +// CHECK-SIGNED-DAG: @sat_usa_const2 = {{.*}}global i16 65535, align 2 +// CHECK-UNSIGNED-DAG: @sat_usa_const2 = {{.*}}global i16 32767, align 2 +_Sat unsigned short _Accum sat_usa_const3 = (_Sat unsigned short _Accum)0.5uhk + (-2); +// CHECK-DAG: @sat_usa_const3 = {{.*}}global i16 0, align 2 void SignedAddition() { // CHECK-LABEL: SignedAddition diff --git a/test/Frontend/fixed_point_conversions.c b/test/Frontend/fixed_point_conversions.c index 22cde0eb69..0b36d9d0ca 100644 --- a/test/Frontend/fixed_point_conversions.c +++ b/test/Frontend/fixed_point_conversions.c @@ -1,5 +1,39 @@ -// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - | FileCheck %s -check-prefix=DEFAULT -// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - -fpadding-on-unsigned-fixed-point | FileCheck %s -check-prefix=SAME +// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck %s -check-prefix=DEFAULT +// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -S -emit-llvm %s -o - -fpadding-on-unsigned-fixed-point | FileCheck %s -check-prefix=SAME + +// Between different fixed point types +short _Accum sa_const = 2.5hk; // DEFAULT-DAG: @sa_const = {{.*}}global i16 320, align 2 +_Accum a_const = 2.5hk; // DEFAULT-DAG: @a_const = {{.*}}global i32 81920, align 4 +short _Accum sa_const2 = 2.5k; // DEFAULT-DAG: @sa_const2 = {{.*}}global i16 320, align 2 + +short _Accum sa_from_f_const = 0.5r; // DEFAULT-DAG: sa_from_f_const = {{.*}}global i16 64, align 2 +_Fract f_from_sa_const = 0.5hk; // DEFAULT-DAG: f_from_sa_const = {{.*}}global i16 16384, align 2 + +unsigned short _Accum usa_const = 2.5uk; +unsigned _Accum ua_const = 2.5uhk; +// DEFAULT-DAG: @usa_const = {{.*}}global i16 640, align 2 +// DEFAULT-DAG: @ua_const = {{.*}}global i32 163840, align 4 +// SAME-DAG: @usa_const = {{.*}}global i16 320, align 2 +// SAME-DAG: @ua_const = {{.*}}global i32 81920, align 4 + +// Signedness +unsigned short _Accum usa_const2 = 2.5hk; +// DEFAULT-DAG: @usa_const2 = {{.*}}global i16 640, align 2 +// SAME-DAG: @usa_const2 = {{.*}}global i16 320, align 2 +short _Accum sa_const3 = 2.5hk; // DEFAULT-DAG: @sa_const3 = {{.*}}global i16 320, align 2 + +// Overflow (this is undefined but allowed) +short _Accum sa_const4 = 256.0k; + +// Saturation +_Sat short _Accum sat_sa_const = 2.5hk; // DEFAULT-DAG: @sat_sa_const = {{.*}}global i16 320, align 2 +_Sat short _Accum sat_sa_const2 = 256.0k; // DEFAULT-DAG: @sat_sa_const2 = {{.*}}global i16 32767, align 2 +_Sat unsigned short _Accum sat_usa_const = -1.0hk; +// DEFAULT-DAG: @sat_usa_const = {{.*}}global i16 0, align 2 +// SAME-DAG: @sat_usa_const = {{.*}}global i16 0, align 2 +_Sat unsigned short _Accum sat_usa_const2 = 256.0k; +// DEFAULT-DAG: @sat_usa_const2 = {{.*}}global i16 -1, align 2 +// SAME-DAG: @sat_usa_const2 = {{.*}}global i16 32767, align 2 void TestFixedPointCastSameType() { _Accum a = 2.5k; diff --git a/test/Frontend/fixed_point_errors.c b/test/Frontend/fixed_point_errors.c index 41427e3431..43c5057257 100644 --- a/test/Frontend/fixed_point_errors.c +++ b/test/Frontend/fixed_point_errors.c @@ -232,3 +232,9 @@ void CheckSuffixOnIntegerLiterals() { auto auto_accum = 0k; // expected-error{{invalid suffix 'k' on integer constant}} // expected-warning@-1{{type specifier missing, defaults to 'int'}} } + +// Overflow +short _Accum sa_const = 256.0k; // expected-warning{{implicit conversion from 256.0 cannot fit within the range of values for 'short _Accum'}} +short _Fract sf_const = 1.0hk; // expected-warning{{implicit conversion from 1.0 cannot fit within the range of values for 'short _Fract'}} +unsigned _Accum ua_const = -1.0k; // expected-warning{{implicit conversion from -1.0 cannot fit within the range of values for 'unsigned _Accum'}} +short _Accum sa_const2 = 128.0k + 128.0k; // expected-warning{{implicit conversion from 256.0 cannot fit within the range of values for 'short _Accum'}} |