diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-07-21 22:09:15 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-07-21 22:09:15 +0000 |
commit | 465172f304248a9aab6f2c398a836ce4e25efbbf (patch) | |
tree | 16bae648616296284e4b3268b82dbce68d4e42d9 | |
parent | eb2b2a3f1898f146c6e153a64ec58ec5e1750bd2 (diff) |
Add test case for nonnull attribute.
Fix indexing bug.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53882 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaDeclAttr.cpp | 7 | ||||
-rw-r--r-- | test/Sema/nonnull.c | 8 |
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 3800fa3568..edf9a664e2 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -14,6 +14,7 @@ #include "Sema.h" #include "clang/AST/ASTContext.h" #include "clang/Basic/TargetInfo.h" +#include <sstream> using namespace clang; //===----------------------------------------------------------------------===// @@ -266,10 +267,14 @@ static void HandleNonNullAttr(Decl *d, const AttributeList &Attr, Sema &S) { unsigned x = (unsigned) ArgNum.getZExtValue(); if (x < 1 || x > NumArgs) { + std::ostringstream os; + os << I.getArgNum(); S.Diag(Attr.getLoc(), diag::err_attribute_argument_out_of_bounds, - "nonnull", Ex->getSourceRange()); + "nonnull", os.str(), Ex->getSourceRange()); return; } + + --x; // Is the function argument a pointer type? if (!proto->getArgType(x).getCanonicalType()->isPointerType()) { diff --git a/test/Sema/nonnull.c b/test/Sema/nonnull.c new file mode 100644 index 0000000000..f8a2a0ed78 --- /dev/null +++ b/test/Sema/nonnull.c @@ -0,0 +1,8 @@ +// RUN: clang -fsyntax-only -verify %s + +int f1(int x) __attribute__((nonnull)); +int f2(int *x) __attribute__ ((nonnull (1))); +int f3(int *x) __attribute__ ((nonnull (0))); // expected-error {{'nonnull' attribute parameter 1 is out of bounds}} +int f4(int *x, int *y) __attribute__ ((nonnull (1,2))); +int f5(int *x, int *y) __attribute__ ((nonnull (2,1))); + |