xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/compound-assign-overflow.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // Verify proper type emitted for compound assignments
2*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -ffreestanding -triple x86_64-apple-darwin10 -emit-llvm -o - %s  -fsanitize=signed-integer-overflow,unsigned-integer-overflow | FileCheck %s
3*f4a2713aSLionel Sambuc 
4*f4a2713aSLionel Sambuc #include <stdint.h>
5*f4a2713aSLionel Sambuc 
6*f4a2713aSLionel Sambuc // CHECK: @[[INT:.*]] = private unnamed_addr constant { i16, i16, [6 x i8] } { i16 0, i16 11, [6 x i8] c"'int'\00" }
7*f4a2713aSLionel Sambuc // CHECK: @[[LINE_100:.*]] = private unnamed_addr global {{.*}}, i32 100, i32 5 {{.*}} @[[INT]]
8*f4a2713aSLionel Sambuc // CHECK: @[[UINT:.*]] = private unnamed_addr constant { i16, i16, [15 x i8] } { i16 0, i16 10, [15 x i8] c"'unsigned int'\00" }
9*f4a2713aSLionel Sambuc // CHECK: @[[LINE_200:.*]] = private unnamed_addr global {{.*}}, i32 200, i32 5 {{.*}} @[[UINT]]
10*f4a2713aSLionel Sambuc // CHECK: @[[LINE_300:.*]] = private unnamed_addr global {{.*}}, i32 300, i32 5 {{.*}} @[[INT]]
11*f4a2713aSLionel Sambuc 
12*f4a2713aSLionel Sambuc int32_t x;
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc // CHECK: @compaddsigned
15*f4a2713aSLionel Sambuc void compaddsigned() {
16*f4a2713aSLionel Sambuc #line 100
17*f4a2713aSLionel Sambuc   x += ((int32_t)1);
18*f4a2713aSLionel Sambuc   // CHECK: @__ubsan_handle_add_overflow(i8* bitcast ({{.*}} @[[LINE_100]] to i8*), {{.*}})
19*f4a2713aSLionel Sambuc }
20*f4a2713aSLionel Sambuc 
21*f4a2713aSLionel Sambuc // CHECK: @compaddunsigned
22*f4a2713aSLionel Sambuc void compaddunsigned() {
23*f4a2713aSLionel Sambuc #line 200
24*f4a2713aSLionel Sambuc   x += ((uint32_t)1U);
25*f4a2713aSLionel Sambuc   // CHECK: @__ubsan_handle_add_overflow(i8* bitcast ({{.*}} @[[LINE_200]] to i8*), {{.*}})
26*f4a2713aSLionel Sambuc }
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc int8_t a, b;
29*f4a2713aSLionel Sambuc 
30*f4a2713aSLionel Sambuc // CHECK: @compdiv
31*f4a2713aSLionel Sambuc void compdiv() {
32*f4a2713aSLionel Sambuc #line 300
33*f4a2713aSLionel Sambuc   a /= b;
34*f4a2713aSLionel Sambuc   // CHECK: @__ubsan_handle_divrem_overflow(i8* bitcast ({{.*}} @[[LINE_300]] to i8*), {{.*}})
35*f4a2713aSLionel Sambuc }
36