From: Martin Liska Date: Fri, 9 Dec 2016 10:15:33 +0000 (+0100) Subject: Escape non-printable chars in strings. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cdecc83f3e0c71790841630597c5ab1303c39742;p=gcc.git Escape non-printable chars in strings. * tree-pretty-print.c (pretty_print_string): Escape non-printable chars in strings. * gcc.dg/tree-ssa/dump-3.c: New test. From-SVN: r243477 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2ccc00fccae..eaada9bc71a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2016-12-09 Martin Liska + + * tree-pretty-print.c (pretty_print_string): Escape non-printable + chars in strings. + 2016-12-09 Jakub Jelinek PR tree-optimization/78726 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3ea10f27886..12a3c4b8901 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2016-12-09 Martin Liska + + * gcc.dg/tree-ssa/dump-3.c: New test. + 2016-12-09 Jakub Jelinek PR tree-optimization/78726 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/dump-3.c b/gcc/testsuite/gcc.dg/tree-ssa/dump-3.c new file mode 100644 index 00000000000..853312406b5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/dump-3.c @@ -0,0 +1,271 @@ +/* { dg-do compile } */ +/* { dg-options "-O0 -fdump-tree-optimized" } */ + +int main() +{ + char string_0[] = "\x0"; + char string_1[] = "\x1"; + char string_2[] = "\x2"; + char string_3[] = "\x3"; + char string_4[] = "\x4"; + char string_5[] = "\x5"; + char string_6[] = "\x6"; + char string_7[] = "\x7"; + char string_8[] = "\x8"; + char string_9[] = "\x9"; + char string_10[] = "\xa"; + char string_11[] = "\xb"; + char string_12[] = "\xc"; + char string_13[] = "\xd"; + char string_14[] = "\xe"; + char string_15[] = "\xf"; + char string_16[] = "\x10"; + char string_17[] = "\x11"; + char string_18[] = "\x12"; + char string_19[] = "\x13"; + char string_20[] = "\x14"; + char string_21[] = "\x15"; + char string_22[] = "\x16"; + char string_23[] = "\x17"; + char string_24[] = "\x18"; + char string_25[] = "\x19"; + char string_26[] = "\x1a"; + char string_27[] = "\x1b"; + char string_28[] = "\x1c"; + char string_29[] = "\x1d"; + char string_30[] = "\x1e"; + char string_31[] = "\x1f"; + char string_32[] = "\x20"; + char string_33[] = "\x21"; + char string_34[] = "\x22"; + char string_35[] = "\x23"; + char string_36[] = "\x24"; + char string_37[] = "\x25"; + char string_38[] = "\x26"; + char string_39[] = "\x27"; + char string_40[] = "\x28"; + char string_41[] = "\x29"; + char string_42[] = "\x2a"; + char string_43[] = "\x2b"; + char string_44[] = "\x2c"; + char string_45[] = "\x2d"; + char string_46[] = "\x2e"; + char string_47[] = "\x2f"; + char string_48[] = "\x30"; + char string_49[] = "\x31"; + char string_50[] = "\x32"; + char string_51[] = "\x33"; + char string_52[] = "\x34"; + char string_53[] = "\x35"; + char string_54[] = "\x36"; + char string_55[] = "\x37"; + char string_56[] = "\x38"; + char string_57[] = "\x39"; + char string_58[] = "\x3a"; + char string_59[] = "\x3b"; + char string_60[] = "\x3c"; + char string_61[] = "\x3d"; + char string_62[] = "\x3e"; + char string_63[] = "\x3f"; + char string_64[] = "\x40"; + char string_65[] = "\x41"; + char string_66[] = "\x42"; + char string_67[] = "\x43"; + char string_68[] = "\x44"; + char string_69[] = "\x45"; + char string_70[] = "\x46"; + char string_71[] = "\x47"; + char string_72[] = "\x48"; + char string_73[] = "\x49"; + char string_74[] = "\x4a"; + char string_75[] = "\x4b"; + char string_76[] = "\x4c"; + char string_77[] = "\x4d"; + char string_78[] = "\x4e"; + char string_79[] = "\x4f"; + char string_80[] = "\x50"; + char string_81[] = "\x51"; + char string_82[] = "\x52"; + char string_83[] = "\x53"; + char string_84[] = "\x54"; + char string_85[] = "\x55"; + char string_86[] = "\x56"; + char string_87[] = "\x57"; + char string_88[] = "\x58"; + char string_89[] = "\x59"; + char string_90[] = "\x5a"; + char string_91[] = "\x5b"; + char string_92[] = "\x5c"; + char string_93[] = "\x5d"; + char string_94[] = "\x5e"; + char string_95[] = "\x5f"; + char string_96[] = "\x60"; + char string_97[] = "\x61"; + char string_98[] = "\x62"; + char string_99[] = "\x63"; + char string_100[] = "\x64"; + char string_101[] = "\x65"; + char string_102[] = "\x66"; + char string_103[] = "\x67"; + char string_104[] = "\x68"; + char string_105[] = "\x69"; + char string_106[] = "\x6a"; + char string_107[] = "\x6b"; + char string_108[] = "\x6c"; + char string_109[] = "\x6d"; + char string_110[] = "\x6e"; + char string_111[] = "\x6f"; + char string_112[] = "\x70"; + char string_113[] = "\x71"; + char string_114[] = "\x72"; + char string_115[] = "\x73"; + char string_116[] = "\x74"; + char string_117[] = "\x75"; + char string_118[] = "\x76"; + char string_119[] = "\x77"; + char string_120[] = "\x78"; + char string_121[] = "\x79"; + char string_122[] = "\x7a"; + char string_123[] = "\x7b"; + char string_124[] = "\x7c"; + char string_125[] = "\x7d"; + char string_126[] = "\x7e"; + char string_127[] = "\x7f"; + char string_128[] = "\x80"; + char string_129[] = "\x81"; + char string_130[] = "\x82"; + char string_131[] = "\x83"; + char string_132[] = "\x84"; + char string_133[] = "\x85"; + char string_134[] = "\x86"; + char string_135[] = "\x87"; + char string_136[] = "\x88"; + char string_137[] = "\x89"; + char string_138[] = "\x8a"; + char string_139[] = "\x8b"; + char string_140[] = "\x8c"; + char string_141[] = "\x8d"; + char string_142[] = "\x8e"; + char string_143[] = "\x8f"; + char string_144[] = "\x90"; + char string_145[] = "\x91"; + char string_146[] = "\x92"; + char string_147[] = "\x93"; + char string_148[] = "\x94"; + char string_149[] = "\x95"; + char string_150[] = "\x96"; + char string_151[] = "\x97"; + char string_152[] = "\x98"; + char string_153[] = "\x99"; + char string_154[] = "\x9a"; + char string_155[] = "\x9b"; + char string_156[] = "\x9c"; + char string_157[] = "\x9d"; + char string_158[] = "\x9e"; + char string_159[] = "\x9f"; + char string_160[] = "\xa0"; + char string_161[] = "\xa1"; + char string_162[] = "\xa2"; + char string_163[] = "\xa3"; + char string_164[] = "\xa4"; + char string_165[] = "\xa5"; + char string_166[] = "\xa6"; + char string_167[] = "\xa7"; + char string_168[] = "\xa8"; + char string_169[] = "\xa9"; + char string_170[] = "\xaa"; + char string_171[] = "\xab"; + char string_172[] = "\xac"; + char string_173[] = "\xad"; + char string_174[] = "\xae"; + char string_175[] = "\xaf"; + char string_176[] = "\xb0"; + char string_177[] = "\xb1"; + char string_178[] = "\xb2"; + char string_179[] = "\xb3"; + char string_180[] = "\xb4"; + char string_181[] = "\xb5"; + char string_182[] = "\xb6"; + char string_183[] = "\xb7"; + char string_184[] = "\xb8"; + char string_185[] = "\xb9"; + char string_186[] = "\xba"; + char string_187[] = "\xbb"; + char string_188[] = "\xbc"; + char string_189[] = "\xbd"; + char string_190[] = "\xbe"; + char string_191[] = "\xbf"; + char string_192[] = "\xc0"; + char string_193[] = "\xc1"; + char string_194[] = "\xc2"; + char string_195[] = "\xc3"; + char string_196[] = "\xc4"; + char string_197[] = "\xc5"; + char string_198[] = "\xc6"; + char string_199[] = "\xc7"; + char string_200[] = "\xc8"; + char string_201[] = "\xc9"; + char string_202[] = "\xca"; + char string_203[] = "\xcb"; + char string_204[] = "\xcc"; + char string_205[] = "\xcd"; + char string_206[] = "\xce"; + char string_207[] = "\xcf"; + char string_208[] = "\xd0"; + char string_209[] = "\xd1"; + char string_210[] = "\xd2"; + char string_211[] = "\xd3"; + char string_212[] = "\xd4"; + char string_213[] = "\xd5"; + char string_214[] = "\xd6"; + char string_215[] = "\xd7"; + char string_216[] = "\xd8"; + char string_217[] = "\xd9"; + char string_218[] = "\xda"; + char string_219[] = "\xdb"; + char string_220[] = "\xdc"; + char string_221[] = "\xdd"; + char string_222[] = "\xde"; + char string_223[] = "\xdf"; + char string_224[] = "\xe0"; + char string_225[] = "\xe1"; + char string_226[] = "\xe2"; + char string_227[] = "\xe3"; + char string_228[] = "\xe4"; + char string_229[] = "\xe5"; + char string_230[] = "\xe6"; + char string_231[] = "\xe7"; + char string_232[] = "\xe8"; + char string_233[] = "\xe9"; + char string_234[] = "\xea"; + char string_235[] = "\xeb"; + char string_236[] = "\xec"; + char string_237[] = "\xed"; + char string_238[] = "\xee"; + char string_239[] = "\xef"; + char string_240[] = "\xf0"; + char string_241[] = "\xf1"; + char string_242[] = "\xf2"; + char string_243[] = "\xf3"; + char string_244[] = "\xf4"; + char string_245[] = "\xf5"; + char string_246[] = "\xf6"; + char string_247[] = "\xf7"; + char string_248[] = "\xf8"; + char string_249[] = "\xf9"; + char string_250[] = "\xfa"; + char string_251[] = "\xfb"; + char string_252[] = "\xfc"; + char string_253[] = "\xfd"; + char string_254[] = "\xfe"; + char string_255[] = "\xff"; + + return 0; +} + +/* { dg-final { scan-tree-dump "string_0 = \"\";" "optimized" } } */ +/* { dg-final { scan-tree-dump "string_4 = \"\\\\4\";" "optimized" } } */ +/* { dg-final { scan-tree-dump "string_28 = \"\\\\x1c\";" "optimized" } } */ +/* { dg-final { scan-tree-dump "string_51 = \"3\";" "optimized" } } */ +/* { dg-final { scan-tree-dump "string_255 = \"\\\\xff\";" "optimized" } } */ + diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c index 95db7100428..5b3e23e40f7 100644 --- a/gcc/tree-pretty-print.c +++ b/gcc/tree-pretty-print.c @@ -3869,7 +3869,14 @@ pretty_print_string (pretty_printer *pp, const char *str) break; default: - pp_character (pp, str[0]); + if (!ISPRINT (str[0])) + { + char buf[5]; + sprintf (buf, "\\x%x", (unsigned char)str[0]); + pp_string (pp, buf); + } + else + pp_character (pp, str[0]); break; } str++;