Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Support/regexec.c
Line
Count
Source (jump to first uncovered line)
1
/*-
2
 * This code is derived from OpenBSD's libc/regex, original license follows:
3
 *
4
 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
5
 * Copyright (c) 1992, 1993, 1994
6
 *  The Regents of the University of California.  All rights reserved.
7
 *
8
 * This code is derived from software contributed to Berkeley by
9
 * Henry Spencer.
10
 *
11
 * Redistribution and use in source and binary forms, with or without
12
 * modification, are permitted provided that the following conditions
13
 * are met:
14
 * 1. Redistributions of source code must retain the above copyright
15
 *    notice, this list of conditions and the following disclaimer.
16
 * 2. Redistributions in binary form must reproduce the above copyright
17
 *    notice, this list of conditions and the following disclaimer in the
18
 *    documentation and/or other materials provided with the distribution.
19
 * 3. Neither the name of the University nor the names of its contributors
20
 *    may be used to endorse or promote products derived from this software
21
 *    without specific prior written permission.
22
 *
23
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33
 * SUCH DAMAGE.
34
 *
35
 *  @(#)regexec.c 8.3 (Berkeley) 3/20/94
36
 */
37
38
/*
39
 * the outer shell of llvm_regexec()
40
 *
41
 * This file includes engine.inc *twice*, after muchos fiddling with the
42
 * macros that code uses.  This lets the same code operate on two different
43
 * representations for state sets.
44
 */
45
#include <sys/types.h>
46
#include <stdio.h>
47
#include <stdlib.h>
48
#include <string.h>
49
#include <limits.h>
50
#include <ctype.h>
51
#include "regex_impl.h"
52
53
#include "regutils.h"
54
#include "regex2.h"
55
56
/* macros for manipulating states, small version */
57
/* FIXME: 'states' is assumed as 'long' on small version. */
58
6.15M
#define states1 long    /* for later use in llvm_regexec() decision */
59
6.15M
#define states  states1
60
4.04M
#define CLEAR(v)  ((v) = 0)
61
#define SET0(v, n)  ((v) &= ~((unsigned long)1 << (n)))
62
2.05M
#define SET1(v, n)  ((v) |= (unsigned long)1 << (n))
63
46.8M
#define ISSET(v, n) (((v) & ((unsigned long)1 << (n))) != 0)
64
63.7M
#define ASSIGN(d, s)  ((d) = (s))
65
23.0M
#define EQ(a, b)  ((a) == (b))
66
#define STATEVARS long dummy  /* dummy version */
67
#define STATESETUP(m, n)  /* nothing */
68
#define STATETEARDOWN(m)  /* nothing */
69
7.95M
#define SETUP(v)  ((v) = 0)
70
29.8M
#define onestate  long
71
30.2M
#define INIT(o, n)  ((o) = (unsigned long)1 << (n))
72
1.00G
#define INC(o)    ((o) = (unsigned long)(o) << 1)
73
91.0M
#define ISSTATEIN(v, o) (((v) & (o)) != 0)
74
/* some abbreviations; note that some of these know variable names! */
75
/* do "if I'm here, I can also be there" etc without branches */
76
479M
#define FWD(dst, src, n)  ((dst) |= ((unsigned long)(src)&(here)) << (n))
77
4.19M
#define BACK(dst, src, n) ((dst) |= ((unsigned long)(src)&(here)) >> (n))
78
7.64M
#define ISSETBACK(v, n)   (((v) & ((unsigned long)here >> (n))) != 0)
79
/* function names */
80
#define SNAMES      /* engine.inc looks after details */
81
82
#include "regengine.inc"
83
84
/* now undo things */
85
#undef  states
86
#undef  CLEAR
87
#undef  SET0
88
#undef  SET1
89
#undef  ISSET
90
#undef  ASSIGN
91
#undef  EQ
92
#undef  STATEVARS
93
#undef  STATESETUP
94
#undef  STATETEARDOWN
95
#undef  SETUP
96
#undef  onestate
97
#undef  INIT
98
#undef  INC
99
#undef  ISSTATEIN
100
#undef  FWD
101
#undef  BACK
102
#undef  ISSETBACK
103
#undef  SNAMES
104
105
/* macros for manipulating states, large version */
106
965k
#define states  char *
107
623k
#define CLEAR(v)  memset(v, 0, m->g->nstates)
108
#define SET0(v, n)  ((v)[n] = 0)
109
321k
#define SET1(v, n)  ((v)[n] = 1)
110
7.79M
#define ISSET(v, n) ((v)[n])
111
10.6M
#define ASSIGN(d, s)  memmove(d, s, m->g->nstates)
112
3.85M
#define EQ(a, b)  (memcmp(a, b, m->g->nstates) == 0)
113
#define STATEVARS long vn; char *space
114
302k
#define STATESETUP(m, nv) { (m)->space = malloc((nv)*(m)->g->nstates); \
115
302k
        if ((m)->space == NULL) 
return(0
REG_ESPACE0
); \
116
302k
        (m)->vn = 0; }
117
302k
#define STATETEARDOWN(m)  { free((m)->space); }
118
1.20M
#define SETUP(v)  ((v) = &m->space[m->vn++ * m->g->nstates])
119
4.93M
#define onestate  long
120
4.97M
#define INIT(o, n)  ((o) = (n))
121
398M
#define INC(o)  ((o)++)
122
42.8M
#define ISSTATEIN(v, o) ((v)[o])
123
/* some abbreviations; note that some of these know variable names! */
124
/* do "if I'm here, I can also be there" etc without branches */
125
181M
#define FWD(dst, src, n)  ((dst)[here+(n)] |= (src)[here])
126
1.12M
#define BACK(dst, src, n) ((dst)[here-(n)] |= (src)[here])
127
2.14M
#define ISSETBACK(v, n) ((v)[here - (n)])
128
/* function names */
129
#define LNAMES      /* flag */
130
131
#include "regengine.inc"
132
133
/*
134
 - llvm_regexec - interface for matching
135
 *
136
 * We put this here so we can exploit knowledge of the state representation
137
 * when choosing which matcher to call.  Also, by this point the matchers
138
 * have been prototyped.
139
 */
140
int       /* 0 success, REG_NOMATCH failure */
141
llvm_regexec(const llvm_regex_t *preg, const char *string, size_t nmatch,
142
             llvm_regmatch_t pmatch[], int eflags)
143
35.3M
{
144
35.3M
  struct re_guts *g = preg->re_g;
145
#ifdef REDEBUG
146
# define  GOODFLAGS(f)  (f)
147
#else
148
35.3M
# define  GOODFLAGS(f)  ((f)&(REG_NOTBOL|REG_NOTEOL|REG_STARTEND))
149
35.3M
#endif
150
35.3M
151
35.3M
  if (preg->re_magic != MAGIC1 || g->magic != MAGIC2)
152
35.3M
    
return(0
REG_BADPAT0
);
153
35.3M
  assert(!(g->iflags&REGEX_BAD));
154
35.3M
  if (g->iflags&REGEX_BAD)   /* backstop for no-debug case */
155
35.3M
    
return(0
REG_BADPAT0
);
156
35.3M
  eflags = GOODFLAGS(eflags);
157
35.3M
158
35.3M
  if (g->nstates <= (long)(CHAR_BIT*sizeof(states1)) && 
!(eflags&34.7M
REG_LARGE34.7M
))
159
34.7M
    return(smatcher(g, string, nmatch, pmatch, eflags));
160
606k
  else
161
606k
    return(lmatcher(g, string, nmatch, pmatch, eflags));
162
35.3M
}