Add test case for nonnull attribute.
Fix indexing bug. llvm-svn: 53882
This commit is contained in:
parent
2d63bc1e99
commit
5224e6a81d
|
@ -14,6 +14,7 @@
|
|||
#include "Sema.h"
|
||||
#include "clang/AST/ASTContext.h"
|
||||
#include "clang/Basic/TargetInfo.h"
|
||||
#include <sstream>
|
||||
using namespace clang;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -266,11 +267,15 @@ 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()) {
|
||||
// FIXME: Should also highlight argument in decl.
|
||||
|
|
|
@ -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)));
|
||||
|
Loading…
Reference in New Issue