1/* Copyright 2018-2023 Free Software Foundation, Inc.
2
3   This program is free software; you can redistribute it and/or modify
4   it under the terms of the GNU General Public License as published by
5   the Free Software Foundation; either version 3 of the License, or
6   (at your option) any later version.
7
8   This program is distributed in the hope that it will be useful,
9   but WITHOUT ANY WARRANTY; without even the implied warranty of
10   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11   GNU General Public License for more details.
12
13   You should have received a copy of the GNU General Public License
14   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
15
16/* The idea here is to, via use of the dwarf assembler, create a function
17   which occupies two non-contiguous address ranges.
18
19   foo_cold and foo will be combined into a single function foo with a
20   function bar in between these two ranges.
21
22   This test case was motivated by a bug in which a function which
23   occupied two non-contiguous address ranges was calling another
24   function which resides in between these ranges.  So we end up with
25   a situation in which the low/start address of our constructed foo
26   (in this case) will be less than any of the addresses in bar, but
27   the high/end address of foo will be greater than any of bar's
28   addresses.
29
30   This situation was causing a problem in the caching code of
31   find_pc_partial_function:  When the low and high addresses of foo
32   are placed in the cache, the simple check that was used to see if
33   the cache was applicable would (incorrectly) succeed when presented
34   with an address in bar.  I.e. an address in bar presented as an
35   input to find_pc_partial_function could produce the answer "this
36   address belongs to foo".  */
37
38volatile int e = 0;
39
40void bar (void);
41void foo_cold (void);
42void baz (void);
43
44void
45baz (void)
46{
47  asm ("baz_label: .globl baz_label");
48}						/* baz end */
49
50void
51foo_cold (void)
52{						/* foo_cold prologue */
53  asm ("foo_cold_label: .globl foo_cold_label");
54  baz ();					/* foo_cold baz call */
55  asm ("foo_cold_label2: .globl foo_cold_label2");
56}						/* foo_cold end */
57
58void
59bar (void)
60{
61  asm ("bar_label: .globl bar_label");
62}						/* bar end */
63
64void
65foo (void)
66{						/* foo prologue */
67  asm ("foo_label: .globl foo_label");
68  bar ();					/* foo bar call */
69  asm ("foo_label2: .globl foo_label2");
70  if (e) foo_cold ();				/* foo foo_cold call */
71  asm ("foo_label3: .globl foo_label3");
72}						/* foo end */
73
74int
75main (void)
76{						/* main prologue */
77  asm ("main_label: .globl main_label");
78  foo ();					/* main foo call */
79  asm ("main_label2: .globl main_label2");
80  return 0;					/* main return */
81}						/* main end */
82
83