xref: /netbsd-src/tests/usr.bin/cc/t_ubsan_int_add_overflow.sh (revision f4fc04f995e166378c59f264211c87641a857783)
1*f4fc04f9Smrg#	$NetBSD: t_ubsan_int_add_overflow.sh,v 1.5 2019/02/09 00:13:19 mrg Exp $
2*f4fc04f9Smrg#
3b4870a45Smgorny# Copyright (c) 2018, 2019 The NetBSD Foundation, Inc.
4e308425eSkamil# All rights reserved.
5e308425eSkamil#
6e308425eSkamil# This code is derived from software contributed to The NetBSD Foundation
7e308425eSkamil# by Harry Pantazis.
8e308425eSkamil#
9e308425eSkamil# Redistribution and use in source and binary forms, with or without
10e308425eSkamil# modification, are permitted provided that the following conditions
11e308425eSkamil# are met:
12e308425eSkamil# 1. Redistributions of source code must retain the above copyright
13e308425eSkamil#    notice, this list of conditions and the following disclaimer.
14e308425eSkamil# 2. Redistributions in binary form must reproduce the above copyright
15e308425eSkamil#    notice, this list of conditions and the following disclaimer in the
16e308425eSkamil#    documentation and/or other materials provided with the distribution.
17e308425eSkamil#
18e308425eSkamil# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19e308425eSkamil# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20e308425eSkamil# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21e308425eSkamil# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22e308425eSkamil# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23e308425eSkamil# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24e308425eSkamil# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25e308425eSkamil# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26e308425eSkamil# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27e308425eSkamil# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28e308425eSkamil# POSSIBILITY OF SUCH DAMAGE.
29e308425eSkamil#
30e308425eSkamil
31b4870a45SmgornyUBSAN_CODE='
32e308425eSkamil#include <limits.h>
33e308425eSkamil#include <stdio.h>
34e308425eSkamil#include <stdlib.h>
35e308425eSkamilint help(int);
36b4870a45Smgorny#ifndef PIC_MAIN
37e308425eSkamilint help(int count) {volatile int l = INT_MAX; l+= count; return l;}
38b4870a45Smgorny#endif
39b4870a45Smgorny#ifndef PIC_FOO
40e308425eSkamilint main(int argc, char **argv) {volatile int l = INT_MAX; l+=argc; return l;}
41b4870a45Smgorny#endif
42b4870a45Smgorny'
43e308425eSkamil
44b4870a45Smgornyubsan_test_case int_add_overflow "int addition overflows" \
45b4870a45Smgorny	"signed integer overflow"
46e308425eSkamil
47e308425eSkamilatf_init_test_cases()
48e308425eSkamil{
49b4870a45Smgorny	ubsan_add_test_cases int_add_overflow
50e308425eSkamil}
51