aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-11-19 07:22:31 +0000
committerChris Lattner <sabre@nondot.org>2008-11-19 07:22:31 +0000
commit30bc96544346bea42921cf6837e66cef80d664b4 (patch)
tree97ede4737a79f212755c55bdadd33796d553c2df
parenta03a5b5a84989b1cbd3917b967e8fe64f99cfa80 (diff)
add direct support for signed and unsigned integer arguments to diagnostics.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59598 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Analysis/PathSensitive/BugReporter.h9
-rw-r--r--include/clang/Basic/Diagnostic.h33
-rw-r--r--lib/Basic/Diagnostic.cpp13
-rw-r--r--lib/Sema/SemaDeclAttr.cpp2
4 files changed, 55 insertions, 2 deletions
diff --git a/include/clang/Analysis/PathSensitive/BugReporter.h b/include/clang/Analysis/PathSensitive/BugReporter.h
index 72f83bee34..870e9d39f0 100644
--- a/include/clang/Analysis/PathSensitive/BugReporter.h
+++ b/include/clang/Analysis/PathSensitive/BugReporter.h
@@ -21,6 +21,7 @@
#include "clang/Analysis/PathSensitive/ExplodedGraph.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/StringExtras.h"
#include <list>
namespace clang {
@@ -323,6 +324,14 @@ public:
case DiagnosticInfo::ak_c_string:
R.addString(Info.getArgCStr(i));
break;
+ case DiagnosticInfo::ak_sint:
+ // FIXME: Optimize
+ R.addString(llvm::itostr(Info.getArgSInt(i)));
+ break;
+ case DiagnosticInfo::ak_uint:
+ // FIXME: Optimize
+ R.addString(llvm::utostr_32(Info.getArgUInt(i)));
+ break;
}
}
}
diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h
index 303d83cc66..fe3cfeeb31 100644
--- a/include/clang/Basic/Diagnostic.h
+++ b/include/clang/Basic/Diagnostic.h
@@ -238,7 +238,9 @@ class DiagnosticInfo {
public:
enum ArgumentKind {
ak_std_string, // std::string
- ak_c_string // const char *
+ ak_c_string, // const char *
+ ak_sint, // int
+ ak_uint // unsigned
};
@@ -302,6 +304,18 @@ public:
return reinterpret_cast<const char*>(DiagObj->DiagArgumentsVal[Idx]);
}
+ /// getArgSInt - Return the specified signed integer argument.
+ int getArgSInt(unsigned Idx) const {
+ assert(getArgKind(Idx) == ak_sint && "invalid argument accessor!");
+ return (int)DiagObj->DiagArgumentsVal[Idx];
+ }
+
+ /// getArgUInt - Return the specified unsigned integer argument.
+ unsigned getArgUInt(unsigned Idx) const {
+ assert(getArgKind(Idx) == ak_uint && "invalid argument accessor!");
+ return (unsigned)DiagObj->DiagArgumentsVal[Idx];
+ }
+
/// getNumRanges - Return the number of source ranges associated with this
/// diagnostic.
unsigned getNumRanges() const {
@@ -330,6 +344,23 @@ public:
return *this;
}
+ DiagnosticInfo &operator<<(int I) {
+ assert((unsigned)DiagObj->NumDiagArgs < Diagnostic::MaxArguments &&
+ "Too many arguments to diagnostic!");
+ DiagObj->DiagArgumentsKind[DiagObj->NumDiagArgs] = ak_sint;
+ DiagObj->DiagArgumentsVal[DiagObj->NumDiagArgs++] = I;
+ return *this;
+ }
+
+ DiagnosticInfo &operator<<(unsigned I) {
+ assert((unsigned)DiagObj->NumDiagArgs < Diagnostic::MaxArguments &&
+ "Too many arguments to diagnostic!");
+ DiagObj->DiagArgumentsKind[DiagObj->NumDiagArgs] = ak_uint;
+ DiagObj->DiagArgumentsVal[DiagObj->NumDiagArgs++] = I;
+ return *this;
+ }
+
+
DiagnosticInfo &operator<<(const SourceRange &R) {
assert((unsigned)DiagObj->NumDiagArgs <
sizeof(DiagObj->DiagRanges)/sizeof(DiagObj->DiagRanges[0]) &&
diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp
index e8c24ab0a7..9428b218e5 100644
--- a/lib/Basic/Diagnostic.cpp
+++ b/lib/Basic/Diagnostic.cpp
@@ -14,6 +14,7 @@
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/SourceLocation.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
#include <vector>
#include <map>
#include <cstring>
@@ -279,6 +280,18 @@ FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const {
OutStr.append(S, S + strlen(S));
break;
}
+ case DiagnosticInfo::ak_sint: {
+ // FIXME: Optimize
+ std::string S = llvm::itostr(getArgSInt(StrNo));
+ OutStr.append(S.begin(), S.end());
+ break;
+ }
+ case DiagnosticInfo::ak_uint: {
+ // FIXME: Optimize
+ std::string S = llvm::utostr_32(getArgUInt(StrNo));
+ OutStr.append(S.begin(), S.end());
+ break;
+ }
}
DiagStr += 2;
}
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 40f70fb3cc..d83ba8561b 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -328,7 +328,7 @@ static void HandleNonNullAttr(Decl *d, const AttributeList &Attr, Sema &S) {
if (x < 1 || x > NumArgs) {
S.Diag(Attr.getLoc(), diag::err_attribute_argument_out_of_bounds)
- << "nonnull" << llvm::utostr_32(I.getArgNum()) << Ex->getSourceRange();
+ << "nonnull" << I.getArgNum() << Ex->getSourceRange();
return;
}