xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/unsigned-trapv.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -fsanitize=unsigned-integer-overflow | FileCheck %s --check-prefix=UNSIGNED
2*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -ftrapv | FileCheck %s --check-prefix=TRAPV
3*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -fsanitize=unsigned-integer-overflow -ftrapv | FileCheck %s --check-prefix=BOTH
4*f4a2713aSLionel Sambuc // Verify that -ftrapv and -fsanitize=unsigned-integer-overflow
5*f4a2713aSLionel Sambuc // work together as expected
6*f4a2713aSLionel Sambuc 
7*f4a2713aSLionel Sambuc 
8*f4a2713aSLionel Sambuc // UNSIGNED: @test_signed
9*f4a2713aSLionel Sambuc // TRAPV: @test_signed
10*f4a2713aSLionel Sambuc // BOTH: @test_signed
test_signed()11*f4a2713aSLionel Sambuc void test_signed() {
12*f4a2713aSLionel Sambuc   extern volatile int a, b, c;
13*f4a2713aSLionel Sambuc   // UNSIGNED: add nsw i32
14*f4a2713aSLionel Sambuc   // UNSIGNED-NOT: overflow
15*f4a2713aSLionel Sambuc   // TRAPV: sadd.with.overflow.i32
16*f4a2713aSLionel Sambuc   // TRAPV-NOT: ubsan
17*f4a2713aSLionel Sambuc   // TRAPV: llvm.trap
18*f4a2713aSLionel Sambuc   // BOTH: sadd.with.overflow.i32
19*f4a2713aSLionel Sambuc   // BOTH-NOT: ubsan
20*f4a2713aSLionel Sambuc   // BOTH: llvm.trap
21*f4a2713aSLionel Sambuc   a = b + c;
22*f4a2713aSLionel Sambuc }
23*f4a2713aSLionel Sambuc 
24*f4a2713aSLionel Sambuc // UNSIGNED: @test_unsigned
25*f4a2713aSLionel Sambuc // TRAPV: @test_unsigned
26*f4a2713aSLionel Sambuc // BOTH: @test_unsigned
test_unsigned()27*f4a2713aSLionel Sambuc void test_unsigned() {
28*f4a2713aSLionel Sambuc   extern volatile unsigned x, y, z;
29*f4a2713aSLionel Sambuc   // UNSIGNED: uadd.with.overflow.i32
30*f4a2713aSLionel Sambuc   // UNSIGNED-NOT: llvm.trap
31*f4a2713aSLionel Sambuc   // UNSIGNED: ubsan
32*f4a2713aSLionel Sambuc   // TRAPV-NOT: overflow
33*f4a2713aSLionel Sambuc   // TRAPV-NOT: llvm.trap
34*f4a2713aSLionel Sambuc   // BOTH: uadd.with.overflow.i32
35*f4a2713aSLionel Sambuc   // BOTH: ubsan
36*f4a2713aSLionel Sambuc   // BOTH-NOT: llvm.trap
37*f4a2713aSLionel Sambuc   x = y + z;
38*f4a2713aSLionel Sambuc }
39