diff options
author | Reid Kleckner <reid@kleckner.net> | 2013-05-20 21:53:29 +0000 |
---|---|---|
committer | Reid Kleckner <reid@kleckner.net> | 2013-05-20 21:53:29 +0000 |
commit | 52d598e24269664825a6ec60e3373af4418f17c2 (patch) | |
tree | ab0a3065d9c5b2a7788a276ab4ae6f5a6abd922b /clang | |
parent | 47447589c9a6af2c290481edc0db126bcd206526 (diff) | |
download | bcm5719-llvm-52d598e24269664825a6ec60e3373af4418f17c2.tar.gz bcm5719-llvm-52d598e24269664825a6ec60e3373af4418f17c2.zip |
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
Diffstat (limited to 'clang')
-rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 4 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 5 | ||||
-rw-r--r-- | clang/lib/Sema/TargetAttributesSema.cpp | 9 | ||||
-rw-r--r-- | clang/test/Sema/dllimport-dllexport.c | 5 |
4 files changed, 18 insertions, 5 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index f1a179c259c..f52d1f3162b 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -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">; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 627bc3d3649..be4bd0e3b78 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -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)))) { diff --git a/clang/lib/Sema/TargetAttributesSema.cpp b/clang/lib/Sema/TargetAttributesSema.cpp index 2f7701227da..526399a2783 100644 --- a/clang/lib/Sema/TargetAttributesSema.cpp +++ b/clang/lib/Sema/TargetAttributesSema.cpp @@ -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); } diff --git a/clang/test/Sema/dllimport-dllexport.c b/clang/test/Sema/dllimport-dllexport.c index 00c9df594b6..80810d696e8 100644 --- a/clang/test/Sema/dllimport-dllexport.c +++ b/clang/test/Sema/dllimport-dllexport.c @@ -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}} |