[cfe-commits] r59598 - in /cfe/trunk: include/clang/Analysis/PathSensitive/BugReporter.h include/clang/Basic/Diagnostic.h lib/Basic/Diagnostic.cpp lib/Sema/SemaDeclAttr.cpp
Chris Lattner
sabre at nondot.org
Tue Nov 18 23:22:31 PST 2008
Author: lattner
Date: Wed Nov 19 01:22:31 2008
New Revision: 59598
URL: http://llvm.org/viewvc/llvm-project?rev=59598&view=rev
Log:
add direct support for signed and unsigned integer arguments to diagnostics.
Modified:
cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
cfe/trunk/include/clang/Basic/Diagnostic.h
cfe/trunk/lib/Basic/Diagnostic.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h?rev=59598&r1=59597&r2=59598&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h Wed Nov 19 01:22:31 2008
@@ -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 @@
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;
}
}
}
Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=59598&r1=59597&r2=59598&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Wed Nov 19 01:22:31 2008
@@ -238,7 +238,9 @@
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 @@
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 @@
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]) &&
Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=59598&r1=59597&r2=59598&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Wed Nov 19 01:22:31 2008
@@ -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 @@
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;
}
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=59598&r1=59597&r2=59598&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Nov 19 01:22:31 2008
@@ -328,7 +328,7 @@
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;
}
More information about the cfe-commits
mailing list