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
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 63e99fd..8d01d63 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -430,7 +430,7 @@
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 @@
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,