aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-03-04 18:08:48 +0000
committerChris Lattner <sabre@nondot.org>2008-03-04 18:08:48 +0000
commit7b937ae68258ce212e39e8e78ad5321e96547f50 (patch)
tree332f3b82c9bf62e01aa8c0a7b406309ab407b8cc
parentfb79f7cc00f9c1e04f11ed636eefb36d246b0fb8 (diff)
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
-rw-r--r--Sema/SemaDecl.cpp23
-rw-r--r--test/CodeGen/attributes.c4
2 files changed, 16 insertions, 11 deletions
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<Expr*>(rawAttr->getArg(0));
+ Arg = Arg->IgnoreParenCasts();
+ StringLiteral *Str = dyn_cast<StringLiteral>(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'