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