[cfe-commits] r158662 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclAttr.cpp test/Sema/alloc_size.c

Nuno Lopes nunoplopes at sapo.pt
Mon Jun 18 09:27:56 PDT 2012


Author: nlopes
Date: Mon Jun 18 11:27:56 2012
New Revision: 158662

URL: http://llvm.org/viewvc/llvm-project?rev=158662&view=rev
Log:
alloc_size attribute: there's nothing wrong with alloc_size(1,1). It just means the function allocates x^2 bytes. GCC also accepts this syntax

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/test/Sema/alloc_size.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=158662&r1=158661&r2=158662&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jun 18 11:27:56 2012
@@ -1509,8 +1509,6 @@
 def err_init_priority_object_attr : Error<
   "can only use 'init_priority' attribute on file-scope definitions "
   "of objects of class type">;
-def err_attribute_argument_duplicate: Error<
-  "'%0' attribute parameter %1 is duplicated">;
 def err_attribute_argument_n_not_int : Error<
   "'%0' attribute requires parameter %1 to be an integer constant">;
 def err_attribute_argument_n_not_string : Error<

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=158662&r1=158661&r2=158662&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Mon Jun 18 11:27:56 2012
@@ -972,15 +972,6 @@
       return;
     }
 
-    // check if the argument is a duplicate
-    SmallVectorImpl<unsigned>::iterator Pos;
-    Pos = std::find(SizeArgs.begin(), SizeArgs.end(), x);
-    if (Pos != SizeArgs.end()) {
-      S.Diag(Attr.getLoc(), diag::err_attribute_argument_duplicate)
-      << "alloc_size" << I.getArgNum() << Ex->getSourceRange();
-      return;
-    }
-
     SizeArgs.push_back(x);
   }
 
@@ -990,11 +981,8 @@
     << "alloc_size" << 0 /*function*/<< 1 /*pointer*/ << D->getSourceRange();
   }
 
-  unsigned size = SizeArgs.size();
-  unsigned* start = &SizeArgs[0];
-  llvm::array_pod_sort(start, start + size);
-  D->addAttr(::new (S.Context) AllocSizeAttr(Attr.getRange(), S.Context, start,
-                                             size));
+  D->addAttr(::new (S.Context) AllocSizeAttr(Attr.getRange(), S.Context,
+                                             SizeArgs.data(), SizeArgs.size()));
 }
 
 static void handleNonNullAttr(Sema &S, Decl *D, const AttributeList &Attr) {

Modified: cfe/trunk/test/Sema/alloc_size.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/alloc_size.c?rev=158662&r1=158661&r2=158662&view=diff
==============================================================================
--- cfe/trunk/test/Sema/alloc_size.c (original)
+++ cfe/trunk/test/Sema/alloc_size.c Mon Jun 18 11:27:56 2012
@@ -17,6 +17,6 @@
 
 void* fn7(unsigned) __attribute__((alloc_size)); // expected-error {{attribute takes at least 1 argument}}
 
-void *fn8(int, int) __attribute__((alloc_size(1, 1))); // expected-error {{attribute parameter 2 is duplicated}}
+void *fn8(int, int) __attribute__((alloc_size(1, 1))); // OK
 
 void* fn9(unsigned) __attribute__((alloc_size(12345678901234567890123))); // expected-warning {{integer constant is too large for its type}} // expected-error {{attribute parameter 1 is out of bounds}}





More information about the cfe-commits mailing list