From Phil Blundell:
[official-gcc.git] / contrib / warn_summary
blob21dfe99fa77d6705e19de315a2dc18a7fa8a1fff
1 #!/bin/sh
3 # This script parses the output of a gcc bootstrap when using warning
4 # flags and determines various statistics.
5 #
6 # usage: warn_summary [-llf] [-s stage] [-nosub|-ch|-cp|-f|-java]
7 # [-pass|-wpass] [file(s)]
9 # -llf
10 # Filter out long lines from the bootstap output before any other
11 # action. This is useful for systems with broken awks/greps which choke
12 # on long lines. It is not done by default as it sometimes slows things
13 # down.
15 # -s number
16 # Take warnings from stage "Number". Stage 0 means show warnings from
17 # before and after the gcc bootstrap directory. E.g. libraries, etc.
18 # This presupposes using "gcc -W*" for the stage1 compiler.
20 # -nosub
21 # Only show warnings from the gcc top level directory.
22 # -ch|-cp|-f|-java
23 # Only show warnings from the specified language subdirectory.
24 # These flags assume the output contains "Entering/Leaving" messages from
25 # gnu make. They override each other so only the last one takes effect.
27 # -pass
28 # Pass through the bootstrap output after filtering stage and subdir
29 # (useful for manual inspection.) This is all lines, not just warnings.
30 # -wpass
31 # Pass through only warnings from the bootstrap output after filtering
32 # stage and subdir.
34 # By Kaveh Ghazi (ghazi@caip.rutgers.edu) 12/13/97.
37 # Some awks choke on long lines, sed seems to do a better job.
38 # Truncate lines > 255 characters. RE '.\{255,\}' doesn't seem to work. :-(
39 # Only do this if -llf was specified, because it can really slow things down.
40 longLineFilter()
42 if test -z "$llf" ; then
43 cat $1
44 else
45 sed 's/^\(...............................................................................................................................................................................................................................................................\).*/\1/' $1
49 # This function does one of three things. It either passes through
50 # all warning data, or passes through gcc toplevel warnings, or passes
51 # through a particular subdirectory set of warnings.
52 subdirectoryFilter()
54 longLineFilter $1 | (
55 if test -z "$filter" ; then
56 # Pass through all lines.
57 cat
58 else
59 if test "$filter" = nosub ; then
60 # Omit all subdirectories.
61 $AWK 'BEGIN{t=1} ; /Entering directory.*\/gcc\/[a-z]/{t--} ; /Leaving directory.*\/gcc\/[a-z]/{t++} ; {if(t==1)print}'
62 else
63 # Pass through only subdir $filter.
64 $AWK "BEGIN {t=-1} ; /^cd $filter; make/{t=0} ; /Entering directory .*\/gcc\/$filter/{t++} ; /Leaving directory .*\/gcc\/$filter/{t--} ; {if(t==1)print}"
66 fi )
69 # This function displays all lines from stageN of the bootstrap. If
70 # stage==0, then show lines prior to stage1 and lines from after the last
71 # stage. I.e. utilities, libraries, etc.
72 stageNfilter()
74 if test "$stageN" -lt 1 ; then
75 # stage "0" means check everything *but* gcc.
76 $AWK "BEGIN{t=1} ; /^Bootstrapping the compiler/{t=0} ; /^Building runtime libraries/{t=1} ; {if(t==1)print}"
77 else
78 if test "$stageN" -eq 1 ; then
79 $AWK "/^Bootstrapping the compiler|^Building the C and C\+\+ compiler/{t=1} ; /stage$stageN/{t=0} ; {if(t==1)print}"
80 else
81 stageNminus1=`expr $stageN - 1`
82 $AWK "/stage$stageNminus1/{t=1} ; /stage$stageN/{t=0} ; {if(t==1)print}"
87 # This function displays lines containing warnings.
88 warningFilter()
90 grep ' warning: ' $1
93 # This function replaces `xxx' with `???', where xxx is usually some
94 # variable or function name. This allows similar warnings to be
95 # counted together when summarizing. However it avoids replacing
96 # certain C keywords which are known appear in various messages.
98 keywordFilter() {
99 sed 's/.*warning: //;
100 s/`\(int\)'"'"'/"\1"/g;
101 s/`\(long\)'"'"'/"\1"/g;
102 s/`\(char\)'"'"'/"\1"/g;
103 s/`\(inline\)'"'"'/"\1"/g;
104 s/`\(else\)'"'"'/"\1"/g;
105 s/`\(return\)'"'"'/"\1"/g;
106 s/`\(static\)'"'"'/"\1"/g;
107 s/`\(extern\)'"'"'/"\1"/g;
108 s/`\(const\)'"'"'/"\1"/g;
109 s/`\(noreturn\)'"'"'/"\1"/g;
110 s/`\(longjmp\)'"'"' or `\(vfork\)'"'"'/"\1" or "\2"/g;
111 s/`'"[^']*'/"'`???'"'/g;"'
112 s/.*format, .* arg (arg [0-9][0-9]*)/??? format, ??? arg (arg ???)/;
113 s/\([( ]\)arg [0-9][0-9]*\([) ]\)/\1arg ???\2/;
114 s/"\([^"]*\)"/`\1'"'"'/g'
118 # Start the main section.
120 usage="usage: `basename $0` [-llf] [-s stage] [-nosub|-ch|-cp|-f|-java] [-pass|-wpass] [file(s)]"
121 stageN=3
122 tmpfile=/tmp/tmp-warn.$$
124 # Remove $tmpfile on exit and various signals.
125 trap "rm -f $tmpfile" 0
126 trap "rm -f $tmpfile ; exit 1" 1 2 3 5 9 13 15
128 # Find a good awk.
129 if test -z "$AWK" ; then
130 for AWK in gawk nawk awk ; do
131 if type $AWK 2>&1 | grep 'not found' > /dev/null 2>&1 ; then
133 else
134 break
136 done
139 # Parse command line arguments.
140 while test -n "$1" ; do
141 case "$1" in
142 -llf) llf=1 ; shift ;;
143 -s) if test -z "$2"; then echo $usage; exit 1; fi; stageN="$2"; shift 2 ;;
144 -s*) stageN="`expr $1 : '-s\(.*\)'`" ; shift ;;
145 -nosub|-ch|-cp|-f|-java) filter="`expr $1 : '-\(.*\)'`" ; shift ;;
146 -pass) pass=1 ; shift ;;
147 -wpass) pass=w ; shift ;;
148 -*) echo $usage ; exit 1 ;;
149 *) break ;;
150 esac
151 done
153 # Check for a valid value of $stageN.
154 case "$stageN" in
155 [0-9]) ;;
156 *) echo "Stage <$stageN> must be in the range [0..9]." ; exit 1 ;;
157 esac
159 for file in "$@" ; do
161 subdirectoryFilter $file | stageNfilter > $tmpfile
163 # (Just) show me the warnings.
164 if test "$pass" != '' ; then
165 if test "$pass" = w ; then
166 warningFilter $tmpfile
167 else
168 cat $tmpfile
170 continue
173 if test -z "$filter" ; then
174 echo "Counting all warnings,"
175 else
176 if test "$filter" = nosub ; then
177 echo "Counting non-subdirectory warnings,"
178 else
179 echo "Counting warnings in the gcc/$filter subdirectory,"
182 count=`warningFilter $tmpfile | wc -l`
183 echo there are $count warnings in stage$stageN of this bootstrap.
185 echo
186 echo Number of warnings per file:
187 warningFilter $tmpfile | $AWK -F: '{print$1}' | sort | uniq -c | sort -nr
189 echo
190 echo Number of warning types:
191 warningFilter $tmpfile | keywordFilter | sort | uniq -c | sort -nr
193 done