[cfe-commits] r53882 - in /cfe/trunk: lib/Sema/SemaDeclAttr.cpp test/Sema/nonnull.c

Ted Kremenek kremenek at apple.com
Mon Jul 21 15:09:16 PDT 2008


Author: kremenek
Date: Mon Jul 21 17:09:15 2008
New Revision: 53882

URL: http://llvm.org/viewvc/llvm-project?rev=53882&view=rev
Log:
Add test case for nonnull attribute.
Fix indexing bug.

Added:
    cfe/trunk/test/Sema/nonnull.c
Modified:
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=53882&r1=53881&r2=53882&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Mon Jul 21 17:09:15 2008
@@ -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 @@
     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()) {

Added: cfe/trunk/test/Sema/nonnull.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/nonnull.c?rev=53882&view=auto

==============================================================================
--- cfe/trunk/test/Sema/nonnull.c (added)
+++ cfe/trunk/test/Sema/nonnull.c Mon Jul 21 17:09:15 2008
@@ -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)));
+





More information about the cfe-commits mailing list