2012-05-10 05:21:49 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - | FileCheck %s --check-prefix=DEFAULT
|
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -fwrapv | FileCheck %s --check-prefix=WRAPV
|
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -ftrapv | FileCheck %s --check-prefix=TRAPV
|
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -ftrapv -ftrapv-handler foo | FileCheck %s --check-prefix=TRAPV_HANDLER
|
2010-06-27 05:25:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
// Tests for signed integer overflow stuff.
|
|
|
|
// rdar://7432000 rdar://7221421
|
|
|
|
void test1() {
|
|
|
|
// DEFAULT: define void @test1
|
|
|
|
// WRAPV: define void @test1
|
|
|
|
// TRAPV: define void @test1
|
|
|
|
extern volatile int f11G, a, b;
|
|
|
|
|
|
|
|
// DEFAULT: add nsw i32
|
|
|
|
// WRAPV: add i32
|
|
|
|
// TRAPV: llvm.sadd.with.overflow.i32
|
2010-09-18 02:29:54 +08:00
|
|
|
// TRAPV_HANDLER: foo(
|
2010-06-27 05:25:03 +08:00
|
|
|
f11G = a + b;
|
|
|
|
|
|
|
|
// DEFAULT: sub nsw i32
|
|
|
|
// WRAPV: sub i32
|
|
|
|
// TRAPV: llvm.ssub.with.overflow.i32
|
2010-09-18 02:29:54 +08:00
|
|
|
// TRAPV_HANDLER: foo(
|
2010-06-27 05:25:03 +08:00
|
|
|
f11G = a - b;
|
|
|
|
|
|
|
|
// DEFAULT: mul nsw i32
|
|
|
|
// WRAPV: mul i32
|
|
|
|
// TRAPV: llvm.smul.with.overflow.i32
|
2010-09-18 02:29:54 +08:00
|
|
|
// TRAPV_HANDLER: foo(
|
2010-06-27 05:25:03 +08:00
|
|
|
f11G = a * b;
|
2010-06-27 06:18:28 +08:00
|
|
|
|
|
|
|
// DEFAULT: sub nsw i32 0,
|
|
|
|
// WRAPV: sub i32 0,
|
|
|
|
// TRAPV: llvm.ssub.with.overflow.i32(i32 0
|
2010-09-18 02:29:54 +08:00
|
|
|
// TRAPV_HANDLER: foo(
|
2010-06-27 06:18:28 +08:00
|
|
|
f11G = -a;
|
|
|
|
|
|
|
|
// PR7426 - Overflow checking for increments.
|
|
|
|
|
|
|
|
// DEFAULT: add nsw i32 {{.*}}, 1
|
|
|
|
// WRAPV: add i32 {{.*}}, 1
|
|
|
|
// TRAPV: llvm.sadd.with.overflow.i32({{.*}}, i32 1)
|
2010-09-18 02:29:54 +08:00
|
|
|
// TRAPV_HANDLER: foo(
|
2010-06-27 06:18:28 +08:00
|
|
|
++a;
|
|
|
|
|
|
|
|
// DEFAULT: add nsw i32 {{.*}}, -1
|
|
|
|
// WRAPV: add i32 {{.*}}, -1
|
|
|
|
// TRAPV: llvm.sadd.with.overflow.i32({{.*}}, i32 -1)
|
2010-09-18 02:29:54 +08:00
|
|
|
// TRAPV_HANDLER: foo(
|
2010-06-27 06:18:28 +08:00
|
|
|
--a;
|
2011-03-01 08:03:48 +08:00
|
|
|
|
|
|
|
// -fwrapv should turn off inbounds for GEP's, PR9256
|
|
|
|
extern int* P;
|
|
|
|
++P;
|
|
|
|
// DEFAULT: getelementptr inbounds i32*
|
|
|
|
// WRAPV: getelementptr i32*
|
|
|
|
// TRAPV: getelementptr inbounds i32*
|
2011-03-02 09:49:12 +08:00
|
|
|
|
|
|
|
// PR9350: char increment never overflows.
|
|
|
|
extern volatile signed char PR9350;
|
|
|
|
// DEFAULT: add i8 {{.*}}, 1
|
|
|
|
// WRAPV: add i8 {{.*}}, 1
|
|
|
|
// TRAPV: add i8 {{.*}}, 1
|
|
|
|
++PR9350;
|
2010-06-27 05:25:03 +08:00
|
|
|
}
|