Warn on and drop dllimport attrs from variable definitions

AsmPrinter::EmitLinkage() does not handle dllimport linkage.  The LLVM
verifier should also be fixed to reject this.

llvm-svn: 182320
This commit is contained in:
Reid Kleckner 2013-05-20 21:53:29 +00:00
parent 47447589c9
commit 52d598e242
4 changed files with 18 additions and 5 deletions

View File

@ -1957,8 +1957,8 @@ def err_attribute_weak_static : Error<
"weak declaration cannot have internal linkage">;
def err_attribute_selectany_non_extern_data : Error<
"'selectany' can only be applied to data items with external linkage">;
def warn_attribute_weak_import_invalid_on_definition : Warning<
"'weak_import' attribute cannot be specified on a definition">,
def warn_attribute_invalid_on_definition : Warning<
"'%0' attribute cannot be specified on a definition">,
InGroup<IgnoredAttributes>;
def err_attribute_weakref_not_static : Error<
"weakref declaration must have internal linkage">;

View File

@ -2725,9 +2725,8 @@ static void handleWeakImportAttr(Sema &S, Decl *D, const AttributeList &Attr) {
bool isDef = false;
if (!D->canBeWeakImported(isDef)) {
if (isDef)
S.Diag(Attr.getLoc(),
diag::warn_attribute_weak_import_invalid_on_definition)
<< "weak_import" << 2 /*variable and function*/;
S.Diag(Attr.getLoc(), diag::warn_attribute_invalid_on_definition)
<< "weak_import";
else if (isa<ObjCPropertyDecl>(D) || isa<ObjCMethodDecl>(D) ||
(S.Context.getTargetInfo().getTriple().isOSDarwin() &&
(isa<ObjCInterfaceDecl>(D) || isa<EnumDecl>(D)))) {

View File

@ -161,6 +161,15 @@ DLLImportAttr *Sema::mergeDLLImportAttr(Decl *D, SourceRange Range,
if (D->hasAttr<DLLImportAttr>())
return NULL;
if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
if (VD->hasDefinition()) {
// dllimport cannot be applied to definitions.
Diag(D->getLocation(), diag::warn_attribute_invalid_on_definition)
<< "dllimport";
return NULL;
}
}
return ::new (Context) DLLImportAttr(Range, Context,
AttrSpellingListIndex);
}

View File

@ -41,3 +41,8 @@ void __attribute__((dllexport)) foo13();
extern int foo14 __attribute__((dllexport));
extern int foo14 __attribute__((dllimport)); // expected-warning{{dllimport attribute ignored}}
__declspec(dllimport) int foo15 = 54; // expected-warning{{'dllimport' attribute cannot be specified on a definition}}
extern __declspec(dllimport) int foo17;
int foo17 = 54; // expected-warning{{'dllimport' attribute cannot be specified on a definition}}