[llvm] [NFC] [Support] Fix warning when build with clang-cl on Windows. (PR #65387)
Xiang Li via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 5 12:06:29 PDT 2023
https://github.com/python3kgae updated https://github.com/llvm/llvm-project/pull/65387:
>From 2d68f51827af3266a43b15da6227122d77f9bc55 Mon Sep 17 00:00:00 2001
From: Xiang Li <python3kgae at outlook.com>
Date: Tue, 5 Sep 2023 13:04:42 -0400
Subject: [PATCH 1/2] [NFC] [Support] Fix warning when build with clang-cl on
Windows.
Add const qualifier to avoid "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.
---
llvm/lib/Support/regcomp.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/llvm/lib/Support/regcomp.c b/llvm/lib/Support/regcomp.c
index 4e9082cec456961..e79c2e5591c0b88 100644
--- a/llvm/lib/Support/regcomp.c
+++ b/llvm/lib/Support/regcomp.c
@@ -190,8 +190,8 @@ static struct cname {
* other clumsinesses
*/
struct parse {
- char *next; /* next character in RE */
- char *end; /* end of string (-> NUL normally) */
+ const char *next; /* next character in RE */
+ const char *end; /* end of string (-> NUL normally) */
int error; /* has an error been seen? */
sop *strip; /* malloced strip */
sopno ssize; /* malloced strip size (allocated) */
@@ -334,7 +334,7 @@ llvm_regcomp(llvm_regex_t *preg, const char *pattern, int cflags)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-qual"
#endif /* __GNUC__ */
- p->next = (char *)pattern; /* convenience; we do not modify it */
+ p->next = pattern; /* convenience; we do not modify it */
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif /* __GNUC__ */
@@ -948,7 +948,7 @@ p_b_term(struct parse *p, cset *cs)
static void
p_b_cclass(struct parse *p, cset *cs)
{
- char *sp = p->next;
+ const char *sp = p->next;
struct cclass *cp;
size_t len;
const char *u;
@@ -1012,7 +1012,7 @@ static char /* value of collating element */
p_b_coll_elem(struct parse *p,
int endc) /* name ended by endc,']' */
{
- char *sp = p->next;
+ const char *sp = p->next;
struct cname *cp;
size_t len;
@@ -1056,8 +1056,8 @@ othercase(int ch)
static void
bothcases(struct parse *p, int ch)
{
- char *oldnext = p->next;
- char *oldend = p->end;
+ const char *oldnext = p->next;
+ const char *oldend = p->end;
char bracket[3];
ch = (uch)ch;
@@ -1098,8 +1098,8 @@ ordinary(struct parse *p, int ch)
static void
nonnewline(struct parse *p)
{
- char *oldnext = p->next;
- char *oldend = p->end;
+ const char *oldnext = p->next;
+ const char *oldend = p->end;
char bracket[4];
p->next = bracket;
>From 4fff4d10889b279ddb41765f7bb5040f76366af2 Mon Sep 17 00:00:00 2001
From: Xiang Li <python3kgae at outlook.com>
Date: Tue, 5 Sep 2023 15:06:12 -0400
Subject: [PATCH 2/2] Remove the gcc change for the cast-qual warning.
---
llvm/lib/Support/regcomp.c | 8 --------
1 file changed, 8 deletions(-)
diff --git a/llvm/lib/Support/regcomp.c b/llvm/lib/Support/regcomp.c
index e79c2e5591c0b88..49cd372369e45a4 100644
--- a/llvm/lib/Support/regcomp.c
+++ b/llvm/lib/Support/regcomp.c
@@ -329,15 +329,7 @@ llvm_regcomp(llvm_regex_t *preg, const char *pattern, int cflags)
/* set things up */
p->g = g;
- /* suppress warning from the following explicit cast. */
-#ifdef __GNUC__
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wcast-qual"
-#endif /* __GNUC__ */
p->next = pattern; /* convenience; we do not modify it */
-#ifdef __GNUC__
-#pragma GCC diagnostic pop
-#endif /* __GNUC__ */
p->end = p->next + len;
p->error = 0;
p->ncsalloc = 0;
More information about the llvm-commits
mailing list