xref: /netbsd-src/external/apache2/llvm/dist/clang/utils/find-unused-diagnostics.sh (revision 7330f729ccf0bd976a06f95fad452fe774fc7fd1)
1*7330f729Sjoerg#!/usr/bin/env bash
2*7330f729Sjoerg#
3*7330f729Sjoerg# This script produces a list of all diagnostics that are defined
4*7330f729Sjoerg# in Diagnostic*.td files but not used in sources.
5*7330f729Sjoerg#
6*7330f729Sjoerg
7*7330f729Sjoerg# Gather all diagnostic identifiers from the .td files.
8*7330f729SjoergALL_DIAGS=$(grep -E --only-matching --no-filename '(err_|warn_|ext_|note_)[a-z_]+' ./include/clang/Basic/Diagnostic*.td)
9*7330f729Sjoerg
10*7330f729Sjoerg# Now look for all potential identifiers in the source files.
11*7330f729SjoergALL_SOURCES=$(find lib include tools utils -name \*.cpp -or -name \*.h)
12*7330f729SjoergDIAGS_IN_SOURCES=$(grep -E --only-matching --no-filename '(err_|warn_|ext_|note_)[a-z_]+' $ALL_SOURCES)
13*7330f729Sjoerg
14*7330f729Sjoerg# Print all diags that occur in the .td files but not in the source.
15*7330f729Sjoergcomm -23 <(sort -u <<< "$ALL_DIAGS") <(sort -u <<< "$DIAGS_IN_SOURCES")
16