[cfe-commits] r47893 - in /cfe/trunk: Sema/SemaDecl.cpp test/CodeGen/attributes.c
Chris Lattner
sabre at nondot.org
Tue Mar 4 10:08:49 PST 2008
Author: lattner
Date: Tue Mar 4 12:08:48 2008
New Revision: 47893
URL: http://llvm.org/viewvc/llvm-project?rev=47893&view=rev
Log:
The operand to the visibility attribute is required to be a quoted string, not a bare identifier.
Modified:
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/test/CodeGen/attributes.c
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=47893&r1=47892&r2=47893&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Tue Mar 4 12:08:48 2008
@@ -2022,32 +2022,37 @@
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;
}
Modified: cfe/trunk/test/CodeGen/attributes.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/attributes.c?rev=47893&r1=47892&r2=47893&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/attributes.c (original)
+++ cfe/trunk/test/CodeGen/attributes.c Tue Mar 4 12:08:48 2008
@@ -11,14 +11,14 @@
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'
More information about the cfe-commits
mailing list