diff options
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 90 |
1 files changed, 24 insertions, 66 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index ffe72c9..e7cb204 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #include "TreeTransform.h" +#include "UsedDeclVisitor.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" #include "clang/AST/ASTLambda.h" @@ -15898,13 +15899,8 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, Func->markUsed(Context); } - if (LangOpts.OpenMP) { + if (LangOpts.OpenMP) markOpenMPDeclareVariantFuncsReferenced(Loc, Func, MightBeOdrUse); - if (LangOpts.OpenMPIsDevice) - checkOpenMPDeviceFunction(Loc, Func); - else - checkOpenMPHostFunction(Loc, Func); - } } /// Directly mark a variable odr-used. Given a choice, prefer to use @@ -17296,71 +17292,33 @@ void Sema::MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T) { } namespace { - /// Helper class that marks all of the declarations referenced by - /// potentially-evaluated subexpressions as "referenced". - class EvaluatedExprMarker : public EvaluatedExprVisitor<EvaluatedExprMarker> { - Sema &S; - bool SkipLocalVariables; - - public: - typedef EvaluatedExprVisitor<EvaluatedExprMarker> Inherited; - - EvaluatedExprMarker(Sema &S, bool SkipLocalVariables) - : Inherited(S.Context), S(S), SkipLocalVariables(SkipLocalVariables) { } - - void VisitDeclRefExpr(DeclRefExpr *E) { - // If we were asked not to visit local variables, don't. - if (SkipLocalVariables) { - if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) - if (VD->hasLocalStorage()) - return; - } - - S.MarkDeclRefReferenced(E); - } - - void VisitMemberExpr(MemberExpr *E) { - S.MarkMemberReferenced(E); - Inherited::VisitMemberExpr(E); - } - - void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { - S.MarkFunctionReferenced( - E->getBeginLoc(), - const_cast<CXXDestructorDecl *>(E->getTemporary()->getDestructor())); - Visit(E->getSubExpr()); - } - - void VisitCXXNewExpr(CXXNewExpr *E) { - if (E->getOperatorNew()) - S.MarkFunctionReferenced(E->getBeginLoc(), E->getOperatorNew()); - if (E->getOperatorDelete()) - S.MarkFunctionReferenced(E->getBeginLoc(), E->getOperatorDelete()); - Inherited::VisitCXXNewExpr(E); - } +/// Helper class that marks all of the declarations referenced by +/// potentially-evaluated subexpressions as "referenced". +class EvaluatedExprMarker : public UsedDeclVisitor<EvaluatedExprMarker> { +public: + typedef UsedDeclVisitor<EvaluatedExprMarker> Inherited; + bool SkipLocalVariables; - void VisitCXXDeleteExpr(CXXDeleteExpr *E) { - if (E->getOperatorDelete()) - S.MarkFunctionReferenced(E->getBeginLoc(), E->getOperatorDelete()); - QualType Destroyed = S.Context.getBaseElementType(E->getDestroyedType()); - if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { - CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); - S.MarkFunctionReferenced(E->getBeginLoc(), S.LookupDestructor(Record)); - } + EvaluatedExprMarker(Sema &S, bool SkipLocalVariables) + : Inherited(S), SkipLocalVariables(SkipLocalVariables) {} - Inherited::VisitCXXDeleteExpr(E); - } + void visitUsedDecl(SourceLocation Loc, Decl *D) { + S.MarkFunctionReferenced(Loc, cast<FunctionDecl>(D)); + } - void VisitCXXConstructExpr(CXXConstructExpr *E) { - S.MarkFunctionReferenced(E->getBeginLoc(), E->getConstructor()); - Inherited::VisitCXXConstructExpr(E); + void VisitDeclRefExpr(DeclRefExpr *E) { + // If we were asked not to visit local variables, don't. + if (SkipLocalVariables) { + if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) + if (VD->hasLocalStorage()) + return; } + S.MarkDeclRefReferenced(E); + } - void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { - Visit(E->getExpr()); - } - }; -} + void VisitMemberExpr(MemberExpr *E) { S.MarkMemberReferenced(E); } +}; +} // namespace /// Mark any declarations that appear within this expression or any /// potentially-evaluated subexpressions as "referenced". |