From 003071734f88d59421d78847eb9fec3993effef2 Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Mon, 6 Jan 2014 11:30:15 +0000 Subject: [PATCH] Apply some LLVM_READONLY / LLVM_READNONE on diagnostic functions git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198598 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticIDs.h | 12 ++++++------ include/clang/Basic/TokenKinds.h | 4 ++-- lib/Basic/TokenKinds.cpp | 8 +++++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/clang/Basic/DiagnosticIDs.h b/include/clang/Basic/DiagnosticIDs.h index 56e30fbda7..2be4acf2fa 100644 --- a/include/clang/Basic/DiagnosticIDs.h +++ b/include/clang/Basic/DiagnosticIDs.h @@ -247,15 +247,15 @@ private: /// /// \param Loc The source location for which we are interested in finding out /// the diagnostic state. Can be null in order to query the latest state. - DiagnosticIDs::Level getDiagnosticLevel(unsigned DiagID, SourceLocation Loc, - const DiagnosticsEngine &Diag) const; + DiagnosticIDs::Level + getDiagnosticLevel(unsigned DiagID, SourceLocation Loc, + const DiagnosticsEngine &Diag) const LLVM_READONLY; /// \brief An internal implementation helper used when \p DiagClass is /// already known. - DiagnosticIDs::Level getDiagnosticLevel(unsigned DiagID, - unsigned DiagClass, - SourceLocation Loc, - const DiagnosticsEngine &Diag) const; + DiagnosticIDs::Level + getDiagnosticLevel(unsigned DiagID, unsigned DiagClass, SourceLocation Loc, + const DiagnosticsEngine &Diag) const LLVM_READONLY; /// \brief Used to report a diagnostic that is finally fully formed. /// diff --git a/include/clang/Basic/TokenKinds.h b/include/clang/Basic/TokenKinds.h index 029cbdd48c..53f006a887 100644 --- a/include/clang/Basic/TokenKinds.h +++ b/include/clang/Basic/TokenKinds.h @@ -54,7 +54,7 @@ enum OnOffSwitch { /// /// The name of a token will be an internal name (such as "l_square") /// and should not be used as part of diagnostic messages. -const char *getTokenName(enum TokenKind Kind); +const char *getTokenName(enum TokenKind Kind) LLVM_READNONE; /// \brief Determines the spelling of simple punctuation tokens like /// '!' or '%', and returns NULL for literal and annotation tokens. @@ -63,7 +63,7 @@ const char *getTokenName(enum TokenKind Kind); /// and will not produce any alternative spellings (e.g., a /// digraph). For the actual spelling of a given Token, use /// Preprocessor::getSpelling(). -const char *getTokenSimpleSpelling(enum TokenKind Kind); +const char *getTokenSimpleSpelling(enum TokenKind Kind) LLVM_READNONE; /// \brief Return true if this is a raw identifier or an identifier kind. inline bool isAnyIdentifier(TokenKind K) { diff --git a/lib/Basic/TokenKinds.cpp b/lib/Basic/TokenKinds.cpp index 6ce076e57a..f62624c55a 100644 --- a/lib/Basic/TokenKinds.cpp +++ b/lib/Basic/TokenKinds.cpp @@ -12,7 +12,7 @@ //===----------------------------------------------------------------------===// #include "clang/Basic/TokenKinds.h" -#include +#include "llvm/Support/ErrorHandling.h" using namespace clang; static const char * const TokNames[] = { @@ -23,8 +23,10 @@ static const char * const TokNames[] = { }; const char *tok::getTokenName(enum TokenKind Kind) { - assert(Kind < tok::NUM_TOKENS); - return TokNames[Kind]; + if (Kind < tok::NUM_TOKENS) + return TokNames[Kind]; + llvm_unreachable("unknown TokenKind"); + return 0; } const char *tok::getTokenSimpleSpelling(enum TokenKind Kind) { -- 2.40.0