]> granicus.if.org Git - clang/commitdiff
Amending r249721 to properly handle pathological attribute-related names like __...
authorAaron Ballman <aaron@aaronballman.com>
Fri, 9 Oct 2015 13:53:24 +0000 (13:53 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Fri, 9 Oct 2015 13:53:24 +0000 (13:53 +0000)
Patch by Adrian Zgorzalek!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249833 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclAttr.cpp
test/Sema/attr-ownership.c

index 2b38e0f8705d9648e2aab553d4001e5fd4a45192..1f3497609e0c22218f3958703e2de667d1d59c54 100644 (file)
@@ -1311,8 +1311,8 @@ void Sema::AddAssumeAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E,
 /// Normalize the attribute, __foo__ becomes foo.
 /// Returns true if normalization was applied.
 static bool normalizeName(StringRef &AttrName) {
-  if (AttrName.startswith("__") && AttrName.endswith("__")) {
-    assert(AttrName.size() > 4 && "Name too short");
+  if (AttrName.size() > 4 && AttrName.startswith("__") &&
+      AttrName.endswith("__")) {
     AttrName = AttrName.drop_front(2).drop_back(2);
     return true;
   }
index d2e48c65a23cce8d56b84c51d8633b8fafb4f58b..c76f78914b59137c2fc1eb249e586bc621229401 100644 (file)
@@ -19,6 +19,7 @@ void f13(int *i, int *j) __attribute__((ownership_holds(foo, 1))) __attribute__(
 void f14(int i, int j, int *k) __attribute__((ownership_holds(foo, 3))) __attribute__((ownership_takes(foo, 3)));  // expected-error {{'ownership_holds' and 'ownership_takes' attributes are not compatible}}
 
 void f15(int, int)
-  __attribute__((ownership_returns(foo, 1)))  // expected-note {{declared with index 1 here}}
-  __attribute__((ownership_returns(foo, 2))); // expected-error {{'ownership_returns' attribute index does not match; here it is 2}}
-void f16(int *i, int *j) __attribute__((ownership_holds(foo, 1))) __attribute__((ownership_holds(foo, 1))); // OK, same index
+  __attribute__((ownership_returns(foo, 1)))  // expected-note {{declared with index 1 here}}\r
+  __attribute__((ownership_returns(foo, 2))); // expected-error {{'ownership_returns' attribute index does not match; here it is 2}}\r
+void f16(int *i, int *j) __attribute__((ownership_holds(foo, 1))) __attribute__((ownership_holds(foo, 1))); // OK, same index\r
+void f17(void*) __attribute__((ownership_takes(__, 1)));\r