Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/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
5.73M
#define states1 long    /* for later use in llvm_regexec() decision */
59
5.73M
#define states  states1
60
3.76M
#define CLEAR(v)  ((v) = 0)
61
#define SET0(v, n)  ((v) &= ~((unsigned long)1 << (n)))
62
1.91M
#define SET1(v, n)  ((v) |= (unsigned long)1 << (n))
63
23.0M
#define ISSET(v, n) (((v) & ((unsigned long)1 << (n))) != 0)
64
40.4M
#define ASSIGN(d, s)  ((d) = (s))
65
21.1M
#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.41M
#define SETUP(v)  ((v) = 0)
70
27.8M
#define onestate  long
71
28.1M
#define INIT(o, n)  ((o) = (unsigned long)1 << (n))
72
865M
#define INC(o)    ((o) = (unsigned long)(o) << 1)
73
79.7M
#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
434M
#define FWD(dst, src, n)  ((dst) |= ((unsigned long)(src)&(here)) << (n))
77
4.05M
#define BACK(dst, src, n) ((dst) |= ((unsigned long)(src)&(here)) >> (n))
78
7.41M
#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
570k
#define states  char *
107
369k
#define CLEAR(v)  memset(v, 0, m->g->nstates)
108
#define SET0(v, n)  ((v)[n] = 0)
109
190k
#define SET1(v, n)  ((v)[n] = 1)
110
2.34M
#define ISSET(v, n) ((v)[n])
111
4.13M
#define ASSIGN(d, s)  memmove(d, s, m->g->nstates)
112
2.16M
#define EQ(a, b)  (memcmp(a, b, m->g->nstates) == 0)
113
#define STATEVARS long vn; char *space
114
179k
#define STATESETUP(m, nv) { (m)->space = malloc((nv)*(m)->g->nstates); \
115
179k
        if (
(m)->space == NULL179k
)
return(0
REG_ESPACE0
); \
116
179k
        (m)->vn = 0; }
117
179k
#define STATETEARDOWN(m)  { free((m)->space); }
118
719k
#define SETUP(v)  ((v) = &m->space[m->vn++ * m->g->nstates])
119
2.85M
#define onestate  long
120
2.87M
#define INIT(o, n)  ((o) = (n))
121
230M
#define INC(o)  ((o)++)
122
24.6M
#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
105M
#define FWD(dst, src, n)  ((dst)[here+(n)] |= (src)[here])
126
564k
#define BACK(dst, src, n) ((dst)[here-(n)] |= (src)[here])
127
1.06M
#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
251M
{
144
251M
  struct re_guts *g = preg->re_g;
145
#ifdef REDEBUG
146
# define  GOODFLAGS(f)  (f)
147
#else
148
251M
# define  GOODFLAGS(f)  
((f)&(251M
REG_NOTBOL251M
|
REG_NOTEOL251M
|
REG_STARTEND251M
))
149
251M
#endif
150
251M
151
251M
  if (
preg->re_magic != 251M
MAGIC1251M
||
g->magic != 251M
MAGIC2251M
)
152
0
    
return(0
REG_BADPAT0
);
153
251M
  assert(!(g->iflags&REGEX_BAD));
154
251M
  if (
g->iflags&251M
REGEX_BAD251M
)   /* backstop for no-debug case */
155
0
    
return(0
REG_BADPAT0
);
156
251M
  
eflags = 251M
GOODFLAGS251M
(eflags);
157
251M
158
251M
  if (
g->nstates <= (long)(CHAR_BIT*sizeof(states1)) && 251M
!(eflags&250M
REG_LARGE250M
))
159
250M
    return(smatcher(g, string, nmatch, pmatch, eflags));
160
251M
  else
161
614k
    return(lmatcher(g, string, nmatch, pmatch, eflags));
162
0
}