]> granicus.if.org Git - clang/commitdiff
Guard availability and thread safety attributes against wide strings.
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 13 Sep 2013 16:30:12 +0000 (16:30 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 13 Sep 2013 16:30:12 +0000 (16:30 +0000)
Found by inspection.

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

lib/Sema/SemaDeclAttr.cpp
test/Sema/attr-availability.c
test/SemaCXX/warn-thread-safety-parsing.cpp

index 63e99fdb0f546af719fea9d457a76029fa76ef05..8d01d638d385015dcd8c453d706f56905d70d79d 100644 (file)
@@ -430,7 +430,7 @@ static void checkAttrArgsAreLockableObjs(Sema &S, Decl *D,
 
     if (StringLiteral *StrLit = dyn_cast<StringLiteral>(ArgExp)) {
       if (StrLit->getLength() == 0 ||
-          StrLit->getString() == StringRef("*")) {
+          (StrLit->isAscii() && StrLit->getString() == StringRef("*"))) {
         // Pass empty strings to the analyzer without warnings.
         // Treat "*" as the universal lock.
         Args.push_back(ArgExp);
@@ -2267,10 +2267,16 @@ static void handleAvailabilityAttr(Sema &S, Decl *D,
   AvailabilityChange Obsoleted = Attr.getAvailabilityObsoleted();
   bool IsUnavailable = Attr.getUnavailableLoc().isValid();
   StringRef Str;
-  const StringLiteral *SE = 
-    dyn_cast_or_null<const StringLiteral>(Attr.getMessageExpr());
-  if (SE)
+  if (Attr.getMessageExpr()) {
+    const StringLiteral *SE = dyn_cast<StringLiteral>(Attr.getMessageExpr());
+    if (!SE || !SE->isAscii()) {
+      S.Diag(Attr.getMessageExpr()->getLocStart(),
+             diag::err_attribute_argument_type)
+        << Attr.getName() << AANT_ArgumentString;
+      return;
+    }
     Str = SE->getString();
+  }
 
   AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(ND, Attr.getRange(), II,
                                                       Introduced.Version,
index ac6a187591b07be1e8f9b8d1f5bb99a6cc46f4e6..f7bd74d8d3bc6d9b7a29bf6759af53d899a1f4c6 100644 (file)
@@ -54,3 +54,5 @@ void f8() {
 
 extern int x2 __attribute__((availability(macosx,introduced=10.2))); // expected-note {{previous attribute is here}}
 extern int x2 __attribute__((availability(macosx,introduced=10.5))); // expected-warning {{availability does not match previous declaration}}
+
+extern int x3 __attribute__((availability(macosx,message=L"wide"))); // expected-error {{'availability' attribute requires a string}}
index 16ac422fd25bd521f9aa5b4034a9af09e91a6c23..1bd4e439b7b0a14948356550c50669ab41d6c568 100644 (file)
@@ -307,6 +307,8 @@ void sl_function_params(int lvar SCOPED_LOCKABLE); // \
 
 int gb_var_arg GUARDED_BY(mu1);
 
+int gb_non_ascii GUARDED_BY(L"wide"); // expected-warning {{ignoring 'guarded_by' attribute because its argument is invalid}}
+
 int gb_var_args __attribute__((guarded_by(mu1, mu2))); // \
   // expected-error {{'guarded_by' attribute takes one argument}}