]> granicus.if.org Git - clang/commitdiff
Sema: Don't crash on visibility attributes with an identifier argument.
authorBenjamin Kramer <benny.kra@googlemail.com>
Mon, 9 Sep 2013 15:08:57 +0000 (15:08 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Mon, 9 Sep 2013 15:08:57 +0000 (15:08 +0000)
PR17105.

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

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

index 78b963c16ffb4805354177c606613f32d76b45a2..0a6cee900b465b03913fd0a9d3e1d328046bd12c 100644 (file)
@@ -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)
index 7f7fd546f0954cd8ca9d70688b58ccd271c9d38e..ed52ec2743f9568082155c6999dd9afae331df68 100644 (file)
@@ -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}}