Skip to content

Commit eca08f1

Browse files
A pass over initialization of Arena-allocated classes
PREfast raised warnings on a number of classes about members lacking initialization before the constructor, and in many cases after it. A comparison between that list and the list of classes that we make in arena memory (where we often don't zero) gave the set addressed here in the associated files.
1 parent c203d18 commit eca08f1

18 files changed

Lines changed: 248 additions & 143 deletions

lib/Backend/FlowGraph.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ class FlowGraph
140140
loopList(nullptr),
141141
catchLabelStack(nullptr),
142142
finallyLabelStack(nullptr),
143+
leaveNullLabelStack(nullptr),
143144
regToFinallyEndMap(nullptr),
145+
leaveNullLabelToFinallyLabelMap(nullptr),
144146
hasBackwardPassInfo(false),
145147
hasLoop(false),
146148
implicitCallFlags(Js::ImplicitCall_HasNoInfo)

lib/Backend/Func.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ struct Cloner
2828
lowerer(lowerer),
2929
instrFirst(nullptr),
3030
instrLast(nullptr),
31-
fRetargetClonedBranch(FALSE)
31+
fRetargetClonedBranch(FALSE),
32+
clonedInstrGetOrigArgSlotSym(false)
3233
{
3334
}
3435

@@ -48,13 +49,13 @@ struct Cloner
4849
void Finish();
4950
void RetargetClonedBranches();
5051

52+
JitArenaAllocator *alloc;
5153
HashTable<StackSym*> *symMap;
5254
HashTable<IR::LabelInstr*> *labelMap;
5355
Lowerer * lowerer;
5456
IR::Instr * instrFirst;
5557
IR::Instr * instrLast;
5658
BOOL fRetargetClonedBranch;
57-
JitArenaAllocator *alloc;
5859
bool clonedInstrGetOrigArgSlotSym;
5960
};
6061

lib/Backend/GlobOpt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class PathDependentInfo
169169

170170
public:
171171
PathDependentInfo(const PathDependentRelationship relationship, Value *const leftValue, Value *const rightValue)
172-
: relationship(relationship), leftValue(leftValue), rightValue(rightValue)
172+
: leftValue(leftValue), rightValue(rightValue), rightConstantValue(0), relationship(relationship)
173173
{
174174
Assert(leftValue);
175175
Assert(rightValue);
@@ -180,7 +180,7 @@ class PathDependentInfo
180180
Value *const leftValue,
181181
Value *const rightValue,
182182
const int32 rightConstantValue)
183-
: relationship(relationship), leftValue(leftValue), rightValue(rightValue), rightConstantValue(rightConstantValue)
183+
: leftValue(leftValue), rightValue(rightValue), rightConstantValue(rightConstantValue), relationship(relationship)
184184
{
185185
Assert(leftValue);
186186
}

lib/Backend/IR.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class BranchJumpTableWrapper
4242
{
4343
public:
4444

45-
BranchJumpTableWrapper(uint tableSize) : defaultTarget(nullptr), labelInstr(nullptr), tableSize(tableSize)
45+
BranchJumpTableWrapper(uint tableSize) : jmpTable(nullptr), defaultTarget(nullptr), labelInstr(nullptr), tableSize(tableSize)
4646
{
4747
}
4848

@@ -832,7 +832,10 @@ class MultiBranchInstr : public BranchInstr
832832
IntConstType m_lastCaseValue;
833833

834834
MultiBranchInstr() :
835-
m_branchTargets(nullptr)
835+
m_branchTargets(nullptr),
836+
m_kind(IntJumpTable),
837+
m_baseCaseValue(0),
838+
m_lastCaseValue(0)
836839
{
837840
#if DBG
838841
m_isMultiBranch = true;

lib/Backend/Lifetime.h

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,43 @@ class Lifetime
99
{
1010
public:
1111

12-
Lifetime(JitArenaAllocator * alloc, StackSym *sym, RegNum reg, uint32 start, uint32 end, Func *func)
13-
: sym(sym), reg(reg), start(start), end(end), previousDefBlockNumber(0), defList(alloc),
14-
useList(alloc), lastUseLabel(NULL), region(NULL), isSpilled(false), useCount(0), useCountAdjust(0), allDefsCost(0), isLiveAcrossCalls(false),
15-
isLiveAcrossUserCalls(false), isDeadStore(true), isOpHelperSpilled(false), cantOpHelperSpill(false), isOpHelperSpillAsArg(false),
16-
isFloat(0), cantSpill(false), dontAllocate(false), isSecondChanceAllocated(false), isCheapSpill(false), spillStackSlot(NULL),
17-
totalOpHelperLengthByEnd(0), needsStoreCompensation(false), alloc(alloc), regionUseCount(NULL), regionUseCountAdjust(NULL),
18-
cantStackPack(false)
12+
Lifetime(JitArenaAllocator * alloc, StackSym *sym, RegNum reg, uint32 start, uint32 end)
13+
:
14+
sym(sym),
15+
regionUseCount(nullptr),
16+
regionUseCountAdjust(nullptr),
17+
defList(alloc),
18+
useList(alloc),
19+
lastUseLabel(nullptr),
20+
region(nullptr),
21+
spillStackSlot(nullptr),
22+
alloc(alloc),
23+
intUsageBv(0),
24+
regPreference(0),
25+
start(start),
26+
end(end),
27+
previousDefBlockNumber(0),
28+
useCount(0),
29+
useCountAdjust(0),
30+
allDefsCost(0),
31+
lastAllocationStart(0),
32+
reg(reg),
33+
totalOpHelperLengthByEnd(0),
34+
isSpilled(false),
35+
isLiveAcrossCalls(false),
36+
isLiveAcrossUserCalls(false),
37+
isDeadStore(true),
38+
isOpHelperSpilled(false),
39+
isOpHelperSpillAsArg(false),
40+
cantOpHelperSpill(false),
41+
cantSpill(false),
42+
dontAllocate(false),
43+
isSecondChanceAllocated(false),
44+
isCheapSpill(false),
45+
needsStoreCompensation(false),
46+
cantStackPack(false),
47+
isFloat(false)
1948
{
20-
intUsageBv.ClearAll();
21-
regPreference.ClearAll();
2249
}
2350

2451
public:

lib/Backend/SccLiveness.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ Lifetime *
722722
SCCLiveness::InsertLifetime(StackSym *stackSym, RegNum reg, IR::Instr *const currentInstr)
723723
{
724724
const uint start = currentInstr->GetNumber(), end = start;
725-
Lifetime * newLlifetime = JitAnew(tempAlloc, Lifetime, tempAlloc, stackSym, reg, start, end, this->func);
725+
Lifetime * newLlifetime = JitAnew(tempAlloc, Lifetime, tempAlloc, stackSym, reg, start, end);
726726
newLlifetime->totalOpHelperLengthByEnd = this->totalOpHelperFullVisitedLength + CurrentOpHelperVisitedLength(currentInstr);
727727

728728
// Find insertion point

lib/Backend/SymTable.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ class SymTable
2424
PropertyEquivBvMap *m_propertyEquivBvMap;
2525

2626
public:
27-
SymTable() : m_currentID(0), m_func(nullptr), m_IDAdjustment(0)
27+
SymTable() :
28+
m_table{ nullptr },
29+
m_implicitParams{ nullptr },
30+
m_propertyMap(nullptr),
31+
m_func(nullptr),
32+
m_currentID(0),
33+
m_IDAdjustment(0)
2834
{
29-
memset(m_table, 0, sizeof(m_table));
30-
memset(m_implicitParams, 0, sizeof(m_implicitParams));
3135
}
3236

3337

lib/Backend/ValueInfo.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ class ValueInfo : protected ValueType
3535

3636
protected:
3737
ValueInfo(const ValueType type, const ValueStructureKind structureKind)
38-
: ValueType(type), structureKind(structureKind)
38+
: ValueType(type), structureKind(structureKind), symStore(nullptr)
3939
{
4040
// We can only prove that the representation is a tagged int on a ToVar. Currently, we cannot have more than one value
4141
// info per value number in a block, so a value info specifying tagged int representation cannot be created for a
4242
// specific sym. Instead, a value info can be shared by multiple syms, and hence cannot specify tagged int
4343
// representation. Currently, the tagged int representation info can only be carried on the dst opnd of ToVar, and can't
4444
// even be propagated forward.
4545
Assert(!type.IsTaggedInt());
46-
47-
SetSymStore(nullptr);
4846
}
4947

5048
private:
5149
ValueInfo(const ValueInfo &other, const bool)
52-
: ValueType(other), structureKind(ValueStructureKind::Generic) // uses generic structure kind, as opposed to copying the structure kind
50+
: ValueType(other),
51+
structureKind(ValueStructureKind::Generic), // uses generic structure kind, as opposed to copying the structure kind
52+
symStore(nullptr) // Will be immediately overridden
5353
{
5454
SetSymStore(other.GetSymStore());
5555
}

lib/Parser/Parse.cpp

Lines changed: 86 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ struct StmtNest
5656
};
5757
StmtNest *pstmtOuter; // Enclosing statement.
5858

59-
OpCode GetNop() const
60-
{
59+
OpCode GetNop() const
60+
{
6161
AnalysisAssert(isDeferred || pnodeStmt != nullptr);
62-
return isDeferred ? op : pnodeStmt->nop;
62+
return isDeferred ? op : pnodeStmt->nop;
6363
}
6464
};
6565

@@ -78,63 +78,85 @@ Parser::Parser(Js::ScriptContext* scriptContext, BOOL strictMode, PageAllocator
7878
Parser::Parser(Js::ScriptContext* scriptContext, BOOL strictMode, PageAllocator *alloc, bool isBackground)
7979
#endif
8080
: m_nodeAllocator(_u("Parser"), alloc ? alloc : scriptContext->GetThreadContext()->GetPageAllocator(), Parser::OutOfMemory),
81+
m_cactIdentToNodeLookup(0),
82+
m_grfscr(fscrNil),
83+
m_length(0),
84+
m_originalLength(0),
85+
m_nextFunctionId(nullptr),
86+
m_sourceContextInfo(nullptr),
87+
#if ENABLE_BACKGROUND_PARSING
88+
m_isInBackground(isBackground),
89+
m_hasParallelJob(false),
90+
m_doingFastScan(false),
91+
#endif
92+
m_nextBlockId(0),
8193
// use the GuestArena directly for keeping the RegexPattern* alive during byte code generation
82-
m_registeredRegexPatterns(scriptContext->GetGuestArena())
94+
m_registeredRegexPatterns(scriptContext->GetGuestArena()),
95+
96+
m_scriptContext(scriptContext),
97+
m_phtbl(nullptr),
98+
99+
m_token(), // should initialize to 0/nullptrs
100+
m_pscan(nullptr),
101+
102+
m_currentNodeNonLambdaFunc(nullptr),
103+
m_currentNodeNonLambdaDeferredFunc(nullptr),
104+
m_currentNodeFunc(nullptr),
105+
m_currentNodeDeferredFunc(nullptr),
106+
m_currentNodeProg(nullptr),
107+
m_currDeferredStub(nullptr),
108+
m_prevSiblingDeferredStub(nullptr),
109+
m_pCurrentAstSize(nullptr),
110+
m_ppnodeScope(nullptr),
111+
m_ppnodeExprScope(nullptr),
112+
m_ppnodeVar(nullptr),
113+
m_inDeferredNestedFunc(false),
114+
m_reparsingLambdaParams(false),
115+
m_disallowImportExportStmt(false),
116+
m_isInParsingArgList(false),
117+
m_hasDestructuringPattern(false),
118+
m_hasDeferredShorthandInitError(false),
119+
m_pnestedCount(nullptr),
120+
121+
wellKnownPropertyPids(), // should initialize to nullptrs
122+
m_sourceLim(0),
123+
m_functionBody(nullptr),
124+
m_parseType(ParseType_Upfront),
125+
126+
m_arrayDepth(0),
127+
m_funcInArrayDepth(0),
128+
m_funcInArray(0),
129+
m_scopeCountNoAst(0),
130+
131+
m_parsingSuperRestrictionState(ParsingSuperRestrictionState_SuperDisallowed),
132+
133+
m_funcParenExprDepth(0),
134+
m_deferEllipsisError(false),
135+
m_deferEllipsisErrorLoc(), // calls default initializer
136+
137+
m_tryCatchOrFinallyDepth(0),
138+
139+
m_pstmtCur(nullptr),
140+
m_currentBlockInfo(nullptr),
141+
m_currentScope(nullptr),
142+
143+
currBackgroundParseItem(nullptr),
144+
backgroundParseItems(nullptr),
145+
fastScannedRegExpNodes(nullptr),
146+
147+
m_currentDynamicBlock(nullptr),
148+
149+
m_UsesArgumentsAtGlobal(false),
150+
151+
m_fUseStrictMode(strictMode),
152+
m_InAsmMode(false),
153+
m_deferAsmJs(true),
154+
m_fExpectExternalSource(FALSE),
155+
m_deferringAST(FALSE),
156+
m_stoppedDeferredParse(FALSE)
83157
{
84158
AssertMsg(size == sizeof(Parser), "verify conditionals affecting the size of Parser agree");
85159
Assert(scriptContext != nullptr);
86-
m_phtbl = nullptr;
87-
m_pscan = nullptr;
88-
m_deferringAST = FALSE;
89-
m_stoppedDeferredParse = FALSE;
90-
#if ENABLE_BACKGROUND_PARSING
91-
m_isInBackground = isBackground;
92-
m_hasParallelJob = false;
93-
m_doingFastScan = false;
94-
#endif
95-
m_isInParsingArgList = false;
96-
m_hasDestructuringPattern = false;
97-
m_scriptContext = scriptContext;
98-
m_pCurrentAstSize = nullptr;
99-
m_arrayDepth = 0;
100-
m_funcInArrayDepth = 0;
101-
m_funcParenExprDepth = 0;
102-
m_funcInArray = 0;
103-
m_tryCatchOrFinallyDepth = 0;
104-
m_UsesArgumentsAtGlobal = false;
105-
m_currentNodeFunc = nullptr;
106-
m_currentNodeDeferredFunc = nullptr;
107-
m_currentNodeNonLambdaFunc = nullptr;
108-
m_currentNodeNonLambdaDeferredFunc = nullptr;
109-
m_currentNodeProg = nullptr;
110-
m_currDeferredStub = nullptr;
111-
m_prevSiblingDeferredStub = nullptr;
112-
m_pstmtCur = nullptr;
113-
m_currentBlockInfo = nullptr;
114-
m_currentScope = nullptr;
115-
m_currentDynamicBlock = nullptr;
116-
m_grfscr = fscrNil;
117-
m_length = 0;
118-
m_originalLength = 0;
119-
m_nextFunctionId = nullptr;
120-
m_reparsingLambdaParams = false;
121-
currBackgroundParseItem = nullptr;
122-
backgroundParseItems = nullptr;
123-
fastScannedRegExpNodes = nullptr;
124-
125-
m_fUseStrictMode = strictMode;
126-
m_InAsmMode = false;
127-
m_deferAsmJs = true;
128-
m_scopeCountNoAst = 0;
129-
m_fExpectExternalSource = 0;
130-
131-
m_parseType = ParseType_Upfront;
132-
133-
m_deferEllipsisError = false;
134-
m_hasDeferredShorthandInitError = false;
135-
m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperDisallowed;
136-
137-
m_disallowImportExportStmt = false;
138160
}
139161

140162
Parser::~Parser(void)
@@ -5429,7 +5451,7 @@ bool Parser::ParseFncDeclHelper(ParseNodePtr pnodeFnc, LPCOLESTR pNameHint, usho
54295451
}
54305452

54315453
// These are heuristic conditions that prohibit upfront deferral but not redeferral.
5432-
isTopLevelDeferredFunc = isTopLevelDeferredFunc && !isDeferredFnc &&
5454+
isTopLevelDeferredFunc = isTopLevelDeferredFunc && !isDeferredFnc &&
54335455
(!isLikelyIIFE || !topLevelStmt || PHASE_FORCE_RAW(Js::DeferParsePhase, m_sourceContextInfo->sourceContextId, pnodeFnc->sxFnc.functionId));
54345456

54355457
#if ENABLE_BACKGROUND_PARSING
@@ -6559,7 +6581,7 @@ bool Parser::ParseFncNames(ParseNodePtr pnodeFnc, ParseNodePtr pnodeFncParent, u
65596581
{
65606582
// Multiple names. Turn the source into an IdentPtr.
65616583
pnodeFnc->sxFnc.pid = m_phtbl->PidHashNameLen(
6562-
m_pscan->PchBase() + ichMinNames,
6584+
m_pscan->PchBase() + ichMinNames,
65636585
m_pscan->AdjustedLast(),
65646586
ichLimNames - ichMinNames);
65656587
}
@@ -7249,7 +7271,7 @@ void Parser::FinishFncNode(ParseNodePtr pnodeFnc)
72497271
else
72507272
{
72517273
m_pscan->SetCurrentCharacter(pnodeFnc->ichMin, pnodeFnc->sxFnc.lineNumber);
7252-
7274+
72537275
if (fMethod)
72547276
{
72557277
// Method. Skip identifier name, computed property name, "async", "get", "set", and '*' or '(' characters.
@@ -8866,7 +8888,7 @@ ParseNodePtr Parser::ParseExpr(int oplMin,
88668888

88678889
ParseDestructuredLiteralWithScopeSave(tkLCurly, false/*isDecl*/, false /*topLevel*/, DIC_ShouldNotParseInitializer);
88688890

8869-
// Restore the Block ID at the end of the reparsing so it matches the one at the end of the first pass. We need to do this
8891+
// Restore the Block ID at the end of the reparsing so it matches the one at the end of the first pass. We need to do this
88708892
// because we don't parse initializers during reparse and there may be additional blocks (e.g. a class declaration)
88718893
// in the initializers that will cause the next Block ID at the end of the reparsing to be different.
88728894
m_nextBlockId = saveNextBlockId;
@@ -8976,9 +8998,9 @@ ParseNodePtr Parser::ParseExpr(int oplMin,
89768998
}
89778999

89789000
// Assignment stmt of the form "this.<id> = <expr>"
8979-
if (nop == knopAsg
8980-
&& pnode->nop == knopDot
8981-
&& pnode->sxBin.pnode1->nop == knopName
9001+
if (nop == knopAsg
9002+
&& pnode->nop == knopDot
9003+
&& pnode->sxBin.pnode1->nop == knopName
89829004
&& pnode->sxBin.pnode1->sxVar.pid == wellKnownPropertyPids._this
89839005
&& pnode->sxBin.pnode2->nop == knopName)
89849006
{
@@ -12761,7 +12783,7 @@ IdentPtr Parser::ParseSuper(bool fAllowCall)
1276112783
// Anything else is an error
1276212784
Error(ERRInvalidSuper);
1276312785
}
12764-
12786+
1276512787
return superPid;
1276612788
}
1276712789

0 commit comments

Comments
 (0)