Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -14530,7 +14530,7 @@ LookupOrdinaryName); WeakInfo W = WeakInfo(Name, NameLoc); - if (PrevDecl) { + if (PrevDecl && (isa(PrevDecl) || isa(PrevDecl))) { if (!PrevDecl->hasAttr()) if (NamedDecl *ND = dyn_cast(PrevDecl)) DeclApplyPragmaWeak(TUScope, ND, W); Index: test/CodeGen/pragma-weak.c =================================================================== --- test/CodeGen/pragma-weak.c +++ test/CodeGen/pragma-weak.c @@ -59,6 +59,8 @@ #pragma weak td2 = __td2 // expected-warning {{weak identifier '__td2' never declared}} typedef int __td2; +typedef int __td3; +#pragma weak td3 = __td3 // expected-warning {{weak identifier '__td3' never declared}} ///// test weird cases