Skip to content

Conversation

@jurahul
Copy link
Contributor

@jurahul jurahul commented May 20, 2025

Apply clang-format to regcomp.c since it's not conformant and leads to clang-format failures when doing individual changes to this file (for example in #140758). File generated by running clang-format -i regcomp.c

@jurahul jurahul marked this pull request as ready for review May 21, 2025 00:30
@jurahul jurahul requested a review from kazutakahirata May 21, 2025 00:30
@llvmbot
Copy link
Member

llvmbot commented May 21, 2025

@llvm/pr-subscribers-llvm-support

Author: Rahul Joshi (jurahul)

Changes

Apply clang-format to regcomp.c since it's not conformant and leads to clang-format failures when doing individual changes to this file (for example in #140758)


Patch is 72.22 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/140769.diff

1 Files Affected:

  • (modified) llvm/lib/Support/regcomp.c (+1270-1336)
diff --git a/llvm/lib/Support/regcomp.c b/llvm/lib/Support/regcomp.c
index daa41eb4912ef..1ffb92f52dfd8 100644
--- a/llvm/lib/Support/regcomp.c
+++ b/llvm/lib/Support/regcomp.c
@@ -35,172 +35,166 @@
  *	@(#)regcomp.c	8.5 (Berkeley) 3/20/94
  */
 
-#include <sys/types.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
+#include "regex_impl.h"
 #include <ctype.h>
 #include <limits.h>
+#include <stdint.h>
+#include <stdio.h>
 #include <stdlib.h>
-#include "regex_impl.h"
+#include <string.h>
+#include <sys/types.h>
 
-#include "regutils.h"
 #include "regex2.h"
+#include "regutils.h"
 
 #include "llvm/Config/config.h"
 #include "llvm/Support/Compiler.h"
 
 /* character-class table */
 static struct cclass {
-	const char *name;
-	const char *chars;
-	const char *multis;
+  const char *name;
+  const char *chars;
+  const char *multis;
 } cclasses[] = {
-	{ "alnum",	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
-0123456789",				""} ,
-	{ "alpha",	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
-					""} ,
-	{ "blank",	" \t",		""} ,
-	{ "cntrl",	"\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\
-\25\26\27\30\31\32\33\34\35\36\37\177",	""} ,
-	{ "digit",	"0123456789",	""} ,
-	{ "graph",	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
+    {"alnum", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
+0123456789",
+     ""},
+    {"alpha", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", ""},
+    {"blank", " \t", ""},
+    {"cntrl", "\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\
+\25\26\27\30\31\32\33\34\35\36\37\177",
+     ""},
+    {"digit", "0123456789", ""},
+    {"graph", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
 0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
-					""} ,
-	{ "lower",	"abcdefghijklmnopqrstuvwxyz",
-					""} ,
-	{ "print",	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
+     ""},
+    {"lower", "abcdefghijklmnopqrstuvwxyz", ""},
+    {"print", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
 0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ",
-					""} ,
-	{ "punct",	"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
-					""} ,
-	{ "space",	"\t\n\v\f\r ",	""} ,
-	{ "upper",	"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
-					""} ,
-	{ "xdigit",	"0123456789ABCDEFabcdef",
-					""} ,
-	{ NULL,		0,		"" }
-};
+     ""},
+    {"punct", "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", ""},
+    {"space", "\t\n\v\f\r ", ""},
+    {"upper", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", ""},
+    {"xdigit", "0123456789ABCDEFabcdef", ""},
+    {NULL, 0, ""}};
 
 /* character-name table */
 static struct cname {
-	const char *name;
-	char code;
-} cnames[] = {
-	{ "NUL",			'\0' },
-	{ "SOH",			'\001' },
-	{ "STX",			'\002' },
-	{ "ETX",			'\003' },
-	{ "EOT",			'\004' },
-	{ "ENQ",			'\005' },
-	{ "ACK",			'\006' },
-	{ "BEL",			'\007' },
-	{ "alert",			'\007' },
-	{ "BS",				'\010' },
-	{ "backspace",			'\b' },
-	{ "HT",				'\011' },
-	{ "tab",			'\t' },
-	{ "LF",				'\012' },
-	{ "newline",			'\n' },
-	{ "VT",				'\013' },
-	{ "vertical-tab",		'\v' },
-	{ "FF",				'\014' },
-	{ "form-feed",			'\f' },
-	{ "CR",				'\015' },
-	{ "carriage-return",		'\r' },
-	{ "SO",				'\016' },
-	{ "SI",				'\017' },
-	{ "DLE",			'\020' },
-	{ "DC1",			'\021' },
-	{ "DC2",			'\022' },
-	{ "DC3",			'\023' },
-	{ "DC4",			'\024' },
-	{ "NAK",			'\025' },
-	{ "SYN",			'\026' },
-	{ "ETB",			'\027' },
-	{ "CAN",			'\030' },
-	{ "EM",				'\031' },
-	{ "SUB",			'\032' },
-	{ "ESC",			'\033' },
-	{ "IS4",			'\034' },
-	{ "FS",				'\034' },
-	{ "IS3",			'\035' },
-	{ "GS",				'\035' },
-	{ "IS2",			'\036' },
-	{ "RS",				'\036' },
-	{ "IS1",			'\037' },
-	{ "US",				'\037' },
-	{ "space",			' ' },
-	{ "exclamation-mark",		'!' },
-	{ "quotation-mark",		'"' },
-	{ "number-sign",		'#' },
-	{ "dollar-sign",		'$' },
-	{ "percent-sign",		'%' },
-	{ "ampersand",			'&' },
-	{ "apostrophe",			'\'' },
-	{ "left-parenthesis",		'(' },
-	{ "right-parenthesis",		')' },
-	{ "asterisk",			'*' },
-	{ "plus-sign",			'+' },
-	{ "comma",			',' },
-	{ "hyphen",			'-' },
-	{ "hyphen-minus",		'-' },
-	{ "period",			'.' },
-	{ "full-stop",			'.' },
-	{ "slash",			'/' },
-	{ "solidus",			'/' },
-	{ "zero",			'0' },
-	{ "one",			'1' },
-	{ "two",			'2' },
-	{ "three",			'3' },
-	{ "four",			'4' },
-	{ "five",			'5' },
-	{ "six",			'6' },
-	{ "seven",			'7' },
-	{ "eight",			'8' },
-	{ "nine",			'9' },
-	{ "colon",			':' },
-	{ "semicolon",			';' },
-	{ "less-than-sign",		'<' },
-	{ "equals-sign",		'=' },
-	{ "greater-than-sign",		'>' },
-	{ "question-mark",		'?' },
-	{ "commercial-at",		'@' },
-	{ "left-square-bracket",	'[' },
-	{ "backslash",			'\\' },
-	{ "reverse-solidus",		'\\' },
-	{ "right-square-bracket",	']' },
-	{ "circumflex",			'^' },
-	{ "circumflex-accent",		'^' },
-	{ "underscore",			'_' },
-	{ "low-line",			'_' },
-	{ "grave-accent",		'`' },
-	{ "left-brace",			'{' },
-	{ "left-curly-bracket",		'{' },
-	{ "vertical-line",		'|' },
-	{ "right-brace",		'}' },
-	{ "right-curly-bracket",	'}' },
-	{ "tilde",			'~' },
-	{ "DEL",			'\177' },
-	{ NULL,				0 }
-};
+  const char *name;
+  char code;
+} cnames[] = {{"NUL", '\0'},
+              {"SOH", '\001'},
+              {"STX", '\002'},
+              {"ETX", '\003'},
+              {"EOT", '\004'},
+              {"ENQ", '\005'},
+              {"ACK", '\006'},
+              {"BEL", '\007'},
+              {"alert", '\007'},
+              {"BS", '\010'},
+              {"backspace", '\b'},
+              {"HT", '\011'},
+              {"tab", '\t'},
+              {"LF", '\012'},
+              {"newline", '\n'},
+              {"VT", '\013'},
+              {"vertical-tab", '\v'},
+              {"FF", '\014'},
+              {"form-feed", '\f'},
+              {"CR", '\015'},
+              {"carriage-return", '\r'},
+              {"SO", '\016'},
+              {"SI", '\017'},
+              {"DLE", '\020'},
+              {"DC1", '\021'},
+              {"DC2", '\022'},
+              {"DC3", '\023'},
+              {"DC4", '\024'},
+              {"NAK", '\025'},
+              {"SYN", '\026'},
+              {"ETB", '\027'},
+              {"CAN", '\030'},
+              {"EM", '\031'},
+              {"SUB", '\032'},
+              {"ESC", '\033'},
+              {"IS4", '\034'},
+              {"FS", '\034'},
+              {"IS3", '\035'},
+              {"GS", '\035'},
+              {"IS2", '\036'},
+              {"RS", '\036'},
+              {"IS1", '\037'},
+              {"US", '\037'},
+              {"space", ' '},
+              {"exclamation-mark", '!'},
+              {"quotation-mark", '"'},
+              {"number-sign", '#'},
+              {"dollar-sign", '$'},
+              {"percent-sign", '%'},
+              {"ampersand", '&'},
+              {"apostrophe", '\''},
+              {"left-parenthesis", '('},
+              {"right-parenthesis", ')'},
+              {"asterisk", '*'},
+              {"plus-sign", '+'},
+              {"comma", ','},
+              {"hyphen", '-'},
+              {"hyphen-minus", '-'},
+              {"period", '.'},
+              {"full-stop", '.'},
+              {"slash", '/'},
+              {"solidus", '/'},
+              {"zero", '0'},
+              {"one", '1'},
+              {"two", '2'},
+              {"three", '3'},
+              {"four", '4'},
+              {"five", '5'},
+              {"six", '6'},
+              {"seven", '7'},
+              {"eight", '8'},
+              {"nine", '9'},
+              {"colon", ':'},
+              {"semicolon", ';'},
+              {"less-than-sign", '<'},
+              {"equals-sign", '='},
+              {"greater-than-sign", '>'},
+              {"question-mark", '?'},
+              {"commercial-at", '@'},
+              {"left-square-bracket", '['},
+              {"backslash", '\\'},
+              {"reverse-solidus", '\\'},
+              {"right-square-bracket", ']'},
+              {"circumflex", '^'},
+              {"circumflex-accent", '^'},
+              {"underscore", '_'},
+              {"low-line", '_'},
+              {"grave-accent", '`'},
+              {"left-brace", '{'},
+              {"left-curly-bracket", '{'},
+              {"vertical-line", '|'},
+              {"right-brace", '}'},
+              {"right-curly-bracket", '}'},
+              {"tilde", '~'},
+              {"DEL", '\177'},
+              {NULL, 0}};
 
 /*
  * parse structure, passed up and down to avoid global variables and
  * other clumsinesses
  */
 struct parse {
-	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) */
-	sopno slen;		/* malloced strip length (used) */
-	int ncsalloc;		/* number of csets allocated */
-	struct re_guts *g;
-#	define	NPAREN	10	/* we need to remember () 1-9 for back refs */
-	sopno pbegin[NPAREN];	/* -> ( ([0] unused) */
-	sopno pend[NPAREN];	/* -> ) ([0] unused) */
+  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) */
+  sopno slen;       /* malloced strip length (used) */
+  int ncsalloc;     /* number of csets allocated */
+  struct re_guts *g;
+#define NPAREN 10       /* we need to remember () 1-9 for back refs */
+  sopno pbegin[NPAREN]; /* -> ( ([0] unused) */
+  sopno pend[NPAREN];   /* -> ) ([0] unused) */
 };
 
 static void p_ere(struct parse *, int);
@@ -241,378 +235,373 @@ static void stripsnug(struct parse *, struct re_guts *);
 static void findmust(struct parse *, struct re_guts *);
 static sopno pluscount(struct parse *, struct re_guts *);
 
-static char nuls[10];		/* place to point scanner in event of error */
+static char nuls[10]; /* place to point scanner in event of error */
 
 /*
  * macros for use with parse structure
  * BEWARE:  these know that the parse structure is named `p' !!!
  */
-#define	PEEK()	(*p->next)
-#define	PEEK2()	(*(p->next+1))
-#define	MORE()	(p->end - p->next > 0)
-#define	MORE2()	(p->end - p->next > 1)
-#define	SEE(c)	(MORE() && PEEK() == (c))
-#define	SEETWO(a, b)	(MORE2() && PEEK() == (a) && PEEK2() == (b))
-#define	EAT(c)	((SEE(c)) ? (NEXT(), 1) : 0)
-#define	EATTWO(a, b)	((SEETWO(a, b)) ? (NEXT2(), 1) : 0)
-#define	NEXT()	(p->next++)
-#define	NEXT2()	(p->next += 2)
-#define	NEXTn(n)	(p->next += (n))
-#define	GETNEXT()	(*p->next++)
-#define	SETERROR(e)	seterr(p, (e))
-#define	REQUIRE(co, e)	(void)((co) || SETERROR(e))
-#define	MUSTSEE(c, e)	(REQUIRE(MORE() && PEEK() == (c), e))
-#define	MUSTEAT(c, e)	(REQUIRE(MORE() && GETNEXT() == (c), e))
-#define	MUSTNOTSEE(c, e)	(REQUIRE(!MORE() || PEEK() != (c), e))
-#define	EMIT(op, sopnd)	doemit(p, (sop)(op), (size_t)(sopnd))
-#define	INSERT(op, pos)	doinsert(p, (sop)(op), HERE()-(pos)+1, pos)
-#define	AHEAD(pos)		dofwd(p, pos, HERE()-(pos))
-#define	ASTERN(sop, pos)	EMIT(sop, HERE()-pos)
-#define	HERE()		(p->slen)
-#define	THERE()		(p->slen - 1)
-#define	THERETHERE()	(p->slen - 2)
-#define	DROP(n)	(p->slen -= (n))
-
-#ifdef	_POSIX2_RE_DUP_MAX
-#define	DUPMAX	_POSIX2_RE_DUP_MAX
+#define PEEK() (*p->next)
+#define PEEK2() (*(p->next + 1))
+#define MORE() (p->end - p->next > 0)
+#define MORE2() (p->end - p->next > 1)
+#define SEE(c) (MORE() && PEEK() == (c))
+#define SEETWO(a, b) (MORE2() && PEEK() == (a) && PEEK2() == (b))
+#define EAT(c) ((SEE(c)) ? (NEXT(), 1) : 0)
+#define EATTWO(a, b) ((SEETWO(a, b)) ? (NEXT2(), 1) : 0)
+#define NEXT() (p->next++)
+#define NEXT2() (p->next += 2)
+#define NEXTn(n) (p->next += (n))
+#define GETNEXT() (*p->next++)
+#define SETERROR(e) seterr(p, (e))
+#define REQUIRE(co, e) (void)((co) || SETERROR(e))
+#define MUSTSEE(c, e) (REQUIRE(MORE() && PEEK() == (c), e))
+#define MUSTEAT(c, e) (REQUIRE(MORE() && GETNEXT() == (c), e))
+#define MUSTNOTSEE(c, e) (REQUIRE(!MORE() || PEEK() != (c), e))
+#define EMIT(op, sopnd) doemit(p, (sop)(op), (size_t)(sopnd))
+#define INSERT(op, pos) doinsert(p, (sop)(op), HERE() - (pos) + 1, pos)
+#define AHEAD(pos) dofwd(p, pos, HERE() - (pos))
+#define ASTERN(sop, pos) EMIT(sop, HERE() - pos)
+#define HERE() (p->slen)
+#define THERE() (p->slen - 1)
+#define THERETHERE() (p->slen - 2)
+#define DROP(n) (p->slen -= (n))
+
+#ifdef _POSIX2_RE_DUP_MAX
+#define DUPMAX _POSIX2_RE_DUP_MAX
 #else
-#define	DUPMAX	255
+#define DUPMAX 255
 #endif
 #define REGINFINITY (DUPMAX + 1)
 
 #ifndef NDEBUG
-static int never = 0;		/* for use in asserts; shuts lint up */
+static int never = 0; /* for use in asserts; shuts lint up */
 #else
-#define	never	0		/* some <assert.h>s have bugs too */
+#define never 0 /* some <assert.h>s have bugs too */
 #endif
 
 /*
  - llvm_regcomp - interface for parser and compilation
  */
-int				/* 0 success, otherwise REG_something */
-llvm_regcomp(llvm_regex_t *preg, const char *pattern, int cflags)
-{
-	struct parse pa;
-	struct re_guts *g;
-	struct parse *p = &pa;
-	int i;
-	size_t len;
+int /* 0 success, otherwise REG_something */
+llvm_regcomp(llvm_regex_t *preg, const char *pattern, int cflags) {
+  struct parse pa;
+  struct re_guts *g;
+  struct parse *p = &pa;
+  int i;
+  size_t len;
 #ifdef REDEBUG
-#	define	GOODFLAGS(f)	(f)
+#define GOODFLAGS(f) (f)
 #else
-#	define	GOODFLAGS(f)	((f)&~REG_DUMP)
+#define GOODFLAGS(f) ((f) & ~REG_DUMP)
 #endif
 
-	cflags = GOODFLAGS(cflags);
-	if ((cflags&REG_EXTENDED) && (cflags&REG_NOSPEC))
-		return(REG_INVARG);
-
-	if (cflags&REG_PEND) {
-		if (preg->re_endp < pattern)
-			return(REG_INVARG);
-		len = preg->re_endp - pattern;
-	} else
-		len = strlen((const char *)pattern);
-
-	/* do the mallocs early so failure handling is easy */
-	g = (struct re_guts *)malloc(sizeof(struct re_guts) +
-							(NC-1)*sizeof(cat_t));
-	if (g == NULL)
-		return(REG_ESPACE);
-	p->ssize = len/(size_t)2*(size_t)3 + (size_t)1;	/* ugh */
-	p->strip = (sop *)calloc(p->ssize, sizeof(sop));
-	p->slen = 0;
-	if (p->strip == NULL) {
-		free((char *)g);
-		return(REG_ESPACE);
-	}
-
-	/* set things up */
-	p->g = g;
-	p->next = pattern;
-	p->end = p->next + len;
-	p->error = 0;
-	p->ncsalloc = 0;
-	for (i = 0; i < NPAREN; i++) {
-		p->pbegin[i] = 0;
-		p->pend[i] = 0;
-	}
-	g->csetsize = NC;
-	g->sets = NULL;
-	g->setbits = NULL;
-	g->ncsets = 0;
-	g->cflags = cflags;
-	g->iflags = 0;
-	g->nbol = 0;
-	g->neol = 0;
-	g->must = NULL;
-	g->mlen = 0;
-	g->nsub = 0;
-	g->ncategories = 1;	/* category 0 is "everything else" */
-	g->categories = &g->catspace[-(CHAR_MIN)];
-	(void) memset((char *)g->catspace, 0, NC*sizeof(cat_t));
-	g->backrefs = 0;
-
-	/* do it */
-	EMIT(OEND, 0);
-	g->firststate = THERE();
-	if (cflags&REG_EXTENDED)
-		p_ere(p, OUT);
-	else if (cflags&REG_NOSPEC)
-		p_str(p);
-	else
-		p_bre(p, OUT, OUT);
-	EMIT(OEND, 0);
-	g->laststate = THERE();
-
-	/* tidy up loose ends and fill things in */
-	categorize(p, g);
-	stripsnug(p, g);
-	findmust(p, g);
-	g->nplus = pluscount(p, g);
-	g->magic = MAGIC2;
-	preg->re_nsub = g->nsub;
-	preg->re_g = g;
-	preg->re_magic = MAGIC1;
+  cflags = GOODFLAGS(cflags);
+  if ((cflags & REG_EXTENDED) && (cflags & REG_NOSPEC))
+    return (REG_INVARG);
+
+  if (cflags & REG_PEND) {
+    if (preg->re_endp < pattern)
+      return (REG_INVARG);
+    len = preg->re_endp - pattern;
+  } else
+    len = strlen((const char *)pattern);
+
+  /* do the mallocs early so failure handling is easy */
+  g = (struct re_guts *)malloc(sizeof(struct re_guts) +
+                               (NC - 1) * sizeof(cat_t));
+  if (g == NULL)
+    return (REG_ESPACE);
+  p->ssize = len / (size_t)2 * (size_t)3 + (size_t)1; /* ugh */
+  p->strip = (sop *)calloc(p->ssize, sizeof(sop));
+  p->slen = 0;
+  if (p->strip == NULL) {
+    free((char *)g);
+    return (REG_ESPACE);
+  }
+
+  /* set things up */
+  p->g = g;
+  p->next = pattern;
+  p->end = p->next + len;
+  p->error = 0;
+  p->ncsalloc = 0;
+  for (i = 0; i < NPAREN; i++) {
+    p->pbegin[i] = 0;
+    p->pend[i] = 0;
+  }
+  g->csetsize = NC;
+  g->sets = NULL;
+  g->setbits = NULL;
+  g->ncsets = 0;
+  g->cflags = cflags;
+  g->iflags = 0;
+  g->nbol = 0;
+  g->neol = 0;
+  g->must = NULL;
+  g->mlen = 0;
+  g->nsub = 0;
+  g->ncategories = 1; /* category 0 is "everything else" */
+  g->categories = &g->catspace[-(CHAR_MIN)];
+  (void)memset((char *)g->catspace, 0, NC * sizeof(cat_t));
+  g->backrefs = 0;
+
+  /* do it */
+  EMIT(OEND, 0);
+  g->firststate = THERE();
+  if (cflags & REG_EXTENDED)
+    p_ere(p, OUT);
+  else if (cflags & REG_NOSPEC)
+    p_str(p);
+  else
+    p_bre(p, OUT, OUT);
+  EMIT(OEND, 0);
+  g->laststate = THERE();
+
+  /* tidy up loose ends and fill things in */
+  categorize(p, g);
+  stripsnug(p, g);
+  findmust(p, g);
+  g->nplus = pluscount(p, g);
+  g->magic = MAGIC2;
+  preg->re_nsub = g->nsub;
+  preg->re_g = g;
+  preg->re_magic = MAGIC1;
 #ifndef REDEBUG
-	/* not debugging, so can't rely on the assert() in llvm_regexec() */
-	if (g->iflags&REGEX_BAD)
-		SETERROR(REG_ASSERT);
+  /* not debugging, so can't rely on the assert() in llvm_regexec() */
+  if (g->iflags & REGEX_BAD)
+    SETERROR(REG_ASSERT);
 #endif
 
-	/* win or lose, we're done */
-	if (p->error != 0)	/* lose */
-		llvm_regfree(preg);
-	return(p->error);
+  /* win or lose, we're done */
+  if (p->error != 0) /* lose */
+    llvm_regfree(preg);
+  return (p->error);
 }
 
 /*
  - p_ere - ERE parser top level, concatenation and alternation
  */
-static void
-p_ere(struct parse *p, int stop)	/* character this ERE should end at */
+static void p_ere(struct parse *p,
+                  int stop) /* character this ERE should end at */
 {
-	char c;
-	sopno prevback = 0;
-	sopno prevfwd = 0;
-	sopno conc;
-	int first = 1;		/* is this the first alternative? */
-
-	for (;;) {
-		/* do a bunch of concatenated expressions */
-		conc = HERE();
-		while (MORE() && (c = PEEK()) != '|' && c != stop)
-			p_ere_exp(p);
-		REQUIRE(HERE() != conc, REG_EMPTY);	/* require nonempty */
-
-		if (!EAT('|'))
-			break;		/* NOTE BREAK OUT */
-
-		if (first) {
-			INSERT(OCH_, conc);	/* offset is wrong */
-			prevfwd = conc;
-			prevback = conc;
-			first = 0;
-		}
-		ASTERN(OOR1, prevback);
-		prevback = THERE();
-		AHEAD(prevfwd);			/* fix previous offset */
-		prevfwd = HERE();
-		EMIT(OOR2, 0);			/* offset is very wrong */
-	}
-
-	if (!first) {		/* tail-end fixups */
-		AHEAD(prevfwd);
-		ASTERN(O_CH, prevback);
-	}
-
-	assert(!MORE() || SEE(stop));
+  char c;
+  sopno prevback = 0;
+  sopno prevfwd = 0;
+  sopno conc;
+  int first = 1; /* is this the first alternative? */
+
+  for (;;) {
+    /* do a bunch of concatenated expressions */
+    conc = HERE();
+    while (MORE() && (c = PEEK()) != '|' && c != stop)
+      p_ere_exp(p);
+    REQUIRE(HERE() != conc, REG_EMPTY); /* require nonempty */
+
+    if (!EAT('|'))
+      break; /* NOTE BREAK OUT */
+
+    if (first) {
+      INSERT(OCH_, conc); /* offset is wrong */
+      prevfwd = conc;
+      prevback = conc;
+      first = 0;
+    }
+    ASTERN(OOR1, prevback);
+    prevback = THERE();
+    AHEAD(prevfwd); /* fix previous offset */
+    prevfwd = HERE();
+    EMIT(OOR2, 0); /* offset is very wrong */
+  }
+
+  if (!first) { /* tail-end fixups */
+    AHEAD(prevfwd);
+    ASTERN(O_CH, prevback);
+  }
+
+  assert(!MORE() || SEE(stop));
 }
 
 /*
  - p_ere_exp - parse one subERE, an atom possibly followed by a repetition op
  */
-static void
-p_ere_exp(struct parse *p)
-{
-	char c;
-	sopno pos;
-	int count;
-	int count2;
-	int backrefnum;
-	sopno subno;
-	int wascaret = 0;
-
-	assert(MORE());		/* caller should have ensured this */
-	c = GETNEXT();
-
-	pos = HERE();
-	switch (c) {
-	case '(':
-		REQUIRE(MORE(), REG_EPAREN);
-		p->g->nsub++;
-		subno = p->g->nsub;
-		if (subno < NPAREN)
-			p->pbegin[subno] = HERE();
-		EMIT(OLPAREN, subno);
-		if (!SEE(')'))
-			p_ere(p, ')');
-		if (subno < NPAREN) {
-			p->pend[subno] = HERE();
-			assert(p->pend[subno] != 0);
-		}
-		EMIT(ORPAREN, subno);
-		MUSTEAT(')', REG_EPAREN);
-		break;
+static void p_ere_exp(struct parse *p) {
+  char c;
+  sopno pos;
+  int count;
+  int count2;
+  int backrefnum;
+  sopno subno;
+  int wascaret = 0;
+
+  assert(MORE()); /* caller should have ensured this */
+  c = GETNEXT();
+
+  pos = HERE();
+  switch (c) {
+  case '(':
+    REQUIRE(MORE(), REG_EPAREN);
+    p->g->nsub++;
+    subno = p->g->nsub;
+    if (subno < NPAREN)
+      p->pbegin[subno] = HERE();
+    EMIT(OLPAREN, s...
[truncated]

@jurahul jurahul requested a review from nikic May 21, 2025 00:31
@jurahul
Copy link
Contributor Author

jurahul commented May 21, 2025

I don't know what's our policy for changes like this, so tagging @nikic as well.

Copy link
Contributor

@kazutakahirata kazutakahirata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@jurahul jurahul merged commit 2cf6099 into llvm:main May 21, 2025
15 checks passed
@jurahul jurahul deleted the clang_format_regcomp_c branch May 21, 2025 13:24
@nikic
Copy link
Contributor

nikic commented May 22, 2025

I don't know what's our policy for changes like this, so tagging @nikic as well.

This is vendored 3rd party code, so usually we would avoid touching it as much as possible, to reduce divergence with upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants