Skip to content

Commit a52223b

Browse files
committed
Merge 100438 from mainline.
Push const through the regex engine. Fixes some of the warnings in PR6616. llvm-svn: 100450
1 parent b76aad9 commit a52223b

File tree

2 files changed

+51
-44
lines changed

2 files changed

+51
-44
lines changed

llvm/lib/Support/regengine.inc

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,26 @@ struct match {
7272
struct re_guts *g;
7373
int eflags;
7474
llvm_regmatch_t *pmatch; /* [nsub+1] (0 element unused) */
75-
char *offp; /* offsets work from here */
76-
char *beginp; /* start of string -- virtual NUL precedes */
77-
char *endp; /* end of string -- virtual NUL here */
78-
char *coldp; /* can be no match starting before here */
79-
char **lastpos; /* [nplus+1] */
75+
const char *offp; /* offsets work from here */
76+
const char *beginp; /* start of string -- virtual NUL precedes */
77+
const char *endp; /* end of string -- virtual NUL here */
78+
const char *coldp; /* can be no match starting before here */
79+
const char **lastpos; /* [nplus+1] */
8080
STATEVARS;
8181
states st; /* current states */
8282
states fresh; /* states for a fresh start */
8383
states tmp; /* temporary */
8484
states empty; /* empty set of states */
8585
};
8686

87-
static int matcher(struct re_guts *, char *, size_t, llvm_regmatch_t[], int);
88-
static char *dissect(struct match *, char *, char *, sopno, sopno);
89-
static char *backref(struct match *, char *, char *, sopno, sopno, sopno, int);
90-
static char *fast(struct match *, char *, char *, sopno, sopno);
91-
static char *slow(struct match *, char *, char *, sopno, sopno);
87+
static int matcher(struct re_guts *, const char *, size_t,
88+
llvm_regmatch_t[], int);
89+
static const char *dissect(struct match *, const char *, const char *, sopno,
90+
sopno);
91+
static const char *backref(struct match *, const char *, const char *, sopno,
92+
sopno, sopno, int);
93+
static const char *fast(struct match *, const char *, const char *, sopno, sopno);
94+
static const char *slow(struct match *, const char *, const char *, sopno, sopno);
9295
static states step(struct re_guts *, sopno, sopno, states, int, states);
9396
#define MAX_RECURSION 100
9497
#define BOL (OUT+1)
@@ -125,18 +128,19 @@ static int nope = 0;
125128
- matcher - the actual matching engine
126129
*/
127130
static int /* 0 success, REG_NOMATCH failure */
128-
matcher(struct re_guts *g, char *string, size_t nmatch, llvm_regmatch_t pmatch[],
131+
matcher(struct re_guts *g, const char *string, size_t nmatch,
132+
llvm_regmatch_t pmatch[],
129133
int eflags)
130134
{
131-
char *endp;
135+
const char *endp;
132136
size_t i;
133137
struct match mv;
134138
struct match *m = &mv;
135-
char *dp;
139+
const char *dp;
136140
const sopno gf = g->firststate+1; /* +1 for OEND */
137141
const sopno gl = g->laststate;
138-
char *start;
139-
char *stop;
142+
const char *start;
143+
const char *stop;
140144

141145
/* simplify the situation where possible */
142146
if (g->cflags&REG_NOSUB)
@@ -216,7 +220,7 @@ matcher(struct re_guts *g, char *string, size_t nmatch, llvm_regmatch_t pmatch[]
216220
dp = dissect(m, m->coldp, endp, gf, gl);
217221
} else {
218222
if (g->nplus > 0 && m->lastpos == NULL)
219-
m->lastpos = (char **)malloc((g->nplus+1) *
223+
m->lastpos = (const char **)malloc((g->nplus+1) *
220224
sizeof(char *));
221225
if (g->nplus > 0 && m->lastpos == NULL) {
222226
free(m->pmatch);
@@ -287,21 +291,22 @@ matcher(struct re_guts *g, char *string, size_t nmatch, llvm_regmatch_t pmatch[]
287291
/*
288292
- dissect - figure out what matched what, no back references
289293
*/
290-
static char * /* == stop (success) always */
291-
dissect(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
294+
static const char * /* == stop (success) always */
295+
dissect(struct match *m, const char *start, const char *stop, sopno startst,
296+
sopno stopst)
292297
{
293298
int i;
294299
sopno ss; /* start sop of current subRE */
295300
sopno es; /* end sop of current subRE */
296-
char *sp; /* start of string matched by it */
297-
char *stp; /* string matched by it cannot pass here */
298-
char *rest; /* start of rest of string */
299-
char *tail; /* string unmatched by rest of RE */
301+
const char *sp; /* start of string matched by it */
302+
const char *stp; /* string matched by it cannot pass here */
303+
const char *rest; /* start of rest of string */
304+
const char *tail; /* string unmatched by rest of RE */
300305
sopno ssub; /* start sop of subsubRE */
301306
sopno esub; /* end sop of subsubRE */
302-
char *ssp; /* start of string matched by subsubRE */
303-
char *sep; /* end of string matched by subsubRE */
304-
char *oldssp; /* previous ssp */
307+
const char *ssp; /* start of string matched by subsubRE */
308+
const char *sep; /* end of string matched by subsubRE */
309+
const char *oldssp; /* previous ssp */
305310

306311
AT("diss", start, stop, startst, stopst);
307312
sp = start;
@@ -360,7 +365,7 @@ dissect(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
360365
esub = es - 1;
361366
/* did innards match? */
362367
if (slow(m, sp, rest, ssub, esub) != NULL) {
363-
char *dp = dissect(m, sp, rest, ssub, esub);
368+
const char *dp = dissect(m, sp, rest, ssub, esub);
364369
(void)dp; /* avoid warning if assertions off */
365370
assert(dp == rest);
366371
} else /* no */
@@ -400,7 +405,7 @@ dissect(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
400405
assert(sep == rest); /* must exhaust substring */
401406
assert(slow(m, ssp, sep, ssub, esub) == rest);
402407
{
403-
char *dp = dissect(m, ssp, sep, ssub, esub);
408+
const char *dp = dissect(m, ssp, sep, ssub, esub);
404409
(void)dp; /* avoid warning if assertions off */
405410
assert(dp == sep);
406411
}
@@ -438,7 +443,7 @@ dissect(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
438443
assert(OP(m->g->strip[esub]) == O_CH);
439444
}
440445
{
441-
char *dp = dissect(m, sp, rest, ssub, esub);
446+
const char *dp = dissect(m, sp, rest, ssub, esub);
442447
(void)dp; /* avoid warning if assertions off */
443448
assert(dp == rest);
444449
}
@@ -474,17 +479,17 @@ dissect(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
474479
/*
475480
- backref - figure out what matched what, figuring in back references
476481
*/
477-
static char * /* == stop (success) or NULL (failure) */
478-
backref(struct match *m, char *start, char *stop, sopno startst, sopno stopst,
479-
sopno lev, int rec) /* PLUS nesting level */
482+
static const char * /* == stop (success) or NULL (failure) */
483+
backref(struct match *m, const char *start, const char *stop, sopno startst,
484+
sopno stopst, sopno lev, int rec) /* PLUS nesting level */
480485
{
481486
int i;
482487
sopno ss; /* start sop of current subRE */
483-
char *sp; /* start of string matched by it */
488+
const char *sp; /* start of string matched by it */
484489
sopno ssub; /* start sop of subsubRE */
485490
sopno esub; /* end sop of subsubRE */
486-
char *ssp; /* start of string matched by subsubRE */
487-
char *dp;
491+
const char *ssp; /* start of string matched by subsubRE */
492+
const char *dp;
488493
size_t len;
489494
int hard;
490495
sop s;
@@ -674,18 +679,19 @@ backref(struct match *m, char *start, char *stop, sopno startst, sopno stopst,
674679
/*
675680
- fast - step through the string at top speed
676681
*/
677-
static char * /* where tentative match ended, or NULL */
678-
fast(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
682+
static const char * /* where tentative match ended, or NULL */
683+
fast(struct match *m, const char *start, const char *stop, sopno startst,
684+
sopno stopst)
679685
{
680686
states st = m->st;
681687
states fresh = m->fresh;
682688
states tmp = m->tmp;
683-
char *p = start;
689+
const char *p = start;
684690
int c = (start == m->beginp) ? OUT : *(start-1);
685691
int lastc; /* previous c */
686692
int flagch;
687693
int i;
688-
char *coldp; /* last p after which no match was underway */
694+
const char *coldp; /* last p after which no match was underway */
689695

690696
CLEAR(st);
691697
SET1(st, startst);
@@ -758,18 +764,19 @@ fast(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
758764
/*
759765
- slow - step through the string more deliberately
760766
*/
761-
static char * /* where it ended */
762-
slow(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
767+
static const char * /* where it ended */
768+
slow(struct match *m, const char *start, const char *stop, sopno startst,
769+
sopno stopst)
763770
{
764771
states st = m->st;
765772
states empty = m->empty;
766773
states tmp = m->tmp;
767-
char *p = start;
774+
const char *p = start;
768775
int c = (start == m->beginp) ? OUT : *(start-1);
769776
int lastc; /* previous c */
770777
int flagch;
771778
int i;
772-
char *matchp; /* last p at which a match ended */
779+
const char *matchp; /* last p at which a match ended */
773780

774781
AT("slow", start, stop, startst, stopst);
775782
CLEAR(st);

llvm/lib/Support/regexec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ llvm_regexec(const llvm_regex_t *preg, const char *string, size_t nmatch,
155155
eflags = GOODFLAGS(eflags);
156156

157157
if (g->nstates <= (long)(CHAR_BIT*sizeof(states1)) && !(eflags&REG_LARGE))
158-
return(smatcher(g, (char *)string, nmatch, pmatch, eflags));
158+
return(smatcher(g, string, nmatch, pmatch, eflags));
159159
else
160-
return(lmatcher(g, (char *)string, nmatch, pmatch, eflags));
160+
return(lmatcher(g, string, nmatch, pmatch, eflags));
161161
}

0 commit comments

Comments
 (0)