From 0dd7a25e8d679de1dc0ce788222d6dee0e879885 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Mon, 5 Dec 2011 20:16:26 +0000 Subject: [PATCH] Make isWeakDecl available as a method on ValueDecl. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145845 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Decl.h | 6 ++++++ lib/AST/ExprConstant.cpp | 12 +++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 28a01cf04e..c8120eb361 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -508,6 +508,12 @@ public: QualType getType() const { return DeclType; } void setType(QualType newType) { DeclType = newType; } + /// \brief Determine whether this symbol is weakly-imported, + /// or declared with the weak or weak-ref attr. + bool isWeak() const { + return hasAttr() || hasAttr() || isWeakImported(); + } + // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classof(const ValueDecl *D) { return true; } diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 81fe7e3a4e..438bef5de8 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -580,15 +580,9 @@ static bool IsLiteralLValue(const LValue &Value) { return Value.Base.dyn_cast() && !Value.Frame; } -static bool IsWeakDecl(const ValueDecl *Decl) { - return Decl->hasAttr() || - Decl->hasAttr() || - Decl->isWeakImported(); -} - static bool IsWeakLValue(const LValue &Value) { const ValueDecl *Decl = GetLValueBaseDecl(Value); - return Decl && IsWeakDecl(Decl); + return Decl && Decl->isWeak(); } static bool EvalPointerValueAsBool(const CCValue &Value, bool &Result) { @@ -607,7 +601,7 @@ static bool EvalPointerValueAsBool(const CCValue &Value, bool &Result) { // a weak declaration it can be null at runtime. Result = true; const ValueDecl *Decl = Value.getLValueBase().dyn_cast(); - return !Decl || !IsWeakDecl(Decl); + return !Decl || !Decl->isWeak(); } static bool HandleConversionToBool(const CCValue &Val, bool &Result) { @@ -866,7 +860,7 @@ static bool EvaluateVarDeclInit(EvalInfo &Info, const VarDecl *VD, // Never evaluate the initializer of a weak variable. We can't be sure that // this is the definition which will be used. - if (IsWeakDecl(VD)) + if (VD->isWeak()) return false; const Expr *Init = VD->getAnyInitializer(); -- 2.40.0