• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Check -fsanitize=signed-integer-overflow and
2 // -fsanitize=unsigned-integer-overflow with promoted unsigned types
3 //
4 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s \
5 // RUN:   -fsanitize=signed-integer-overflow | FileCheck %s --check-prefix=CHECKS
6 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s \
7 // RUN:   -fsanitize=unsigned-integer-overflow | FileCheck %s --check-prefix=CHECKU
8 
9 unsigned short si, sj, sk;
10 
11 // CHECKS-LABEL:   define void @testshortmul()
12 // CHECKU-LABEL: define void @testshortmul()
testshortmul()13 void testshortmul() {
14 
15   // CHECKS:        load i16, i16* @sj
16   // CHECKS:        load i16, i16* @sk
17   // CHECKS:        [[T1:%.*]] = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 [[T2:%.*]], i32 [[T3:%.*]])
18   // CHECKS-NEXT:   [[T4:%.*]] = extractvalue { i32, i1 } [[T1]], 0
19   // CHECKS-NEXT:   [[T5:%.*]] = extractvalue { i32, i1 } [[T1]], 1
20   // CHECKS:        call void @__ubsan_handle_mul_overflow
21   //
22   // CHECKU:      [[T1:%.*]] = load i16, i16* @sj
23   // CHECKU:      [[T2:%.*]] = zext i16 [[T1]]
24   // CHECKU:      [[T3:%.*]] = load i16, i16* @sk
25   // CHECKU:      [[T4:%.*]] = zext i16 [[T3]]
26   // CHECKU-NOT:  llvm.smul
27   // CHECKU-NOT:  llvm.umul
28   // CHECKU:      [[T5:%.*]] = mul nsw i32 [[T2]], [[T4]]
29   si = sj * sk;
30 }
31