aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-06-01 22:23:02 +0000
committerJordan Rose <jordan_rose@apple.com>2012-06-01 22:23:02 +0000
commit0a5ca3588df1cb9248ae299f7f5ac1434c0e4d8c (patch)
tree5feda31e2617692af9895cfa88a464e75585fced
parentb705489e8e23e7a5401a4bb0b528bf6bcede9d5c (diff)
[diagtool] Pull show-enabled back out for now.
Need to figure out how to get Frontend's warning parsing without bringing in all of Frontend. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157847 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--test/Misc/warning-flags-enabled.c27
-rw-r--r--tools/diagtool/CMakeLists.txt4
-rw-r--r--tools/diagtool/DiagnosticNames.cpp25
-rw-r--r--tools/diagtool/DiagnosticNames.h28
-rw-r--r--tools/diagtool/ListWarnings.cpp27
-rw-r--r--tools/diagtool/Makefile13
-rw-r--r--tools/diagtool/ShowEnabledWarnings.cpp148
7 files changed, 27 insertions, 245 deletions
diff --git a/test/Misc/warning-flags-enabled.c b/test/Misc/warning-flags-enabled.c
deleted file mode 100644
index 61e115e815..0000000000
--- a/test/Misc/warning-flags-enabled.c
+++ /dev/null
@@ -1,27 +0,0 @@
-// RUN: diagtool show-enabled 2>&1 | FileCheck %s
-//
-// This shows warnings which are on by default.
-// We just check a few to make sure it's doing something sensible.
-//
-// CHECK: warn_condition_is_assignment
-// CHECK: warn_null_arg
-// CHECK: warn_unterminated_string
-
-
-// RUN: diagtool show-enabled -Wno-everything 2>&1 | count 0
-
-
-// RUN: diagtool show-enabled -Wno-everything -Wobjc-root-class 2>&1 | FileCheck -check-prefix CHECK-WARN %s
-// RUN: diagtool show-enabled -Wno-everything -Werror=objc-root-class 2>&1 | FileCheck -check-prefix CHECK-ERROR %s
-// RUN: diagtool show-enabled -Wno-everything -Wfatal-errors=objc-root-class 2>&1 | FileCheck -check-prefix CHECK-FATAL %s
-//
-// CHECK-WARN: W warn_objc_root_class_missing [-Wobjc-root-class]
-// CHECK-ERROR: E warn_objc_root_class_missing [-Wobjc-root-class]
-// CHECK-FATAL: F warn_objc_root_class_missing [-Wobjc-root-class]
-
-// RUN: diagtool show-enabled --no-flags -Wno-everything -Wobjc-root-class 2>&1 | FileCheck -check-prefix CHECK-NO-FLAGS %s
-//
-// CHECK-NO-FLAGS-NOT: W
-// CHECK-NO-FLAGS-NOT: E
-// CHECK-NO-FLAGS-NOT: F
-// CHECK-NO-FLAGS: warn_objc_root_class_missing [-Wobjc-root-class]
diff --git a/tools/diagtool/CMakeLists.txt b/tools/diagtool/CMakeLists.txt
index 6263cb10a5..f1fd9de03b 100644
--- a/tools/diagtool/CMakeLists.txt
+++ b/tools/diagtool/CMakeLists.txt
@@ -1,21 +1,17 @@
set( LLVM_LINK_COMPONENTS
support
- ${LLVM_TARGETS_TO_BUILD}
)
set( LLVM_USED_LIBS
clangBasic
clangLex
clangSema
- clangFrontend
)
add_clang_executable(diagtool
diagtool_main.cpp
DiagTool.cpp
- DiagnosticNames.cpp
ListWarnings.cpp
- ShowEnabledWarnings.cpp
)
if(UNIX)
diff --git a/tools/diagtool/DiagnosticNames.cpp b/tools/diagtool/DiagnosticNames.cpp
deleted file mode 100644
index dd86c287ac..0000000000
--- a/tools/diagtool/DiagnosticNames.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-//===- DiagnosticNames.cpp - Defines a table of all builtin diagnostics ----==//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "DiagnosticNames.h"
-#include "clang/Basic/AllDiagnostics.h"
-
-using namespace clang;
-
-const diagtool::DiagnosticRecord diagtool::BuiltinDiagnostics[] = {
-#define DIAG_NAME_INDEX(ENUM) { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) },
-#include "clang/Basic/DiagnosticIndexName.inc"
-#undef DIAG_NAME_INDEX
- { 0, 0, 0 }
-};
-
-const size_t diagtool::BuiltinDiagnosticsCount =
- sizeof(diagtool::BuiltinDiagnostics) /
- sizeof(diagtool::BuiltinDiagnostics[0]) - 1;
-
diff --git a/tools/diagtool/DiagnosticNames.h b/tools/diagtool/DiagnosticNames.h
deleted file mode 100644
index ac1934aac1..0000000000
--- a/tools/diagtool/DiagnosticNames.h
+++ /dev/null
@@ -1,28 +0,0 @@
-//===- DiagnosticNames.h - Defines a table of all builtin diagnostics ------==//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/DataTypes.h"
-
-namespace diagtool {
- struct DiagnosticRecord {
- const char *NameStr;
- unsigned short DiagID;
- uint8_t NameLen;
-
- llvm::StringRef getName() const {
- return llvm::StringRef(NameStr, NameLen);
- }
- };
-
- extern const DiagnosticRecord BuiltinDiagnostics[];
- extern const size_t BuiltinDiagnosticsCount;
-
-} // end namespace diagtool
-
diff --git a/tools/diagtool/ListWarnings.cpp b/tools/diagtool/ListWarnings.cpp
index 6c59338eef..2bbeca8024 100644
--- a/tools/diagtool/ListWarnings.cpp
+++ b/tools/diagtool/ListWarnings.cpp
@@ -13,7 +13,6 @@
//===----------------------------------------------------------------------===//
#include "DiagTool.h"
-#include "DiagnosticNames.h"
#include "clang/Basic/Diagnostic.h"
#include "llvm/Support/Format.h"
#include "llvm/ADT/StringMap.h"
@@ -27,6 +26,28 @@ DEF_DIAGTOOL("list-warnings",
using namespace clang;
namespace {
+struct StaticDiagNameIndexRec {
+ const char *NameStr;
+ unsigned short DiagID;
+ uint8_t NameLen;
+
+ StringRef getName() const {
+ return StringRef(NameStr, NameLen);
+ }
+};
+}
+
+static const StaticDiagNameIndexRec StaticDiagNameIndex[] = {
+#define DIAG_NAME_INDEX(ENUM) { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) },
+#include "clang/Basic/DiagnosticIndexName.inc"
+#undef DIAG_NAME_INDEX
+ { 0, 0, 0 }
+};
+
+static const unsigned StaticDiagNameIndexSize =
+ sizeof(StaticDiagNameIndex)/sizeof(StaticDiagNameIndex[0])-1;
+
+namespace {
struct Entry {
llvm::StringRef DiagName;
llvm::StringRef Flag;
@@ -52,8 +73,8 @@ int ListWarnings::run(unsigned int argc, char **argv, llvm::raw_ostream &out) {
std::vector<Entry> Flagged, Unflagged;
llvm::StringMap<std::vector<unsigned> > flagHistogram;
- for (const diagtool::DiagnosticRecord *di = diagtool::BuiltinDiagnostics,
- *de = di + diagtool::BuiltinDiagnosticsCount; di != de; ++di) {
+ for (const StaticDiagNameIndexRec *di = StaticDiagNameIndex, *de = StaticDiagNameIndex + StaticDiagNameIndexSize;
+ di != de; ++di) {
unsigned diagID = di->DiagID;
diff --git a/tools/diagtool/Makefile b/tools/diagtool/Makefile
index 1004dd44c4..6e3bcfc292 100644
--- a/tools/diagtool/Makefile
+++ b/tools/diagtool/Makefile
@@ -1,4 +1,4 @@
-##===- tools/diagtool/Makefile -----------------------------*- Makefile -*-===##
+##===- tools/driver/Makefile -------------------------------*- Makefile -*-===##
#
# The LLVM Compiler Infrastructure
#
@@ -16,16 +16,9 @@ TOOL_NO_EXPORTS := 1
# Don't install this.
NO_INSTALL = 1
-# Include this here so we can get the configuration of the targets that have
-# been configured for construction. We have to do this early so we can set up
-# LINK_COMPONENTS before including Makefile.rules
-include $(CLANG_LEVEL)/../../Makefile.config
+LINK_COMPONENTS := support
-LINK_COMPONENTS := support $(TARGETS_TO_BUILD)
-
-# FIXME: diagtool should be much lighter than this.
-USEDLIBS = clangAST.a clangBasic.a clangDriver.a clangEdit.a clangFrontend.a \
- clangLex.a clangParse.a clangSema.a clangSerialization.a
+USEDLIBS = clangBasic.a
include $(CLANG_LEVEL)/Makefile
diff --git a/tools/diagtool/ShowEnabledWarnings.cpp b/tools/diagtool/ShowEnabledWarnings.cpp
deleted file mode 100644
index 853c5c4dea..0000000000
--- a/tools/diagtool/ShowEnabledWarnings.cpp
+++ /dev/null
@@ -1,148 +0,0 @@
-//===- ShowEnabledWarnings - diagtool tool for printing enabled flags -----===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "DiagTool.h"
-#include "DiagnosticNames.h"
-#include "clang/Basic/LLVM.h"
-#include "clang/Frontend/CompilerInstance.h"
-#include "clang/Frontend/TextDiagnosticBuffer.h"
-#include "llvm/Support/TargetSelect.h"
-
-DEF_DIAGTOOL("show-enabled",
- "Show which warnings are enabled for a given command line",
- ShowEnabledWarnings)
-
-using namespace clang;
-
-namespace {
- struct PrettyDiag {
- StringRef Name;
- StringRef Flag;
- DiagnosticsEngine::Level Level;
-
- PrettyDiag(StringRef name, StringRef flag, DiagnosticsEngine::Level level)
- : Name(name), Flag(flag), Level(level) {}
-
- bool operator<(const PrettyDiag &x) const { return Name < x.Name; }
- };
-}
-
-static char getFlagForLevel(DiagnosticsEngine::Level Level) {
- switch (Level) {
- case DiagnosticsEngine::Ignored: return ' ';
- case DiagnosticsEngine::Note: return '-';
- case DiagnosticsEngine::Warning: return 'W';
- case DiagnosticsEngine::Error: return 'E';
- case DiagnosticsEngine::Fatal: return 'F';
- }
-
- llvm_unreachable("Unknown diagnostic level");
-}
-
-static CompilerInstance *createCompiler(unsigned int argc, char **argv) {
- // First, build a compiler instance!
- OwningPtr<CompilerInstance> Clang(new CompilerInstance());
- IntrusiveRefCntPtr<DiagnosticIDs> DiagIDs(new DiagnosticIDs());
-
- // Initialize targets first. This may be necessary if any warnings are
- // selectively enabled.
- llvm::InitializeAllTargets();
- llvm::InitializeAllTargetMCs();
- llvm::InitializeAllAsmPrinters();
- llvm::InitializeAllAsmParsers();
-
- // Buffer diagnostics from argument parsing so that we can output them using a
- // well formed diagnostic object.
- TextDiagnosticBuffer *DiagsBuffer = new TextDiagnosticBuffer;
- DiagnosticsEngine Diags(DiagIDs, DiagsBuffer);
-
- bool Success;
- Success = CompilerInvocation::CreateFromArgs(Clang->getInvocation(),
- argv, argv+argc, Diags);
-
- // We are skipping cc1's usual search for a resource directory.
- // This is not likely to affect warning output.
-
- // Create the actual diagnostics engine.
- Clang->createDiagnostics(argc, argv);
- if (!Clang->hasDiagnostics())
- return NULL;
-
- // Flush any errors created when initializing everything. This could happen
- // for invalid command lines, which will probably give non-sensical results.
- DiagsBuffer->FlushDiagnostics(Clang->getDiagnostics());
- if (!Success)
- return NULL;
-
- return Clang.take();
-}
-
-int ShowEnabledWarnings::run(unsigned int argc, char **argv, raw_ostream &Out) {
- // First check our one flag (--flags).
- bool ShouldShowFlags = true;
- if (argc > 0) {
- StringRef FirstArg(*argv);
- if (FirstArg.equals("--no-flags")) {
- ShouldShowFlags = false;
- --argc;
- ++argv;
- } else if (FirstArg.equals("--flags")) {
- ShouldShowFlags = true;
- --argc;
- ++argv;
- }
- }
-
- // Create the compiler instance.
- OwningPtr<CompilerInstance> Clang(createCompiler(argc, argv));
- if (!Clang)
- return EXIT_FAILURE;
-
- DiagnosticsEngine &Diags = Clang->getDiagnostics();
-
- // Now we have our diagnostics. Iterate through EVERY diagnostic and see
- // which ones are turned on.
- // FIXME: It would be very nice to print which flags are turning on which
- // diagnostics, but this can be done with a diff.
- std::vector<PrettyDiag> Active;
-
- for (const diagtool::DiagnosticRecord *I = diagtool::BuiltinDiagnostics,
- *E = I + diagtool::BuiltinDiagnosticsCount; I != E; ++I) {
- unsigned DiagID = I->DiagID;
-
- if (DiagnosticIDs::isBuiltinNote(DiagID))
- continue;
-
- if (!DiagnosticIDs::isBuiltinWarningOrExtension(DiagID))
- continue;
-
- DiagnosticsEngine::Level DiagLevel =
- Diags.getDiagnosticLevel(DiagID, SourceLocation());
- if (DiagLevel == DiagnosticsEngine::Ignored)
- continue;
-
- StringRef WarningOpt = DiagnosticIDs::getWarningOptionForDiag(DiagID);
- Active.push_back(PrettyDiag(I->getName(), WarningOpt, DiagLevel));
- }
-
- std::sort(Active.begin(), Active.end());
-
- // Print them all out.
- for (std::vector<PrettyDiag>::const_iterator I = Active.begin(),
- E = Active.end(); I != E; ++I) {
- if (ShouldShowFlags)
- Out << getFlagForLevel(I->Level) << " ";
- Out << I->Name;
- if (!I->Flag.empty())
- Out << " [-W" << I->Flag << "]";
- Out << '\n';
- }
-
- return EXIT_SUCCESS;
-}