Skip to content

Commit bc8f4a1

Browse files
authored
[NFC] [Support] Fix warning when build with clang-cl on Windows. (llvm#65387)
Add const qualifier to avoid warning "_cast from 'const char *' to 'char*' drops const qualifier [-Werror,-Wcast-qual]_" This will allow enable LLVM_ENABLE_WERROR when build with clang-cl on Windows. This is imported from openbsd/src@b817630 Also removed the gcc change for the cast-qual warning which is not needed with const qualifier added.
1 parent e3298bb commit bc8f4a1

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

llvm/lib/Support/regcomp.c

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ static struct cname {
190190
* other clumsinesses
191191
*/
192192
struct parse {
193-
char *next; /* next character in RE */
194-
char *end; /* end of string (-> NUL normally) */
193+
const char *next; /* next character in RE */
194+
const char *end; /* end of string (-> NUL normally) */
195195
int error; /* has an error been seen? */
196196
sop *strip; /* malloced strip */
197197
sopno ssize; /* malloced strip size (allocated) */
@@ -329,15 +329,7 @@ llvm_regcomp(llvm_regex_t *preg, const char *pattern, int cflags)
329329

330330
/* set things up */
331331
p->g = g;
332-
/* suppress warning from the following explicit cast. */
333-
#ifdef __GNUC__
334-
#pragma GCC diagnostic push
335-
#pragma GCC diagnostic ignored "-Wcast-qual"
336-
#endif /* __GNUC__ */
337-
p->next = (char *)pattern; /* convenience; we do not modify it */
338-
#ifdef __GNUC__
339-
#pragma GCC diagnostic pop
340-
#endif /* __GNUC__ */
332+
p->next = pattern;
341333
p->end = p->next + len;
342334
p->error = 0;
343335
p->ncsalloc = 0;
@@ -948,7 +940,7 @@ p_b_term(struct parse *p, cset *cs)
948940
static void
949941
p_b_cclass(struct parse *p, cset *cs)
950942
{
951-
char *sp = p->next;
943+
const char *sp = p->next;
952944
struct cclass *cp;
953945
size_t len;
954946
const char *u;
@@ -1012,7 +1004,7 @@ static char /* value of collating element */
10121004
p_b_coll_elem(struct parse *p,
10131005
int endc) /* name ended by endc,']' */
10141006
{
1015-
char *sp = p->next;
1007+
const char *sp = p->next;
10161008
struct cname *cp;
10171009
size_t len;
10181010

@@ -1056,8 +1048,8 @@ othercase(int ch)
10561048
static void
10571049
bothcases(struct parse *p, int ch)
10581050
{
1059-
char *oldnext = p->next;
1060-
char *oldend = p->end;
1051+
const char *oldnext = p->next;
1052+
const char *oldend = p->end;
10611053
char bracket[3];
10621054

10631055
ch = (uch)ch;
@@ -1098,16 +1090,12 @@ ordinary(struct parse *p, int ch)
10981090
static void
10991091
nonnewline(struct parse *p)
11001092
{
1101-
char *oldnext = p->next;
1102-
char *oldend = p->end;
1103-
char bracket[4];
1093+
const char *oldnext = p->next;
1094+
const char *oldend = p->end;
1095+
static const char bracket[4] = {'^', '\n', ']', '\0'};
11041096

11051097
p->next = bracket;
11061098
p->end = bracket+3;
1107-
bracket[0] = '^';
1108-
bracket[1] = '\n';
1109-
bracket[2] = ']';
1110-
bracket[3] = '\0';
11111099
p_bracket(p);
11121100
assert(p->next == bracket+3);
11131101
p->next = oldnext;

0 commit comments

Comments
 (0)