From f37e4f24c39d0fd3c7f954d2321c4590421907af Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Fri, 13 Sep 2013 16:30:12 +0000 Subject: [PATCH] Guard availability and thread safety attributes against wide strings. Found by inspection. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190701 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclAttr.cpp | 14 ++++++++++---- test/Sema/attr-availability.c | 2 ++ test/SemaCXX/warn-thread-safety-parsing.cpp | 2 ++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 63e99fdb0f..8d01d638d3 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -430,7 +430,7 @@ static void checkAttrArgsAreLockableObjs(Sema &S, Decl *D, if (StringLiteral *StrLit = dyn_cast(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(Attr.getMessageExpr()); - if (SE) + if (Attr.getMessageExpr()) { + const StringLiteral *SE = dyn_cast(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, diff --git a/test/Sema/attr-availability.c b/test/Sema/attr-availability.c index ac6a187591..f7bd74d8d3 100644 --- a/test/Sema/attr-availability.c +++ b/test/Sema/attr-availability.c @@ -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}} diff --git a/test/SemaCXX/warn-thread-safety-parsing.cpp b/test/SemaCXX/warn-thread-safety-parsing.cpp index 16ac422fd2..1bd4e439b7 100644 --- a/test/SemaCXX/warn-thread-safety-parsing.cpp +++ b/test/SemaCXX/warn-thread-safety-parsing.cpp @@ -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}} -- 2.50.1