mirror of
https://github.com/Gericom/teak-llvm.git
synced 2025-06-20 12:05:48 -04:00

by this mode, and also check for signed left shift overflow. The rules for the latter are a little subtle: * neither C89 nor C++98 specify the behavior of a signed left shift at all * in C99 and C11, shifting a 1 bit into the sign bit has undefined behavior * in C++11, with core issue 1457, shifting a 1 bit *out* of the sign bit has undefined behavior As of this change, we use the C99 rules for all C language variants, and the C++11 rules for all C++ language variants. Once we have individual -fcatch-undefined-behavior= flags, this should be revisited. llvm-svn: 162634
76 lines
2.4 KiB
C
76 lines
2.4 KiB
C
// 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 - -fcatch-undefined-behavior | FileCheck %s --check-prefix=CATCH_UB
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -ftrapv -ftrapv-handler foo | FileCheck %s --check-prefix=TRAPV_HANDLER
|
|
|
|
|
|
// 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
|
|
// CATCH_UB: llvm.sadd.with.overflow.i32
|
|
// TRAPV_HANDLER: foo(
|
|
f11G = a + b;
|
|
|
|
// DEFAULT: sub nsw i32
|
|
// WRAPV: sub i32
|
|
// TRAPV: llvm.ssub.with.overflow.i32
|
|
// CATCH_UB: llvm.ssub.with.overflow.i32
|
|
// TRAPV_HANDLER: foo(
|
|
f11G = a - b;
|
|
|
|
// DEFAULT: mul nsw i32
|
|
// WRAPV: mul i32
|
|
// TRAPV: llvm.smul.with.overflow.i32
|
|
// CATCH_UB: llvm.smul.with.overflow.i32
|
|
// TRAPV_HANDLER: foo(
|
|
f11G = a * b;
|
|
|
|
// DEFAULT: sub nsw i32 0,
|
|
// WRAPV: sub i32 0,
|
|
// TRAPV: llvm.ssub.with.overflow.i32(i32 0
|
|
// CATCH_UB: llvm.ssub.with.overflow.i32(i32 0
|
|
// TRAPV_HANDLER: foo(
|
|
f11G = -a;
|
|
|
|
// PR7426 - Overflow checking for increments.
|
|
|
|
// DEFAULT: add nsw i32 {{.*}}, 1
|
|
// WRAPV: add i32 {{.*}}, 1
|
|
// TRAPV: llvm.sadd.with.overflow.i32({{.*}}, i32 1)
|
|
// CATCH_UB: llvm.sadd.with.overflow.i32({{.*}}, i32 1)
|
|
// TRAPV_HANDLER: foo(
|
|
++a;
|
|
|
|
// DEFAULT: add nsw i32 {{.*}}, -1
|
|
// WRAPV: add i32 {{.*}}, -1
|
|
// TRAPV: llvm.sadd.with.overflow.i32({{.*}}, i32 -1)
|
|
// CATCH_UB: llvm.sadd.with.overflow.i32({{.*}}, i32 -1)
|
|
// TRAPV_HANDLER: foo(
|
|
--a;
|
|
|
|
// -fwrapv should turn off inbounds for GEP's, PR9256
|
|
extern int* P;
|
|
++P;
|
|
// DEFAULT: getelementptr inbounds i32*
|
|
// WRAPV: getelementptr i32*
|
|
// TRAPV: getelementptr inbounds i32*
|
|
// CATCH_UB: getelementptr inbounds i32*
|
|
|
|
// PR9350: char increment never overflows.
|
|
extern volatile signed char PR9350;
|
|
// DEFAULT: add i8 {{.*}}, 1
|
|
// WRAPV: add i8 {{.*}}, 1
|
|
// TRAPV: add i8 {{.*}}, 1
|
|
// CATCH_UB: add i8 {{.*}}, 1
|
|
++PR9350;
|
|
}
|