Skip to content

Commit

Permalink
Fix for assertion fail for pragma weak on typedef.
Browse files Browse the repository at this point in the history
Example:
typedef int __td3;
#pragma weak td3 = __td3

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

llvm-svn: 247975
  • Loading branch information
amusman committed Sep 18, 2015
1 parent 8c3142b commit fbbc0b8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
11 changes: 9 additions & 2 deletions clang/lib/Sema/Sema.cpp
Expand Up @@ -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 &&
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaDecl.cpp
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions clang/test/CodeGen/pragma-weak.c
Expand Up @@ -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

Expand Down

0 comments on commit fbbc0b8

Please sign in to comment.