diff options
author | Ben Langmuir <blangmuir@apple.com> | 2015-01-20 20:41:36 +0000 |
---|---|---|
committer | Ben Langmuir <blangmuir@apple.com> | 2015-01-20 20:41:36 +0000 |
commit | c91ac9ed498eea96e135c3433e690edf5f951b74 (patch) | |
tree | 506eb01de2b7c3cc2346794f09ecd5a4d6c61a1a /clang/lib/Sema | |
parent | e7d3dfdb754b8c6bd999f272b9b4b70c2aef538f (diff) | |
download | bcm5719-llvm-c91ac9ed498eea96e135c3433e690edf5f951b74.tar.gz bcm5719-llvm-c91ac9ed498eea96e135c3433e690edf5f951b74.zip |
Fix crashes on missing @interface for category
In a few places we didn't check that Category->getClassInterface() was
not null before using it.
llvm-svn: 226605
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 5 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 10 | ||||
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 4 |
3 files changed, 14 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 9eb5993f2a2..8fbe82fd881 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -13979,7 +13979,10 @@ Decl *Sema::getObjCDeclContext() const { } AvailabilityResult Sema::getCurContextAvailability() const { - const Decl *D = cast<Decl>(getCurObjCLexicalContext()); + const Decl *D = cast_or_null<Decl>(getCurObjCLexicalContext()); + if (!D) + return AR_Available; + // If we are within an Objective-C method, we should consult // both the availability of the method as well as the // enclosing class. If the class is (say) deprecated, diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 8837bbdb2bc..c17451eaaaf 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -3783,6 +3783,10 @@ static void handleObjCDesignatedInitializer(Sema &S, Decl *D, IFace = CatDecl->getClassInterface(); else IFace = cast<ObjCInterfaceDecl>(D->getDeclContext()); + + if (!IFace) + return; + IFace->setHasDesignatedInitializers(); D->addAttr(::new (S.Context) ObjCDesignatedInitializerAttr(Attr.getRange(), S.Context, @@ -5059,7 +5063,8 @@ static bool isDeclDeprecated(Decl *D) { return true; // A category implicitly has the availability of the interface. if (const ObjCCategoryDecl *CatD = dyn_cast<ObjCCategoryDecl>(D)) - return CatD->getClassInterface()->isDeprecated(); + if (const ObjCInterfaceDecl *Interface = CatD->getClassInterface()) + return Interface->isDeprecated(); } while ((D = cast_or_null<Decl>(D->getDeclContext()))); return false; } @@ -5070,7 +5075,8 @@ static bool isDeclUnavailable(Decl *D) { return true; // A category implicitly has the availability of the interface. if (const ObjCCategoryDecl *CatD = dyn_cast<ObjCCategoryDecl>(D)) - return CatD->getClassInterface()->isUnavailable(); + if (const ObjCInterfaceDecl *Interface = CatD->getClassInterface()) + return Interface->isUnavailable(); } while ((D = cast_or_null<Decl>(D->getDeclContext()))); return false; } diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index fba7a2d23ff..74779bc28c4 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -76,8 +76,8 @@ bool Sema::CanUseDecl(NamedDecl *D) { static void DiagnoseUnusedOfDecl(Sema &S, NamedDecl *D, SourceLocation Loc) { // Warn if this is used but marked unused. if (D->hasAttr<UnusedAttr>()) { - const Decl *DC = cast<Decl>(S.getCurObjCLexicalContext()); - if (!DC->hasAttr<UnusedAttr>()) + const Decl *DC = cast_or_null<Decl>(S.getCurObjCLexicalContext()); + if (DC && !DC->hasAttr<UnusedAttr>()) S.Diag(Loc, diag::warn_used_but_marked_unused) << D->getDeclName(); } } |