clang: lib/Sema/ScopeInfo.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

20

21using namespace clang;

22using namespace sema;

23

43

44

51

54 ErrorTrap.reset();

56 WeakObjectUses.clear();

61}

62

66

68}

69

70FunctionScopeInfo::WeakObjectProfileTy::BaseInfoTy

71FunctionScopeInfo::WeakObjectProfileTy::getBaseInfo(const Expr *E) {

73

75 bool IsExact = false;

76

78 case Stmt::DeclRefExprClass:

79 D = cast(E)->getDecl();

80 IsExact = isa(D);

81 break;

82 case Stmt::MemberExprClass: {

83 const MemberExpr *ME = cast(E);

86 break;

87 }

88 case Stmt::ObjCIvarRefExprClass: {

92 break;

93 }

94 case Stmt::PseudoObjectExprClass: {

98 if (BaseProp) {

100

102 const Expr *DoubleBase = BaseProp->getBase();

103 if (const OpaqueValueExpr *OVE = dyn_cast(DoubleBase))

104 DoubleBase = OVE->getSourceExpr();

105

107 }

108 }

109 break;

110 }

111 default:

112 break;

113 }

114

115 return BaseInfoTy(D, IsExact);

116}

117

118FunctionScopeInfo::WeakObjectProfileTy::WeakObjectProfileTy(

121

125 Base = getBaseInfo(E);

128 } else {

130 }

131}

132

133FunctionScopeInfo::WeakObjectProfileTy::WeakObjectProfileTy(const Expr *BaseE,

136 if (BaseE)

137 Base = getBaseInfo(BaseE);

138

139}

140

141FunctionScopeInfo::WeakObjectProfileTy::WeakObjectProfileTy(

144 assert(isa(Property));

145}

146

147FunctionScopeInfo::WeakObjectProfileTy::WeakObjectProfileTy(

149 : Base(getBaseInfo(IvarE->getBase())), Property(IvarE->getDecl()) {

150}

151

154 assert(Msg && Prop);

158}

159

162

163 if (const PseudoObjectExpr *POE = dyn_cast(E)) {

165 return;

166 }

167

171 return;

172 }

173

175 dyn_cast(E)) {

178 return;

179 }

180

181

182 FunctionScopeInfo::WeakObjectUseMap::iterator Uses = WeakObjectUses.end();

184 if (!RefExpr->isObjectReceiver())

185 return;

186 if (isa(RefExpr->getBase()))

188 else {

190 return;

191 }

192 }

193 else if (const ObjCIvarRefExpr *IvarE = dyn_cast(E))

195 else if (const DeclRefExpr *DRE = dyn_cast(E)) {

196 if (isa(DRE->getDecl()))

198 } else if (const ObjCMessageExpr *MsgE = dyn_cast(E)) {

199 if (const ObjCMethodDecl *MD = MsgE->getMethodDecl()) {

201 Uses =

203 Prop));

204 }

205 }

206 }

207 else

208 return;

209

210 if (Uses == WeakObjectUses.end())

211 return;

212

213

214 FunctionScopeInfo::WeakUseVector::reverse_iterator ThisUse =

215 llvm::find(llvm::reverse(Uses->second), WeakUseTy(E, true));

216 if (ThisUse == Uses->second.rend())

217 return;

218

219 ThisUse->markSafe();

220}

221

223

224

225 return !isNested() && isVariableCapture() && getVariable()->isInitCapture();

226}

227

229 for (auto &Cap : Captures)

230 if (Cap.isVLATypeCapture() && Cap.getCapturedVLAType() == VAT)

231 return true;

232 return false;

233}

234

236 llvm::function_ref<void(ValueDecl *, Expr *)> Callback) const {

237 for (Expr *E : PotentiallyCapturingExprs) {

238 if (auto *DRE = dyn_cast(E)) {

239 Callback(cast(DRE->getFoundDecl()), E);

240 } else if (auto *ME = dyn_cast(E)) {

242 } else if (auto *FP = dyn_cast(E)) {

244 Callback(VD, E);

245 } else {

246 llvm_unreachable("unexpected expression in potential captures list");

247 }

248 }

249}

250

252 if (ExplicitObjectParameter)

253 return ExplicitObjectParameter->getType()

254 .getNonReferenceType()

255 .isConstQualified();

256 return !Mutable;

257}

258

Defines the clang::Expr interface and subclasses for C++ expressions.

static const NamedDecl * getBestPropertyDecl(const ObjCPropertyRefExpr *PropE)

BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...

ConditionalOperator - The ?: ternary operator.

A reference to a declared variable, function, enum, etc.

void reset()

Set to initial state of "no errors occurred".

This represents one expression.

Expr * IgnoreParenCasts() LLVM_READONLY

Skip past any parentheses and casts which might surround this expression until reaching a fixed point...

Expr * IgnoreParenImpCasts() LLVM_READONLY

Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...

bool isObjCSelfExpr() const

Check if this expression is the ObjC 'self' implicit parameter.

MemberExpr - [C99 6.5.2.3] Structure and Union Members.

ValueDecl * getMemberDecl() const

Retrieve the member declaration to which this expression refers.

This represents a decl that may have a name.

ObjCIvarRefExpr - A reference to an ObjC instance variable.

const Expr * getBase() const

An expression that sends a message to the given Objective-C object or class.

Expr * getInstanceReceiver()

Returns the object expression (receiver) for an instance message, or null for a message that is not a...

unsigned getNumArgs() const

Return the number of actual arguments in this message, not counting the receiver.

ObjCMethodDecl - Represents an instance or class method declaration.

Represents one property declaration in an Objective-C interface.

static ObjCPropertyDecl * findPropertyDecl(const DeclContext *DC, const IdentifierInfo *propertyID, ObjCPropertyQueryKind queryKind)

Lookup a property by name in the specified DeclContext.

ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.

ObjCPropertyDecl * getExplicitProperty() const

ObjCMethodDecl * getImplicitPropertyGetter() const

const Expr * getBase() const

bool isObjectReceiver() const

bool isExplicitProperty() const

ObjCInterfaceDecl * getClassReceiver() const

bool isClassReceiver() const

bool isSuperReceiver() const

OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.

Expr * getSourceExpr() const

The source expression of an opaque value expression is the expression which originally generated the ...

PseudoObjectExpr - An expression which accesses a pseudo-object l-value.

Expr * getSyntacticForm()

Return the syntactic form of this expression, i.e.

Encodes a location in the source.

StmtClass getStmtClass() const

Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...

Represents a C array with a specified size that is not an integer-constant-expression.

~BlockScopeInfo() override

bool isInitCapture() const

Determine whether this capture is an init-capture.

~CapturedRegionScopeInfo() override

bool isVLATypeCaptured(const VariableArrayType *VAT) const

Determine whether the given variable-array type has been captured.

Represents a simple identification of a weak object.

Represents a single use of a weak object.

SmallVector< ReturnStmt *, 4 > Returns

The list of return statements that occur within the function or block, if there is any chance of appl...

bool HasIndirectGoto

Whether this function contains any indirect gotos.

bool HasFallthroughStmt

Whether there is a fallthrough statement in this function.

SourceLocation FirstVLALoc

First use of a VLA within the current function.

SourceLocation FirstCXXOrObjCTryLoc

First C++ 'try' or ObjC @try statement in the current function.

bool UsesFPIntrin

Whether this function uses constrained floating point intrinsics.

llvm::SmallMapVector< ParmVarDecl *, Stmt *, 4 > CoroutineParameterMoves

A mapping between the coroutine function parameters that were moved to the coroutine frame,...

void recordUseOfWeak(const ExprT *E, bool IsRead=true)

Record that a weak object was accessed.

bool HasDroppedStmt

Whether a statement was dropped because it was invalid.

void markSafeWeakUse(const Expr *E)

Record that a given expression is a "safe" access of a weak object (e.g.

SourceLocation FirstCoroutineStmtLoc

First coroutine statement in the current function.

bool FoundImmediateEscalatingExpression

Whether we found an immediate-escalating expression.

std::pair< Stmt *, Stmt * > CoroutineSuspends

The initial and final coroutine suspend points.

bool ObjCIsDesignatedInit

True when this is a method marked as a designated initializer.

void Clear()

Clear out the information in this function scope, making it suitable for reuse.

bool ObjCShouldCallSuper

A flag that is set when parsing a method that must call super's implementation, such as -dealloc,...

VarDecl * CoroutinePromise

The promise object for this coroutine, if any.

bool HasBranchProtectedScope

Whether this function contains a VLA, @try, try, C++ initializer, or anything else that can't be jump...

SmallVector< PossiblyUnreachableDiag, 4 > PossiblyUnreachableDiags

A list of PartialDiagnostics created but delayed within the current function scope.

bool ObjCWarnForNoInitDelegation

This starts true for a secondary initializer method and will be set to false if there is an invocatio...

bool HasPotentialAvailabilityViolations

Whether we make reference to a declaration that could be unavailable.

SourceLocation FirstReturnLoc

First 'return' statement in the current function.

bool HasBranchIntoScope

Whether this function contains any switches or direct gotos.

SourceLocation FirstSEHTryLoc

First SEH '__try' statement in the current function.

llvm::SmallPtrSet< const BlockDecl *, 1 > Blocks

The set of blocks that are introduced in this function.

bool ObjCIsSecondaryInit

True when this is an initializer method not marked as a designated initializer within a class that ha...

bool NeedsCoroutineSuspends

True only when this function has not already built, or attempted to build, the initial and final coro...

llvm::SmallVector< AddrLabelExpr *, 4 > AddrLabels

The set of GNU address of label extension "&&label".

llvm::TinyPtrVector< VarDecl * > ByrefBlockVars

The set of __block variables that are introduced in this function.

bool ObjCWarnForNoDesignatedInitChain

This starts true for a method marked as designated initializer and will be set to false if there is a...

SmallVector< SwitchInfo, 8 > SwitchStack

SwitchStack - This is the current set of active switch statements in the block.

bool HasOMPDeclareReductionCombiner

True if current scope is for OpenMP declare reduction combiner.

virtual ~FunctionScopeInfo()

llvm::SmallPtrSet< const ParmVarDecl *, 8 > ModifiedNonNullParams

A list of parameters which have the nonnull attribute and are modified in the function.

bool lambdaCaptureShouldBeConst() const

void visitPotentialCaptures(llvm::function_ref< void(ValueDecl *, Expr *)> Callback) const

The JSON file list parser is used to communicate input to InstallAPI.

@ Property

The type of a property.