]> granicus.if.org Git - clang/commitdiff
Fix for assertion fail for pragma weak on typedef.
authorAlexander Musman <alexander.musman@gmail.com>
Fri, 18 Sep 2015 07:40:22 +0000 (07:40 +0000)
committerAlexander Musman <alexander.musman@gmail.com>
Fri, 18 Sep 2015 07:40:22 +0000 (07:40 +0000)
Example:
typedef int __td3;
#pragma weak td3 = __td3

Differential Revision: http://reviews.llvm.org/D12904

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@247975 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.cpp
lib/Sema/SemaDecl.cpp
test/CodeGen/pragma-weak.c

index cc509566bdd5f6df5dc43926e387dd0422f14ed3..300e2f040a201424c78839d3ea620cb65f1d5748 100644 (file)
@@ -727,8 +727,15 @@ void Sema::ActOnEndOfTranslationUnit() {
     if (WeakID.second.getUsed())
       continue;
 
-    Diag(WeakID.second.getLocation(), diag::warn_weak_identifier_undeclared)
-        << WeakID.first;
+    Decl *PrevDecl = LookupSingleName(TUScope, WeakID.first, SourceLocation(),
+                                      LookupOrdinaryName);
+    if (PrevDecl != nullptr &&
+        !(isa<FunctionDecl>(PrevDecl) || isa<VarDecl>(PrevDecl)))
+      Diag(WeakID.second.getLocation(), diag::warn_attribute_wrong_decl_type)
+          << "'weak'" << ExpectedVariableOrFunction;
+    else
+      Diag(WeakID.second.getLocation(), diag::warn_weak_identifier_undeclared)
+          << WeakID.first;
   }
 
   if (LangOpts.CPlusPlus11 &&
index 2ed4a61aaba4e0c6f61dde117ac84876e9b08e1a..701d8c729020e138d998c20c00bd51165694e115 100644 (file)
@@ -14530,7 +14530,7 @@ void Sema::ActOnPragmaWeakAlias(IdentifierInfo* Name,
                                     LookupOrdinaryName);
   WeakInfo W = WeakInfo(Name, NameLoc);
 
-  if (PrevDecl) {
+  if (PrevDecl && (isa<FunctionDecl>(PrevDecl) || isa<VarDecl>(PrevDecl))) {
     if (!PrevDecl->hasAttr<AliasAttr>())
       if (NamedDecl *ND = dyn_cast<NamedDecl>(PrevDecl))
         DeclApplyPragmaWeak(TUScope, ND, W);
index 063dec30ac567c1ee796aad9dda25f99d7f62a21..36abca5de32bbf5d5fc5160d41d036a64a2baecd 100644 (file)
@@ -53,12 +53,14 @@ void __foo2(void) {}
 #pragma weak unused // expected-warning {{weak identifier 'unused' never declared}}
 #pragma weak unused_alias = __unused_alias  // expected-warning {{weak identifier '__unused_alias' never declared}}
 
-#pragma weak td // expected-warning {{weak identifier 'td' never declared}}
+#pragma weak td // expected-warning {{'weak' attribute only applies to variables and functions}}
 typedef int td;
 
-#pragma weak td2 = __td2 // expected-warning {{weak identifier '__td2' never declared}}
+#pragma weak td2 = __td2 // expected-warning {{'weak' attribute only applies to variables and functions}}
 typedef int __td2;
 
+typedef int __td3;
+#pragma weak td3 = __td3 // expected-warning {{'weak' attribute only applies to variables and functions}}
 
 ///// test weird cases