[llvm] bc8f4a1 - [NFC] [Support] Fix warning when build with clang-cl on Windows. (#65387)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 12 13:55:37 PDT 2023


Author: Xiang Li
Date: 2023-09-12T16:55:34-04:00
New Revision: bc8f4a1b0a843df8ff22bd06e455f2c74e30a226

URL: https://github.com/llvm/llvm-project/commit/bc8f4a1b0a843df8ff22bd06e455f2c74e30a226
DIFF: https://github.com/llvm/llvm-project/commit/bc8f4a1b0a843df8ff22bd06e455f2c74e30a226.diff

LOG: [NFC] [Support] Fix warning when build with clang-cl on Windows. (#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 https://github.com/openbsd/src/commit/b81763002452802e4f7304ea60f121253bd94

Also removed the gcc change for the cast-qual warning which is not needed with const qualifier added.

Added: 
    

Modified: 
    llvm/lib/Support/regcomp.c

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/regcomp.c b/llvm/lib/Support/regcomp.c
index 4e9082cec456961..990aef32a396faf 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) */
@@ -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 = (char *)pattern;	/* convenience; we do not modify it */
-#ifdef __GNUC__
-#pragma GCC diagnostic pop
-#endif /* __GNUC__ */
+	p->next = pattern;
 	p->end = p->next + len;
 	p->error = 0;
 	p->ncsalloc = 0;
@@ -948,7 +940,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 +1004,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 +1048,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,16 +1090,12 @@ ordinary(struct parse *p, int ch)
 static void
 nonnewline(struct parse *p)
 {
-	char *oldnext = p->next;
-	char *oldend = p->end;
-	char bracket[4];
+	const char *oldnext = p->next;
+	const char *oldend = p->end;
+	static const char bracket[4] = {'^', '\n', ']', '\0'};
 
 	p->next = bracket;
 	p->end = bracket+3;
-	bracket[0] = '^';
-	bracket[1] = '\n';
-	bracket[2] = ']';
-	bracket[3] = '\0';
 	p_bracket(p);
 	assert(p->next == bracket+3);
 	p->next = oldnext;


        


More information about the llvm-commits mailing list