summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2013-09-09 15:08:57 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2013-09-09 15:08:57 +0000
commit7037021e78454ff191cd8c2bf796745fba844c2f (patch)
treeaf0f9b46239b89277fe99c0967449eef6ad9537d
parent60509af49add1fedf59d0e117c90c273b70fdaed (diff)
downloadbcm5719-llvm-7037021e78454ff191cd8c2bf796745fba844c2f.tar.gz
bcm5719-llvm-7037021e78454ff191cd8c2bf796745fba844c2f.zip
Sema: Don't crash on visibility attributes with an identifier argument.
PR17105. llvm-svn: 190312
-rw-r--r--clang/lib/Sema/SemaDeclAttr.cpp7
-rw-r--r--clang/test/Sema/attr-visibility.c2
2 files changed, 6 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 78b963c16ff..0a6cee900b4 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2438,9 +2438,10 @@ static void handleVisibilityAttr(Sema &S, Decl *D, const AttributeList &Attr,
if (!checkAttributeNumArgs(S, Attr, 1))
return;
- Expr *Arg = Attr.getArgAsExpr(0);
- Arg = Arg->IgnoreParenCasts();
- StringLiteral *Str = dyn_cast<StringLiteral>(Arg);
+ // Check that the argument is a string literal.
+ StringLiteral *Str = 0;
+ if (Attr.isArgExpr(0))
+ Str = dyn_cast<StringLiteral>(Attr.getArgAsExpr(0)->IgnoreParenCasts());
if (!Str || !Str->isAscii()) {
S.Diag(Attr.getLoc(), diag::err_attribute_argument_type)
diff --git a/clang/test/Sema/attr-visibility.c b/clang/test/Sema/attr-visibility.c
index 7f7fd546f09..ed52ec2743f 100644
--- a/clang/test/Sema/attr-visibility.c
+++ b/clang/test/Sema/attr-visibility.c
@@ -24,3 +24,5 @@ extern int test7 __attribute__((visibility("hidden"))); // expected-error {{visi
typedef int __attribute__((visibility("default"))) bar; // expected-warning {{'visibility' attribute ignored}}
int x __attribute__((type_visibility("default"))); // expected-error {{'type_visibility' attribute only applies to types and namespaces}}
+
+int PR17105 __attribute__((visibility(hidden))); // expected-error {{'visibility' attribute requires a string}}
OpenPOWER on IntegriCloud