From: Benjamin Kramer Date: Mon, 9 Sep 2013 15:08:57 +0000 (+0000) Subject: Sema: Don't crash on visibility attributes with an identifier argument. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ae3a83f578e48745f12b213c222217d91187a248;p=clang Sema: Don't crash on visibility attributes with an identifier argument. PR17105. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190312 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 78b963c16f..0a6cee900b 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/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(Arg); + // Check that the argument is a string literal. + StringLiteral *Str = 0; + if (Attr.isArgExpr(0)) + Str = dyn_cast(Attr.getArgAsExpr(0)->IgnoreParenCasts()); if (!Str || !Str->isAscii()) { S.Diag(Attr.getLoc(), diag::err_attribute_argument_type) diff --git a/test/Sema/attr-visibility.c b/test/Sema/attr-visibility.c index 7f7fd546f0..ed52ec2743 100644 --- a/test/Sema/attr-visibility.c +++ b/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}}