summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/alpha/pr39740.c
blob: 230beb7db5d26730ae8e49e3d15738698322ca31 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* { dg-do compile } */
/* { dg-options "-O3 -std=c99 -mexplicit-relocs" } */

typedef int R_len_t;
typedef unsigned int SEXPTYPE;
struct sxpinfo_struct
{
  SEXPTYPE type:5;
};

struct vecsxp_struct
{
  R_len_t length;
  R_len_t truelength;
};

struct listsxp_struct
{
  struct SEXPREC *carval;
  struct SEXPREC *cdrval;
  struct SEXPREC *tagval;
};

typedef struct SEXPREC
{
  struct sxpinfo_struct sxpinfo;
  union
  {
    struct listsxp_struct listsxp;
  } u;
} SEXPREC, *SEXP;

typedef struct VECTOR_SEXPREC
{
  struct vecsxp_struct vecsxp;
} VECTOR_SEXPREC, *VECSEXP;

typedef union
{
  VECTOR_SEXPREC s;
  double align;
} SEXPREC_ALIGN;

extern SEXP R_NilValue;
extern SEXP R_MissingArg;

int Rf_envlength (SEXP rho);
SEXP Rf_protect (SEXP);
const char *Rf_translateChar (SEXP);

inline R_len_t
Rf_length (SEXP s)
{
  int i;
  switch (((s)->sxpinfo.type))
    {
    case 0:
      return 0;
    case 24:
      return (((VECSEXP) (s))->vecsxp.length);
    case 6:
    case 17:
      i = 0;
      while (s != ((void *) 0) && s != R_NilValue)
	{
	  i++;
	  s = ((s)->u.listsxp.cdrval);
	}
      return i;
    case 4:
      return Rf_envlength (s);
    default:
      return 1;
    }
}

inline SEXP
Rf_lang3 (SEXP s, SEXP t, SEXP u)
{
  return s;
}

typedef SEXP (*CCODE) (SEXP, SEXP, SEXP, SEXP);

static SEXP PlusSymbol;
static SEXP MinusSymbol;
static SEXP DivideSymbol;

int isZero (SEXP s);
SEXP PP (SEXP s);
SEXP AddParens (SEXP expr);
SEXP Rf_install ();

static int
isUminus (SEXP s)
{
  if (((s)->sxpinfo.type) == 6 && ((s)->u.listsxp.carval) == MinusSymbol)
    {
      switch (Rf_length (s))
	{
	case 2:
	  return 1;
	case 3:
	  if (((((((s)->u.listsxp.cdrval))->u.listsxp.cdrval))->u.listsxp.
	       carval) == R_MissingArg)
	    return 1;
	  else
	    return 0;
	}
    }
  else
    return 0;
}

static SEXP
simplify (SEXP fun, SEXP arg1, SEXP arg2)
{
  SEXP ans;
  if (fun == PlusSymbol)
    {
      if (isZero (arg1))
	ans = arg2;
      else if (isUminus (arg1))
	ans =
	  simplify (MinusSymbol, arg2,
		    ((((arg1)->u.listsxp.cdrval))->u.listsxp.carval));
      else if (isUminus (arg2))
	ans =
	  simplify (MinusSymbol, arg1,
		    ((((arg2)->u.listsxp.cdrval))->u.listsxp.carval));
    }
  else if (fun == DivideSymbol)
    {
      ans = Rf_lang3 (DivideSymbol, arg1, arg2);
    }

  return ans;
}


static SEXP
D (SEXP expr, SEXP var)
{
  return simplify (PlusSymbol,
		   PP (D
		       (((((expr)->u.listsxp.cdrval))->u.listsxp.carval),
			var)),
		   PP (D
		       (((((((expr)->u.listsxp.cdrval))->u.listsxp.cdrval))->
			 u.listsxp.carval), var)));
}

SEXP
do_D (SEXP call, SEXP op, SEXP args, SEXP env)
{
  SEXP expr, var;
  var = Rf_install ();
  expr = ((args)->u.listsxp.carval);
  Rf_protect (expr = D (expr, var));
  expr = AddParens (expr);
  return expr;
}