summaryrefslogtreecommitdiffstats
path: root/gcc/testsuite/gcc.dg/uninit-A.c
blob: 28f7fe9fcf46db5ce7cedf43ecc4874c8c87a303 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* Inspired by part of java/parse.y.
   May be a real bug in CSE. */

/* { dg-do compile } */
/* { dg-options "-O2 -Wall" } */

struct tree
{
    struct tree *car, *cdr, *wfl;
    int code;
    struct { unsigned int renp:1;
      unsigned int rtnp:1;
      unsigned int rpnp:1; } flags;
};
typedef struct tree *tree;
#define NULL_TREE ((tree)0)

/* Codes */
enum
{
    CALL_EXPR, NEW_ARRAY_EXPR, NEW_CLASS_EXPR, CONVERT_EXPR,
    ARRAY_REF, CONDITIONAL_EXPR, STRING_CST, EXPR_WITH_FILE_LOCATION
};

/* Flags */
#define RESOLVE_EXPRESSION_NAME_P(t) ((t)->flags.renp)
#define RESOLVE_TYPE_NAME_P(t) ((t)->flags.rtnp)
#define RESOLVE_PACKAGE_NAME_P(t) ((t)->flags.rpnp)

/* Macros */
#define EXPR_WFL_QUALIFICATION(t) ((t)->wfl)
#define QUAL_WFL(t) ((t)->wfl)
#define EXPR_WFL_NODE(t) ((t)->wfl)
#define TREE_CODE(t) ((t)->code)
#define TREE_OPERAND(t,x) ((t)->car)
#define CLASSTYPE_SUPER(t) ((t)->car)
#define IDENTIFIER_LOCAL_VALUE(t) ((t)->car)
#define TREE_CHAIN(t) ((t)->cdr)
#define QUAL_RESOLUTION(t) ((t)->cdr)

extern tree current_class, this_identifier_node;
extern tree super_identifier_node, length_identifier_node;

tree resolve_and_layout (tree, tree);
tree lookup_field_wrapper (tree, tree);

void
qualify_ambiguous_name (id)
     tree id;
{
  tree qual, qual_wfl, decl;
  tree name;	 /* { dg-bogus "name" "uninitialized variable warning" } */
  tree ptr_type; /* { dg-bogus "ptr_type" "uninitialized variable warning" } */
  int again, new_array_found = 0;
  int super_found = 0, this_found = 0;

  qual = EXPR_WFL_QUALIFICATION (id);
  do {
    qual_wfl = QUAL_WFL (qual);
    switch (TREE_CODE (qual_wfl))
      {
      case CALL_EXPR:
	qual_wfl = TREE_OPERAND (qual_wfl, 0);
	if (TREE_CODE (qual_wfl) != EXPR_WITH_FILE_LOCATION)
	  {
	    qual = EXPR_WFL_QUALIFICATION (qual_wfl);
	    qual_wfl = QUAL_WFL (qual);
	  }
	break;
      case NEW_ARRAY_EXPR:
	qual = TREE_CHAIN (qual);
	new_array_found = again = 1;
	continue;
      case NEW_CLASS_EXPR:
      case CONVERT_EXPR:
	qual_wfl = TREE_OPERAND (qual_wfl, 0);
	break;
      case ARRAY_REF:
	while (TREE_CODE (qual_wfl) == ARRAY_REF)
	  qual_wfl = TREE_OPERAND (qual_wfl, 0);
	break;
      default:
	break;
      }

    name = EXPR_WFL_NODE (qual_wfl);
    ptr_type = current_class;
    again = 0;

  } while (again);

  /* If you put straightforward uses of name and ptr_type here
     instead of the if-else sequence below, the warnings go away.
     Therefore I suspect a real bug. */
  
  if (!this_found && !super_found && (decl = IDENTIFIER_LOCAL_VALUE (name)))
    {
      RESOLVE_EXPRESSION_NAME_P (qual_wfl) = 1;
      QUAL_RESOLUTION (qual) = decl;
    }
  else if ((decl = lookup_field_wrapper (ptr_type, name))
	   || (new_array_found && name == length_identifier_node))
    {
      RESOLVE_EXPRESSION_NAME_P (qual_wfl) = 1;
      QUAL_RESOLUTION (qual) = (new_array_found ? NULL_TREE : decl);
    }
  else if ((decl = resolve_and_layout (name, NULL_TREE)))
    {
      RESOLVE_TYPE_NAME_P (qual_wfl) = 1;
      QUAL_RESOLUTION (qual) = decl;
    }
  else if (TREE_CODE (QUAL_WFL (qual)) == CALL_EXPR
	   || TREE_CODE (QUAL_WFL (qual)) == ARRAY_REF)
    RESOLVE_EXPRESSION_NAME_P (qual_wfl) = 1;
  else 
    RESOLVE_PACKAGE_NAME_P (qual_wfl) = 1;
}
OpenPOWER on IntegriCloud