1 /* This testcase is part of GDB, the GNU debugger. 2 3 Copyright 2024 Free Software Foundation, Inc. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 18 /* Used to insert labels within function foo. */ 19 #define LABEL(N) asm ("foo_label_" #N ": .globl foo_label_" #N) 20 21 volatile int global_var = 0; 22 23 /* The contents of this '#if 0' block exist so the generated debug can 24 point to these as the source lines. */ 25 #if 0 26 27 void 28 bar (void) /* bar decl line */ 29 { 30 /* bar line 1 */ 31 /* bar line 2 */ 32 } 33 34 void 35 baz (void) /* baz decl line */ 36 { 37 /* baz line 1 */ 38 /* baz line 2 */ 39 } 40 41 void 42 foo (void) /* foo decl line */ 43 { 44 /* foo line 1 */ 45 /* foo line 2 */ 46 /* foo line 3 */ 47 /* foo line 4 */ 48 } 49 50 #endif 51 52 extern void *foo_label_6 (void); 53 54 void 55 foo (void) 56 { 57 /* This label is used to find the start of 'foo' when generating the 58 debug information. */ 59 asm ("foo_label: .globl foo_label"); 60 ++global_var; 61 62 LABEL (1); 63 ++global_var; 64 65 LABEL (2); 66 ++global_var; 67 68 LABEL (3); 69 ++global_var; 70 71 /* This goto will always trigger, but we make it conditional so that the 72 compiler doesn't optimise out the code between the goto and the 73 destination. 74 75 Also 'goto *ADDR' is a GCC extension, but it is critical that the 76 destination address be a global label so that we can generate DWARF 77 that has ranges that start exactly at the destination address. */ 78 if (global_var > 0) 79 goto *(&foo_label_6); 80 81 LABEL (4); 82 ++global_var; 83 84 LABEL (5); 85 ++global_var; 86 87 LABEL (6); 88 ++global_var; 89 90 LABEL (7); 91 ++global_var; 92 93 LABEL (8); 94 ++global_var; 95 96 LABEL (9); 97 ++global_var; 98 } 99 100 int 101 main (void) 102 { 103 asm ("main_label: .globl main_label"); 104 foo (); 105 } 106