1 // RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -fsanitize=unsigned-integer-overflow | FileCheck %s --check-prefix=UNSIGNED
2 // RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -ftrapv | FileCheck %s --check-prefix=TRAPV
3 // RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -fsanitize=unsigned-integer-overflow -ftrapv | FileCheck %s --check-prefix=BOTH
4 // Verify that -ftrapv and -fsanitize=unsigned-integer-overflow
5 // work together as expected
8 // UNSIGNED: @test_signed
11 void test_signed(void) {
12 extern volatile int a
, b
, c
;
13 // UNSIGNED: add nsw i32
14 // UNSIGNED-NOT: overflow
15 // TRAPV: sadd.with.overflow.i32
16 // TRAPV-NOT: @__ubsan
17 // TRAPV: llvm.ubsantrap
18 // BOTH: sadd.with.overflow.i32
20 // BOTH: llvm.ubsantrap
24 // UNSIGNED: @test_unsigned
25 // TRAPV: @test_unsigned
26 // BOTH: @test_unsigned
27 void test_unsigned(void) {
28 extern volatile unsigned x
, y
, z
;
29 // UNSIGNED: uadd.with.overflow.i32
30 // UNSIGNED-NOT: llvm.trap
32 // TRAPV-NOT: overflow
33 // TRAPV-NOT: llvm.trap
34 // BOTH: uadd.with.overflow.i32
36 // BOTH-NOT: llvm.ubsantrap