1 // RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -emit-llvm -o - %s -fsanitize=signed-integer-overflow,unsigned-integer-overflow | FileCheck %s
3 typedef unsigned char uchar
;
4 typedef unsigned short ushort
;
5 typedef int int4
__attribute__((ext_vector_type(4)));
15 // CHECK-LABEL: define{{.*}} signext i8 @_Z4add1
16 // CHECK-NOT: sadd.with.overflow
17 char add1(char c
) { return c
+ c
; }
19 // CHECK-LABEL: define{{.*}} zeroext i8 @_Z4add2
20 // CHECK-NOT: uadd.with.overflow
21 uchar
add2(uchar uc
) { return uc
+ uc
; }
23 // CHECK-LABEL: define{{.*}} i32 @_Z4add3
24 // CHECK: sadd.with.overflow
25 int add3(E1 e
) { return e
+ a
; }
27 // CHECK-LABEL: define{{.*}} signext i8 @_Z4add4
28 // CHECK-NOT: sadd.with.overflow
29 char add4(E2 e
) { return e
+ b
; }
31 // CHECK-LABEL: define{{.*}} signext i8 @_Z4sub1
32 // CHECK-NOT: ssub.with.overflow
33 char sub1(char c
) { return c
- c
; }
35 // CHECK-LABEL: define{{.*}} zeroext i8 @_Z4sub2
36 // CHECK-NOT: usub.with.overflow
37 uchar
sub2(uchar uc
) { return uc
- uc
; }
39 // CHECK-LABEL: define{{.*}} signext i8 @_Z4sub3
40 // CHECK-NOT: ssub.with.overflow
41 char sub3(char c
) { return -c
; }
43 // Note: -INT_MIN can overflow.
45 // CHECK-LABEL: define{{.*}} i32 @_Z4sub4
46 // CHECK: ssub.with.overflow
47 int sub4(int i
) { return -i
; }
49 // CHECK-LABEL: define{{.*}} signext i8 @_Z4mul1
50 // CHECK-NOT: smul.with.overflow
51 char mul1(char c
) { return c
* c
; }
53 // CHECK-LABEL: define{{.*}} zeroext i8 @_Z4mul2
54 // CHECK-NOT: smul.with.overflow
55 uchar
mul2(uchar uc
) { return uc
* uc
; }
57 // Note: USHRT_MAX * USHRT_MAX can overflow.
59 // CHECK-LABEL: define{{.*}} zeroext i16 @_Z4mul3
60 // CHECK: smul.with.overflow
61 ushort
mul3(ushort us
) { return us
* us
; }
63 // CHECK-LABEL: define{{.*}} i32 @_Z4mul4
64 // CHECK: smul.with.overflow
65 int mul4(int i
, char c
) { return i
* c
; }
67 // CHECK-LABEL: define{{.*}} i32 @_Z4mul5
68 // CHECK: smul.with.overflow
69 int mul5(int i
, char c
) { return c
* i
; }
71 // CHECK-LABEL: define{{.*}} signext i16 @_Z4mul6
72 // CHECK-NOT: smul.with.overflow
73 short mul6(short s
) { return s
* s
; }
75 // CHECK-LABEL: define{{.*}} signext i8 @_Z4div1
76 // CHECK-NOT: ubsan_handle_divrem_overflow
77 char div1(char c
) { return c
/ c
; }
79 // CHECK-LABEL: define{{.*}} zeroext i8 @_Z4div2
80 // CHECK-NOT: ubsan_handle_divrem_overflow
81 uchar
div2(uchar uc
) { return uc
/ uc
; }
83 // CHECK-LABEL: define{{.*}} signext i8 @_Z4div3
84 // CHECK-NOT: ubsan_handle_divrem_overflow
85 char div3(char c
, int i
) { return c
/ i
; }
87 // CHECK-LABEL: define{{.*}} signext i8 @_Z4div4
88 // CHECK: ubsan_handle_divrem_overflow
89 char div4(int i
, char c
) { return i
/ c
; }
91 // Note: INT_MIN / -1 can overflow.
93 // CHECK-LABEL: define{{.*}} signext i8 @_Z4div5
94 // CHECK: ubsan_handle_divrem_overflow
95 char div5(int i
, char c
) { return i
/ c
; }
97 // CHECK-LABEL: define{{.*}} signext i8 @_Z4rem1
98 // CHECK-NOT: ubsan_handle_divrem_overflow
99 char rem1(char c
) { return c
% c
; }
101 // CHECK-LABEL: define{{.*}} zeroext i8 @_Z4rem2
102 // CHECK-NOT: ubsan_handle_divrem_overflow
103 uchar
rem2(uchar uc
) { return uc
% uc
; }
105 // CHECK-LABEL: define{{.*}} signext i8 @_Z4rem3
106 // CHECK: ubsan_handle_divrem_overflow
107 char rem3(int i
, char c
) { return i
% c
; }
109 // CHECK-LABEL: define{{.*}} signext i8 @_Z4rem4
110 // CHECK-NOT: ubsan_handle_divrem_overflow
111 char rem4(char c
, int i
) { return c
% i
; }
113 // CHECK-LABEL: define{{.*}} signext i8 @_Z4inc1
114 // CHECK-NOT: sadd.with.overflow
115 char inc1(char c
) { return c
++ + (char)0; }
117 // CHECK-LABEL: define{{.*}} zeroext i8 @_Z4inc2
118 // CHECK-NOT: uadd.with.overflow
119 uchar
inc2(uchar uc
) { return uc
++ + (uchar
)0; }
121 // CHECK-LABEL: define{{.*}} void @_Z4inc3
122 // CHECK-NOT: sadd.with.overflow
123 void inc3(char c
) { c
++; }
125 // CHECK-LABEL: define{{.*}} void @_Z4inc4
126 // CHECK-NOT: uadd.with.overflow
127 void inc4(uchar uc
) { uc
++; }
129 // CHECK-LABEL: define{{.*}} <4 x i32> @_Z4vremDv4_iS_
130 // CHECK-NOT: ubsan_handle_divrem_overflow
131 int4
vrem(int4 a
, int4 b
) { return a
% b
; }