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