Home | History | Annotate | Download | only in CodeGen
      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
      6 
      7 
      8 // UNSIGNED: @test_signed
      9 // TRAPV: @test_signed
     10 // BOTH: @test_signed
     11 void test_signed() {
     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.trap
     18   // BOTH: sadd.with.overflow.i32
     19   // BOTH-NOT: ubsan
     20   // BOTH: llvm.trap
     21   a = b + c;
     22 }
     23 
     24 // UNSIGNED: @test_unsigned
     25 // TRAPV: @test_unsigned
     26 // BOTH: @test_unsigned
     27 void test_unsigned() {
     28   extern volatile unsigned x, y, z;
     29   // UNSIGNED: uadd.with.overflow.i32
     30   // UNSIGNED-NOT: llvm.trap
     31   // UNSIGNED: ubsan
     32   // TRAPV-NOT: overflow
     33   // TRAPV-NOT: llvm.trap
     34   // BOTH: uadd.with.overflow.i32
     35   // BOTH: ubsan
     36   // BOTH-NOT: llvm.trap
     37   x = y + z;
     38 }
     39