From: Chris Lattner Date: Tue, 4 Mar 2008 18:08:48 +0000 (+0000) Subject: The operand to the visibility attribute is required to be a quoted string, not a... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7b937ae68258ce212e39e8e78ad5321e96547f50;p=clang The operand to the visibility attribute is required to be a quoted string, not a bare identifier. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47893 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index 88225f535d..3b63a80566 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -2022,32 +2022,37 @@ void Sema::HandleDeprecatedAttribute(Decl *d, AttributeList *rawAttr) { void Sema::HandleVisibilityAttribute(Decl *d, AttributeList *rawAttr) { // check the attribute arguments. - if (rawAttr->getNumArgs() != 0) { + if (rawAttr->getNumArgs() != 1) { Diag(rawAttr->getLoc(), diag::err_attribute_wrong_number_arguments, std::string("1")); return; } - if (!rawAttr->getParameterName()) { + Expr *Arg = static_cast(rawAttr->getArg(0)); + Arg = Arg->IgnoreParenCasts(); + StringLiteral *Str = dyn_cast(Arg); + + if (Str == 0 || Str->isWide()) { Diag(rawAttr->getLoc(), diag::err_attribute_argument_n_not_string, - "visibility", std::string("1")); + "visibility", std::string("1")); return; } - const char *typeStr = rawAttr->getParameterName()->getName(); + const char *TypeStr = Str->getStrData(); + unsigned TypeLen = Str->getByteLength(); llvm::GlobalValue::VisibilityTypes type; - if (!memcmp(typeStr, "default", 7)) + if (TypeLen == 7 && !memcmp(TypeStr, "default", 7)) type = llvm::GlobalValue::DefaultVisibility; - else if (!memcmp(typeStr, "hidden", 6)) + else if (TypeLen == 6 && !memcmp(TypeStr, "hidden", 6)) type = llvm::GlobalValue::HiddenVisibility; - else if (!memcmp(typeStr, "internal", 8)) + else if (TypeLen == 8 && !memcmp(TypeStr, "internal", 8)) type = llvm::GlobalValue::HiddenVisibility; // FIXME - else if (!memcmp(typeStr, "protected", 9)) + else if (TypeLen == 9 && !memcmp(TypeStr, "protected", 9)) type = llvm::GlobalValue::ProtectedVisibility; else { Diag(rawAttr->getLoc(), diag::warn_attribute_type_not_supported, - "visibility", typeStr); + "visibility", TypeStr); return; } diff --git a/test/CodeGen/attributes.c b/test/CodeGen/attributes.c index 3533d6d843..a310a3ab64 100644 --- a/test/CodeGen/attributes.c +++ b/test/CodeGen/attributes.c @@ -11,14 +11,14 @@ void t3() __attribute__((weak)); void t3() {} // RUN: clang -emit-llvm < %s | grep 'hidden.*t4' -void t4() __attribute__((visibility(hidden))); +void t4() __attribute__((visibility("hidden"))); void t4() {} // RUN: clang -emit-llvm < %s | grep 't5.*weak' int t5 __attribute__((weak)) = 2; // RUN: clang -emit-llvm < %s | grep 't6.*protected' -int t6 __attribute__((visibility(protected))); +int t6 __attribute__((visibility("protected"))); // RUN: clang -emit-llvm < %s | grep 't7.*noreturn' // RUN: clang -emit-llvm < %s | grep 't7.*nounwind'