From 19e8e2cffc19606d0f44e7c2897cd126ffd3f9b0 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 29 Jan 2009 17:46:13 +0000 Subject: [PATCH] next round of diagnostics cleanups, moving some diags around, eliminating #defines, etc. Patch by Anders Johnsen! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63318 91177308-0d34-0410-b5e6-96231b3b80d8 --- Driver/clang.cpp | 1 - include/clang/AST/ASTDiagnostic.h | 1 + include/clang/Analysis/AnalysisDiagnostic.h | 1 + include/clang/Basic/Diagnostic.h | 21 ++++---- include/clang/Basic/DiagnosticCommonKinds.def | 12 ----- include/clang/Basic/DiagnosticKinds.def | 33 ------------ include/clang/Basic/DiagnosticLexKinds.def | 4 ++ include/clang/Basic/DiagnosticSemaKinds.def | 8 +++ include/clang/Driver/DriverDiagnostic.h | 25 --------- include/clang/Lex/LexDiagnostic.h | 1 + include/clang/Parse/ParseDiagnostic.h | 1 + lib/Basic/Diagnostic.cpp | 52 +++++++++---------- 12 files changed, 54 insertions(+), 106 deletions(-) diff --git a/Driver/clang.cpp b/Driver/clang.cpp index 77d5ef7082..d29579f600 100644 --- a/Driver/clang.cpp +++ b/Driver/clang.cpp @@ -29,7 +29,6 @@ #include "clang/Driver/InitHeaderSearch.h" #include "clang/Driver/TextDiagnosticBuffer.h" #include "clang/Driver/TextDiagnosticPrinter.h" -#include "clang/Driver/DriverDiagnostic.h" #include "clang/Analysis/PathDiagnostic.h" #include "clang/AST/Decl.h" #include "clang/AST/TranslationUnit.h" diff --git a/include/clang/AST/ASTDiagnostic.h b/include/clang/AST/ASTDiagnostic.h index ddb5b404e4..f08cb33e37 100644 --- a/include/clang/AST/ASTDiagnostic.h +++ b/include/clang/AST/ASTDiagnostic.h @@ -18,6 +18,7 @@ namespace clang { #define DIAG(ENUM,FLAGS,DESC) ENUM, #define ASTSTART #include "clang/Basic/DiagnosticASTKinds.def" +#undef DIAG NUM_BUILTIN_AST_DIAGNOSTICS }; } // end namespace diag diff --git a/include/clang/Analysis/AnalysisDiagnostic.h b/include/clang/Analysis/AnalysisDiagnostic.h index 1f2f089100..f01170a925 100644 --- a/include/clang/Analysis/AnalysisDiagnostic.h +++ b/include/clang/Analysis/AnalysisDiagnostic.h @@ -18,6 +18,7 @@ namespace clang { #define DIAG(ENUM,FLAGS,DESC) ENUM, #define ANALYSISSTART #include "clang/Basic/DiagnosticAnalysisKinds.def" +#undef DIAG NUM_BUILTIN_ANALYSIS_DIAGNOSTICS }; } // end namespace diag diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index d9d32bcc5d..2f3184c46b 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -18,13 +18,6 @@ #include #include -#define DIAG_START_LEX 300 -#define DIAG_START_PARSE (DIAG_START_LEX + 300) -#define DIAG_START_AST (DIAG_START_PARSE + 300) -#define DIAG_START_SEMA (DIAG_START_AST + 100) -#define DIAG_START_ANALYSIS (DIAG_START_SEMA + 1000) -#define DIAG_UPPER_LIMIT (DIAG_START_ANALYSIS + 100) - namespace llvm { template class SmallVectorImpl; } @@ -38,6 +31,16 @@ namespace clang { // Import the diagnostic enums themselves. namespace diag { + // Start position for diagnostics. + enum { + DIAG_START_LEX = 300, + DIAG_START_PARSE = DIAG_START_LEX + 300, + DIAG_START_AST = DIAG_START_PARSE + 300, + DIAG_START_SEMA = DIAG_START_AST + 100, + DIAG_START_ANALYSIS = DIAG_START_SEMA + 1000, + DIAG_UPPER_LIMIT = DIAG_START_ANALYSIS + 100 + }; + class CustomDiagInfo; /// diag::kind - All of the diagnostics that can be emitted by the frontend. @@ -93,7 +96,7 @@ private: /// DiagMappings - Mapping information for diagnostics. Mapping info is /// packed into two bits per diagnostic. - unsigned char DiagMappings[DIAG_UPPER_LIMIT/4]; + unsigned char DiagMappings[diag::DIAG_UPPER_LIMIT/4]; /// ErrorOccurred - This is set to true when an error is emitted, and is /// sticky. @@ -155,7 +158,7 @@ public: /// setDiagnosticMapping - This allows the client to specify that certain /// warnings are ignored. Only NOTEs, WARNINGs, and EXTENSIONs can be mapped. void setDiagnosticMapping(diag::kind Diag, diag::Mapping Map) { - assert(Diag < DIAG_UPPER_LIMIT && + assert(Diag < diag::DIAG_UPPER_LIMIT && "Can only map builtin diagnostics"); assert(isBuiltinNoteWarningOrExtension(Diag) && "Cannot map errors!"); unsigned char &Slot = DiagMappings[Diag/4]; diff --git a/include/clang/Basic/DiagnosticCommonKinds.def b/include/clang/Basic/DiagnosticCommonKinds.def index 7386321537..019e9c0de8 100644 --- a/include/clang/Basic/DiagnosticCommonKinds.def +++ b/include/clang/Basic/DiagnosticCommonKinds.def @@ -65,19 +65,7 @@ DIAG(note_invalid_subexpr_in_ice, NOTE, // Driver DIAG(pp_macro_not_used, WARNING, // -Wunused-macros "macro is not used") -DIAG(warn_floatingpoint_eq, WARNING, - "comparing floating point with == or != is unsafe") -DIAG(warn_objc_property_attr_mutually_exclusive, WARNING, - "property attributes '%0' and '%1' are mutually exclusive") -DIAG(warn_printf_not_string_constant, WARNING, - "format string is not a string literal (potentially insecure)") -DIAG(warn_implicit_function_decl, WARNING, - "implicit declaration of function %0") DIAG(err_pp_I_dash_not_supported, ERROR, "-I- not supported, please use -iquote instead") -DIAG(warn_octal_escape_too_large, EXTWARN, - "octal escape sequence out of range") -DIAG(warn_hex_escape_too_large, EXTWARN, - "hex escape sequence out of range") DIAG(warn_pp_undef_identifier, WARNING, "%0 is not defined, evaluates to 0") diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index 70a4821ea1..e69de29bb2 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -1,33 +0,0 @@ -//===-- DiagnosticKinds.def - C Family Diagnostic Kind Database -*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines the DiagnosticKind database. -// -//===----------------------------------------------------------------------===// - -// Flags for diagnostic: -// -// DIAG_TYPE - Allows one of: -// NOTE - Informational message. -// WARNING - Warning. -// EXTENSION - Notification that an extension to the language is being used. -// EXTWARN - Warning for behaviour that is supported as an extension. This -// differs from EXTENSION in that the warning is always emitted -// by default. -// ERROR - Error, compilation will stop after parsing completes. - - -#include "clang/Basic/DiagnosticCommonKinds.def" -#include "clang/Basic/DiagnosticLexKinds.def" -#include "clang/Basic/DiagnosticParseKinds.def" -#include "clang/Basic/DiagnosticASTKinds.def" -#include "clang/Basic/DiagnosticSemaKinds.def" -#include "clang/Basic/DiagnosticAnalysisKinds.def" - -#undef DIAG diff --git a/include/clang/Basic/DiagnosticLexKinds.def b/include/clang/Basic/DiagnosticLexKinds.def index 6965698964..8c9a82688a 100644 --- a/include/clang/Basic/DiagnosticLexKinds.def +++ b/include/clang/Basic/DiagnosticLexKinds.def @@ -98,6 +98,10 @@ DIAG(ext_binary_literal, EXTENSION, "binary integer literals are an extension") DIAG(err_pascal_string_too_long, ERROR, "Pascal string is too long") +DIAG(warn_octal_escape_too_large, EXTWARN, + "octal escape sequence out of range") +DIAG(warn_hex_escape_too_large, EXTWARN, + "hex escape sequence out of range") //===----------------------------------------------------------------------===// // Preprocessor Diagnostics diff --git a/include/clang/Basic/DiagnosticSemaKinds.def b/include/clang/Basic/DiagnosticSemaKinds.def index 6276d61211..63955adc13 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.def +++ b/include/clang/Basic/DiagnosticSemaKinds.def @@ -74,6 +74,8 @@ DIAG(err_parameter_name_omitted, ERROR, "parameter name omitted") DIAG(warn_decl_in_param_list, WARNING, "declaration of %0 will not be visible outside of this function") +DIAG(warn_implicit_function_decl, WARNING, + "implicit declaration of function %0") DIAG(err_declarator_need_ident, ERROR, "declarator requires an identifier") @@ -196,6 +198,8 @@ DIAG(error_duplicate_ivar_use, ERROR, "synthesized properties %0 and %1 both claim ivar %2") DIAG(error_property_implemented, ERROR, "property %0 is already implemented") +DIAG(warn_objc_property_attr_mutually_exclusive, WARNING, + "property attributes '%0' and '%1' are mutually exclusive") // C++ class members DIAG(err_storageclass_invalid_for_member, ERROR, @@ -624,6 +628,8 @@ DIAG(err_offsetof_array_type, ERROR, "offsetof requires array type, %0 invalid") DIAG(ext_offsetof_extended_field_designator, EXTENSION, "using extended field designator is an extension") +DIAG(warn_floatingpoint_eq, WARNING, + "comparing floating point with == or != is unsafe") DIAG(err_typecheck_subscript_value, ERROR, "subscripted value is neither array nor pointer") @@ -721,6 +727,8 @@ DIAG(err_builtin_direct_init_more_than_one_arg, ERROR, "initializer of a builtin type can only take one argument") DIAG(err_value_init_for_array_type, ERROR, "array types cannot be value-initialized") +DIAG(warn_printf_not_string_constant, WARNING, + "format string is not a string literal (potentially insecure)") DIAG(err_unexpected_interface, ERROR, "unexpected interface name %0: expected expression") diff --git a/include/clang/Driver/DriverDiagnostic.h b/include/clang/Driver/DriverDiagnostic.h index 459d17da4e..e69de29bb2 100644 --- a/include/clang/Driver/DriverDiagnostic.h +++ b/include/clang/Driver/DriverDiagnostic.h @@ -1,25 +0,0 @@ -//===--- DiagnosticDriver.h - Diagnostics for the driver --------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_DIAGNOSTICDRIVER_H -#define LLVM_CLANG_DIAGNOSTICDRIVER_H - -#include "clang/Basic/Diagnostic.h" - -namespace clang { - namespace diag { - enum { -// FIXME: REMOVE?? - NUM_BUILTIN_DRIVER_DIAGNOSTICS - }; - } // end namespace diag -} // end namespace clang - -#endif - diff --git a/include/clang/Lex/LexDiagnostic.h b/include/clang/Lex/LexDiagnostic.h index 202605fe5c..8e79e15f6d 100644 --- a/include/clang/Lex/LexDiagnostic.h +++ b/include/clang/Lex/LexDiagnostic.h @@ -18,6 +18,7 @@ namespace clang { #define DIAG(ENUM,FLAGS,DESC) ENUM, #define LEXSTART #include "clang/Basic/DiagnosticLexKinds.def" +#undef DIAG NUM_BUILTIN_LEX_DIAGNOSTICS }; } // end namespace diag diff --git a/include/clang/Parse/ParseDiagnostic.h b/include/clang/Parse/ParseDiagnostic.h index 52a89e8904..1856b0670b 100644 --- a/include/clang/Parse/ParseDiagnostic.h +++ b/include/clang/Parse/ParseDiagnostic.h @@ -18,6 +18,7 @@ namespace clang { #define DIAG(ENUM,FLAGS,DESC) ENUM, #define PARSESTART #include "clang/Basic/DiagnosticParseKinds.def" +#undef DIAG NUM_BUILTIN_PARSE_DIAGNOSTICS }; } // end namespace diag diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp index 6e39beb0c8..5b1145f70b 100644 --- a/lib/Basic/Diagnostic.cpp +++ b/lib/Basic/Diagnostic.cpp @@ -68,21 +68,21 @@ static unsigned char DiagnosticFlagsAnalysis[] = { /// getDiagClass - Return the class field of the diagnostic. /// static unsigned getBuiltinDiagClass(unsigned DiagID) { - assert(DiagID < DIAG_UPPER_LIMIT && + assert(DiagID < diag::DIAG_UPPER_LIMIT && "Diagnostic ID out of range!"); unsigned res; - if (DiagID < DIAG_START_LEX) + if (DiagID < diag::DIAG_START_LEX) res = DiagnosticFlagsCommon[DiagID]; - else if (DiagID < DIAG_START_PARSE) - res = DiagnosticFlagsLex[DiagID - DIAG_START_LEX - 1]; - else if (DiagID < DIAG_START_AST) - res = DiagnosticFlagsParse[DiagID - DIAG_START_PARSE - 1]; - else if (DiagID < DIAG_START_SEMA) - res = DiagnosticFlagsAST[DiagID - DIAG_START_AST - 1]; - else if (DiagID < DIAG_START_ANALYSIS) - res = DiagnosticFlagsSema[DiagID - DIAG_START_SEMA - 1]; + else if (DiagID < diag::DIAG_START_PARSE) + res = DiagnosticFlagsLex[DiagID - diag::DIAG_START_LEX - 1]; + else if (DiagID < diag::DIAG_START_AST) + res = DiagnosticFlagsParse[DiagID - diag::DIAG_START_PARSE - 1]; + else if (DiagID < diag::DIAG_START_SEMA) + res = DiagnosticFlagsAST[DiagID - diag::DIAG_START_AST - 1]; + else if (DiagID < diag::DIAG_START_ANALYSIS) + res = DiagnosticFlagsSema[DiagID - diag::DIAG_START_SEMA - 1]; else - res = DiagnosticFlagsAnalysis[DiagID - DIAG_START_ANALYSIS - 1]; + res = DiagnosticFlagsAnalysis[DiagID - diag::DIAG_START_ANALYSIS - 1]; return res & class_mask; } @@ -216,26 +216,26 @@ unsigned Diagnostic::getCustomDiagID(Level L, const char *Message) { /// level of the specified diagnostic ID is a Note, Warning, or Extension. /// Note that this only works on builtin diagnostics, not custom ones. bool Diagnostic::isBuiltinNoteWarningOrExtension(unsigned DiagID) { - return DiagID < DIAG_UPPER_LIMIT && getBuiltinDiagClass(DiagID) < ERROR; + return DiagID < diag::DIAG_UPPER_LIMIT && getBuiltinDiagClass(DiagID) < ERROR; } /// getDescription - Given a diagnostic ID, return a description of the /// issue. const char *Diagnostic::getDescription(unsigned DiagID) const { - if (DiagID < DIAG_UPPER_LIMIT) { - if (DiagID < DIAG_START_LEX) + if (DiagID < diag::DIAG_UPPER_LIMIT) { + if (DiagID < diag::DIAG_START_LEX) return DiagnosticTextCommon[DiagID]; - else if (DiagID < DIAG_START_PARSE) - return DiagnosticTextLex[DiagID - DIAG_START_LEX - 1]; - else if (DiagID < DIAG_START_AST) - return DiagnosticTextParse[DiagID - DIAG_START_PARSE - 1]; - else if (DiagID < DIAG_START_SEMA) - return DiagnosticTextAST[DiagID - DIAG_START_AST - 1]; - else if (DiagID < DIAG_START_ANALYSIS) - return DiagnosticTextSema[DiagID - DIAG_START_SEMA - 1]; - else if (DiagID < DIAG_UPPER_LIMIT) - return DiagnosticTextAnalysis[DiagID - DIAG_START_ANALYSIS - 1]; + else if (DiagID < diag::DIAG_START_PARSE) + return DiagnosticTextLex[DiagID - diag::DIAG_START_LEX - 1]; + else if (DiagID < diag::DIAG_START_AST) + return DiagnosticTextParse[DiagID - diag::DIAG_START_PARSE - 1]; + else if (DiagID < diag::DIAG_START_SEMA) + return DiagnosticTextAST[DiagID - diag::DIAG_START_AST - 1]; + else if (DiagID < diag::DIAG_START_ANALYSIS) + return DiagnosticTextSema[DiagID - diag::DIAG_START_SEMA - 1]; + else if (DiagID < diag::DIAG_UPPER_LIMIT) + return DiagnosticTextAnalysis[DiagID - diag::DIAG_START_ANALYSIS - 1]; } return CustomDiagInfo->getDescription(DiagID); @@ -246,7 +246,7 @@ const char *Diagnostic::getDescription(unsigned DiagID) const { /// the DiagnosticClient. Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const { // Handle custom diagnostics, which cannot be mapped. - if (DiagID >= DIAG_UPPER_LIMIT) + if (DiagID >= diag::DIAG_UPPER_LIMIT) return CustomDiagInfo->getLevel(DiagID); unsigned DiagClass = getBuiltinDiagClass(DiagID); @@ -307,7 +307,7 @@ void Diagnostic::ProcessDiag() { // ignore extensions and warnings in -Werror and -pedantic-errors modes, // which *map* warnings/extensions to errors. if (SuppressSystemWarnings && - Info.getID() < DIAG_UPPER_LIMIT && + Info.getID() < diag::DIAG_UPPER_LIMIT && getBuiltinDiagClass(Info.getID()) != ERROR && Info.getLocation().isValid() && Info.getLocation().getSpellingLoc().isInSystemHeader()) -- 2.40.0