Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / native_client / tests / toolchain / dwarf_local_var.c
1 /*
2  * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6
7 /* Test that dwarf info for local variables is preserved after linking.
8  *
9  * We have checks encoded as "CHECK: regex", and the regexes must be
10  * matched in-order in the disassembled file.  An external tool
11  * "file-check" will do the checks provided this source file and the binary.
12  */
13
14 #include <stdlib.h>
15
16 extern int bar(int x) __attribute__((noinline));
17
18 __attribute__((noinline)) int foo(int dwarf_test_param) {
19   /* CHECK: DW_TAG_formal_parameter */
20   /* CHECK: DW_AT_name.* dwarf_test_param */
21   /* CHECK: DW_AT_decl_line.* 18 */
22   return bar(dwarf_test_param);
23 }
24
25 int main(int argc, char* argv[]) {
26   int dwarf_test_local;
27   /* CHECK: DW_TAG_variable */
28   /* CHECK: DW_AT_name.* dwarf_test_local */
29   /* CHECK: DW_AT_decl_line.* 26 */
30
31   /* Try to trick the optimizer to preserve dwarf_test_local. */
32   if (argc != 55) {
33     /* This branch should be taken. */
34     dwarf_test_local = 55;
35   } else if (argc == 54) {
36     dwarf_test_local = atoi(argv[1]);
37   } else {
38     dwarf_test_local = -1;
39   }
40
41   if (argc != 54) {
42     /* This branch should be taken. */
43     return foo(dwarf_test_local);
44   } else {
45     return -1;
46   }
47 }