summaryrefslogtreecommitdiffstats
path: root/clang/test/CodeGen/integer-overflow.c
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-06-26 21:25:03 +0000
committerChris Lattner <sabre@nondot.org>2010-06-26 21:25:03 +0000
commit51924e517bd2d25faea6ef873db3c59ec4d09bf8 (patch)
tree7d971b3e55a000a23d28dac62cc985f20f05be06 /clang/test/CodeGen/integer-overflow.c
parent217e056e409f51bc64a82334e72bed0f14a51270 (diff)
downloadbcm5719-llvm-51924e517bd2d25faea6ef873db3c59ec4d09bf8.tar.gz
bcm5719-llvm-51924e517bd2d25faea6ef873db3c59ec4d09bf8.zip
Implement support for -fwrapv, rdar://7221421
As part of this, pull together trapv handling into the same enum. This also add support for NSW multiplies. This also makes PCH disagreement on overflow behavior silent, since it really doesn't matter except for warnings and codegen (no macros get defined etc). llvm-svn: 106956
Diffstat (limited to 'clang/test/CodeGen/integer-overflow.c')
-rw-r--r--clang/test/CodeGen/integer-overflow.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/clang/test/CodeGen/integer-overflow.c b/clang/test/CodeGen/integer-overflow.c
new file mode 100644
index 00000000000..79692161042
--- /dev/null
+++ b/clang/test/CodeGen/integer-overflow.c
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s --check-prefix=DEFAULT
+// RUN: %clang_cc1 %s -emit-llvm -o - -fwrapv | FileCheck %s --check-prefix=WRAPV
+// RUN: %clang_cc1 %s -emit-llvm -o - -ftrapv | FileCheck %s --check-prefix=TRAPV
+
+
+// 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
+ f11G = a + b;
+
+ // DEFAULT: sub nsw i32
+ // WRAPV: sub i32
+ // TRAPV: llvm.ssub.with.overflow.i32
+ f11G = a - b;
+
+ // DEFAULT: sub nsw i32 0,
+ // WRAPV: sub i32 0,
+ // TRAPV: sub nsw i32 0,
+ f11G = -a;
+
+ // DEFAULT: mul nsw i32
+ // WRAPV: mul i32
+ // TRAPV: llvm.smul.with.overflow.i32
+ f11G = a * b;
+}
OpenPOWER on IntegriCloud