diff mbox

Fix PR bootstrap/35855: awk character classes.

Message ID 20100926060530.GK17516@gmx.de
State New
Headers show

Commit Message

Ralf Wildenhues Sept. 26, 2010, 6:05 a.m. UTC
Bootstrapped x86_64-unknown-linux-gnu, regtest is running.

OK for trunk?

OK for 4.5, 4.4, and 4.3 after a while, as the PR documents this to be a
4.3 regression?

Not using [:alpha:] or other character classes for two reasons:
- they would require the locale to be set/overridden correctly,
- not all awk implementations support them; at least, that is what I can
  infer from the gawk.info documentation of -W compat.

Thanks,
Ralf

Fix PR bootstrap/35855: awk character classes.

gcc/ChangeLog:
2010-09-26  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>

	PR bootstrap/35855
	* opt-functions.awk (BEGIN): New section.
	(alpha, ALPHA, numeric, alnum): New variables.
	(static_var, opt_sanitized_name): Use alnum instead of character
	classes, for non-C locale.
	* optc-gen.awk: Likewise.
	* opth-gen.awk: Likewise.

Comments

Ralf Wildenhues Oct. 10, 2010, 3:41 p.m. UTC | #1
Ping http://gcc.gnu.org/ml/gcc-patches/2010-09/msg02027.html

* Ralf Wildenhues wrote on Sun, Sep 26, 2010 at 08:05:30AM CEST:
> Bootstrapped x86_64-unknown-linux-gnu, regtest is running.
> 
> OK for trunk?
> 
> OK for 4.5, 4.4, and 4.3 after a while, as the PR documents this to be a
> 4.3 regression?
> 
> Not using [:alpha:] or other character classes for two reasons:
> - they would require the locale to be set/overridden correctly,
> - not all awk implementations support them; at least, that is what I can
>   infer from the gawk.info documentation of -W compat.

> Fix PR bootstrap/35855: awk character classes.
> 
> gcc/ChangeLog:
> 2010-09-26  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>
> 
> 	PR bootstrap/35855
> 	* opt-functions.awk (BEGIN): New section.
> 	(alpha, ALPHA, numeric, alnum): New variables.
> 	(static_var, opt_sanitized_name): Use alnum instead of character
> 	classes, for non-C locale.
> 	* optc-gen.awk: Likewise.
> 	* opth-gen.awk: Likewise.
Paolo Bonzini Oct. 11, 2010, 11:33 a.m. UTC | #2
On 10/10/2010 05:41 PM, Ralf Wildenhues wrote:
>> gcc/ChangeLog:
>> 2010-09-26  Ralf Wildenhues<Ralf.Wildenhues@gmx.de>
>>
>> 	PR bootstrap/35855
>> 	* opt-functions.awk (BEGIN): New section.
>> 	(alpha, ALPHA, numeric, alnum): New variables.

Can you call these lower, upper, digit, alnum?

Okay with this change.

Paolo
diff mbox

Patch

diff --git a/gcc/opt-functions.awk b/gcc/opt-functions.awk
index ed65d93..52ebf5e 100644
--- a/gcc/opt-functions.awk
+++ b/gcc/opt-functions.awk
@@ -19,6 +19,14 @@ 
 
 # Some common subroutines for use by opt[ch]-gen.awk.
 
+# Define some helpful character classes, for portability.
+BEGIN {
+	alpha = "abcdefghijklmnopqrstuvwxyz"
+	ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+	numeric = "0123456789"
+	alnum = alpha "" ALPHA "" numeric
+}
+
 # Return nonzero if FLAGS contains a flag matching REGEX.
 function flag_set_p(regex, flags)
 {
@@ -127,7 +135,7 @@  function static_var(name, flags)
 {
 	if (global_state_p(flags) || !needs_state_p(flags))
 		return ""
-	gsub ("[^A-Za-z0-9]", "_", name)
+	gsub ("[^" alnum "]", "_", name)
 	return "VAR_" name
 }
 
@@ -206,7 +214,7 @@  function opt_sanitized_name(name)
 {
 	if (name == "gdwarf+")
 		name = "gdwarfplus"
-	gsub ("[^A-Za-z0-9]", "_", name)
+	gsub ("[^" alnum "]", "_", name)
 	return name
 }
 
diff --git a/gcc/optc-gen.awk b/gcc/optc-gen.awk
index 4a146dd..beb14b8 100644
--- a/gcc/optc-gen.awk
+++ b/gcc/optc-gen.awk
@@ -127,7 +127,7 @@  print ""
 print "const char * const lang_names[] =\n{"
 for (i = 0; i < n_langs; i++) {
 	macros[i] = "CL_" langs[i]
-	gsub( "[^A-Za-z0-9_]", "X", macros[i] )
+	gsub( "[^" alnum "_]", "X", macros[i] )
 	s = substr("         ", length (macros[i]))
 	print "  " quote langs[i] quote ","
     }
diff --git a/gcc/opth-gen.awk b/gcc/opth-gen.awk
index 423328d..cd02e14 100644
--- a/gcc/opth-gen.awk
+++ b/gcc/opth-gen.awk
@@ -172,13 +172,13 @@  n_target_int = 0;
 n_target_other = 0;
 
 for (i = 0; i < n_target_save; i++) {
-	if (target_save_decl[i] ~ "^((un)?signed +)?int +[_a-zA-Z0-9]+$")
+	if (target_save_decl[i] ~ "^((un)?signed +)?int +[_" alnum "]+$")
 		var_target_int[n_target_int++] = target_save_decl[i];
 
-	else if (target_save_decl[i] ~ "^((un)?signed +)?short +[_a-zA-Z0-9]+$")
+	else if (target_save_decl[i] ~ "^((un)?signed +)?short +[_" alnum "]+$")
 		var_target_short[n_target_short++] = target_save_decl[i];
 
-	else if (target_save_decl[i] ~ "^((un)?signed +)?char +[_a-zA-Z0-9]+$")
+	else if (target_save_decl[i] ~ "^((un)?signed +)?char +[_ " alnum "]+$")
 		var_target_char[n_target_char++] = target_save_decl[i];
 
 	else
@@ -316,7 +316,7 @@  print ""
 
 for (i = 0; i < n_langs; i++) {
 	macros[i] = "CL_" langs[i]
-	gsub( "[^A-Za-z0-9_]", "X", macros[i] )
+	gsub( "[^" alnum "_]", "X", macros[i] )
 	s = substr("            ", length (macros[i]))
 	print "#define " macros[i] s " (1 << " i ")"
     }