[RISCV][VLOPT] Add vector narrowing integer right shift instructions to isSupportedIn...
[llvm-project.git] / clang / test / CodeGen / abs-overflow.c
blobaead4e282bd6211e2df8eb873aea8b6e84cb2d70
1 // RUN: %clang_cc1 -triple x86_64 -emit-llvm %s -o - -fwrapv -fsanitize=signed-integer-overflow | FileCheck %s --check-prefix=WRAPV
2 // RUN: %clang_cc1 -triple x86_64 -emit-llvm %s -o - -ftrapv | FileCheck %s --check-prefixes=BOTH-TRAP,TRAPV
3 // RUN: %clang_cc1 -triple x86_64 -emit-llvm %s -o - -fsanitize=signed-integer-overflow | FileCheck %s --check-prefixes=BOTH-TRAP,CATCH_UB
4 // COM: TODO: Support -ftrapv-handler.
6 extern int abs(int x);
8 int absi(int x) {
9 // WRAPV: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 %0, i1 false)
10 // WRAPV-NEXT: ret i32 [[ABS]]
12 // BOTH-TRAP: [[NEG:%.*]] = call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 0, i32 [[X:%.*]])
13 // BOTH-TRAP: [[NEGV:%.*]] = extractvalue { i32, i1 } [[NEG]], 0
14 // BOTH-TRAP: [[OFL:%.*]] = extractvalue { i32, i1 } [[NEG]], 1
15 // BOTH-TRAP: [[NOFL:%.*]] = xor i1 [[OFL]], true
16 // BOTH-TRAP: br i1 [[NOFL]], label %[[CONT:.*]], label %[[TRAP:[a-zA-Z_.]*]]
17 // BOTH-TRAP: [[TRAP]]:
18 // TRAPV-NEXT: llvm.ubsantrap
19 // CATCH_UB: @__ubsan_handle_negate_overflow
20 // BOTH-TRAP-NEXT: unreachable
21 // BOTH-TRAP: [[CONT]]:
22 // BOTH-TRAP-NEXT: [[ABSCOND:%.*]] = icmp slt i32 [[X]], 0
23 // BOTH-TRAP-NEXT: select i1 [[ABSCOND]], i32 [[NEGV]], i32 [[X]]
24 return abs(x);
27 int babsi(int x) {
28 // WRAPV: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 %0, i1 false)
29 // WRAPV-NEXT: ret i32 [[ABS]]
31 // BOTH-TRAP: [[NEG:%.*]] = call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 0, i32 [[X:%.*]])
32 // BOTH-TRAP: [[NEGV:%.*]] = extractvalue { i32, i1 } [[NEG]], 0
33 // BOTH-TRAP: [[OFL:%.*]] = extractvalue { i32, i1 } [[NEG]], 1
34 // BOTH-TRAP: [[NOFL:%.*]] = xor i1 [[OFL]], true
35 // BOTH-TRAP: br i1 [[NOFL]], label %[[CONT:.*]], label %[[TRAP:[a-zA-Z_.]*]]
36 // BOTH-TRAP: [[TRAP]]:
37 // TRAPV-NEXT: llvm.ubsantrap
38 // CATCH_UB: @__ubsan_handle_negate_overflow
39 // BOTH-TRAP-NEXT: unreachable
40 // BOTH-TRAP: [[CONT]]:
41 // BOTH-TRAP-NEXT: [[ABSCOND:%.*]] = icmp slt i32 [[X]], 0
42 // BOTH-TRAP-NEXT: select i1 [[ABSCOND]], i32 [[NEGV]], i32 [[X]]
43 return __builtin_abs(x);