2017-02-25 08:43:36 +08:00
|
|
|
// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -emit-llvm -o - %s -fsanitize=signed-integer-overflow,unsigned-integer-overflow | FileCheck %s
|
|
|
|
|
|
|
|
typedef unsigned char uchar;
|
|
|
|
typedef unsigned short ushort;
|
2017-02-25 08:43:39 +08:00
|
|
|
typedef int int4 __attribute__((ext_vector_type(4)));
|
2017-02-25 08:43:36 +08:00
|
|
|
|
|
|
|
enum E1 : int {
|
|
|
|
a
|
|
|
|
};
|
|
|
|
|
|
|
|
enum E2 : char {
|
|
|
|
b
|
|
|
|
};
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} signext i8 @_Z4add1
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK-NOT: sadd.with.overflow
|
|
|
|
char add1(char c) { return c + c; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} zeroext i8 @_Z4add2
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK-NOT: uadd.with.overflow
|
|
|
|
uchar add2(uchar uc) { return uc + uc; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} i32 @_Z4add3
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK: sadd.with.overflow
|
|
|
|
int add3(E1 e) { return e + a; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} signext i8 @_Z4add4
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK-NOT: sadd.with.overflow
|
|
|
|
char add4(E2 e) { return e + b; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} signext i8 @_Z4sub1
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK-NOT: ssub.with.overflow
|
|
|
|
char sub1(char c) { return c - c; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} zeroext i8 @_Z4sub2
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK-NOT: usub.with.overflow
|
|
|
|
uchar sub2(uchar uc) { return uc - uc; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} signext i8 @_Z4sub3
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK-NOT: ssub.with.overflow
|
|
|
|
char sub3(char c) { return -c; }
|
|
|
|
|
|
|
|
// Note: -INT_MIN can overflow.
|
|
|
|
//
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} i32 @_Z4sub4
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK: ssub.with.overflow
|
|
|
|
int sub4(int i) { return -i; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} signext i8 @_Z4mul1
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK-NOT: smul.with.overflow
|
|
|
|
char mul1(char c) { return c * c; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} zeroext i8 @_Z4mul2
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK-NOT: smul.with.overflow
|
|
|
|
uchar mul2(uchar uc) { return uc * uc; }
|
|
|
|
|
|
|
|
// Note: USHRT_MAX * USHRT_MAX can overflow.
|
|
|
|
//
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} zeroext i16 @_Z4mul3
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK: smul.with.overflow
|
|
|
|
ushort mul3(ushort us) { return us * us; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} i32 @_Z4mul4
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK: smul.with.overflow
|
|
|
|
int mul4(int i, char c) { return i * c; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} i32 @_Z4mul5
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK: smul.with.overflow
|
|
|
|
int mul5(int i, char c) { return c * i; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} signext i16 @_Z4mul6
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK-NOT: smul.with.overflow
|
|
|
|
short mul6(short s) { return s * s; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} signext i8 @_Z4div1
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK-NOT: ubsan_handle_divrem_overflow
|
|
|
|
char div1(char c) { return c / c; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} zeroext i8 @_Z4div2
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK-NOT: ubsan_handle_divrem_overflow
|
|
|
|
uchar div2(uchar uc) { return uc / uc; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} signext i8 @_Z4div3
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK-NOT: ubsan_handle_divrem_overflow
|
|
|
|
char div3(char c, int i) { return c / i; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} signext i8 @_Z4div4
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK: ubsan_handle_divrem_overflow
|
|
|
|
char div4(int i, char c) { return i / c; }
|
|
|
|
|
|
|
|
// Note: INT_MIN / -1 can overflow.
|
|
|
|
//
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} signext i8 @_Z4div5
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK: ubsan_handle_divrem_overflow
|
|
|
|
char div5(int i, char c) { return i / c; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} signext i8 @_Z4rem1
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK-NOT: ubsan_handle_divrem_overflow
|
|
|
|
char rem1(char c) { return c % c; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} zeroext i8 @_Z4rem2
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK-NOT: ubsan_handle_divrem_overflow
|
|
|
|
uchar rem2(uchar uc) { return uc % uc; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} signext i8 @_Z4rem3
|
2017-02-25 08:43:39 +08:00
|
|
|
// CHECK: ubsan_handle_divrem_overflow
|
2017-02-25 08:43:36 +08:00
|
|
|
char rem3(int i, char c) { return i % c; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} signext i8 @_Z4rem4
|
2017-02-25 08:43:39 +08:00
|
|
|
// CHECK-NOT: ubsan_handle_divrem_overflow
|
|
|
|
char rem4(char c, int i) { return c % i; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} signext i8 @_Z4inc1
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK-NOT: sadd.with.overflow
|
|
|
|
char inc1(char c) { return c++ + (char)0; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} zeroext i8 @_Z4inc2
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK-NOT: uadd.with.overflow
|
|
|
|
uchar inc2(uchar uc) { return uc++ + (uchar)0; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_Z4inc3
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK-NOT: sadd.with.overflow
|
|
|
|
void inc3(char c) { c++; }
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_Z4inc4
|
2017-02-25 08:43:36 +08:00
|
|
|
// CHECK-NOT: uadd.with.overflow
|
|
|
|
void inc4(uchar uc) { uc++; }
|
2017-02-25 08:43:39 +08:00
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} <4 x i32> @_Z4vremDv4_iS_
|
2017-02-25 08:43:39 +08:00
|
|
|
// CHECK-NOT: ubsan_handle_divrem_overflow
|
|
|
|
int4 vrem(int4 a, int4 b) { return a % b; }
|