@@ -142,10 +142,7 @@ class ConstraintVariable {
142
142
virtual bool solutionEqualTo (Constraints &, const ConstraintVariable *,
143
143
bool ComparePtyp = true ) const = 0;
144
144
145
- virtual void constrainToWild (Constraints &CS,
146
- const std::string &Rsn) const = 0;
147
- virtual void constrainToWild (Constraints &CS, const std::string &Rsn,
148
- PersistentSourceLoc *PL) const = 0;
145
+ virtual void constrainToWild (Constraints &CS, const ReasonLoc &Rsn) const = 0;
149
146
150
147
// Return true if this variable was checked in the input. Checked variables
151
148
// might solve to WILD, and unchecked variables might solve to checked. Use
@@ -177,7 +174,7 @@ class ConstraintVariable {
177
174
virtual bool hasNtArr (const EnvironmentMap &E, int AIdx = -1 ) const = 0;
178
175
179
176
// Force use of equality constraints in function calls for this CV
180
- virtual void equateArgumentConstraints (ProgramInfo &I) = 0;
177
+ virtual void equateArgumentConstraints (ProgramInfo &I, ReasonLoc &Rsn ) = 0;
181
178
182
179
// Internally combine the constraints and other data from the first parameter
183
180
// with this constraint variable. Used with redeclarations, especially of
@@ -208,17 +205,25 @@ class ConstraintVariable {
208
205
// achieve that, we additionally constrain the internal variables to not
209
206
// change.
210
207
//
211
- // Some cases in which the itype must not change at all are indicated by
212
- // passing a reason for the "root cause of wildness" as ReasonUnchangeable.
213
- // Otherwise ReasonUnchangeable should be set to the empty string.
208
+ // Some cases in which the itype needs to be constrained not change at all are
209
+ // indicated by passing a non-default reason for the "root cause of wildness"
210
+ // in ReasonUnchangeable. If the reason is DEFAULT_REASON, this is a sentinel
211
+ // meaning that the caller is not requesting such a constraint. Other cases
212
+ // that need the constraint are detected within equateWithItype itself, and
213
+ // the appropriate reason is attached there.
214
+ //
215
+ // TODO: It looks like there may be some unusual cases in which
216
+ // equateWithType generates constraints using the reason from
217
+ // ReasonUnchangeable even if it is the DEFAULT_REASON sentinel. Rethink the
218
+ // equateWithItype design to figure out what reason should actually be used or
219
+ // if those constraints should be generated at all.
214
220
virtual void equateWithItype (ProgramInfo &CS,
215
- const std::string &ReasonUnchangeable,
216
- PersistentSourceLoc *PSL) = 0;
221
+ const ReasonLoc &ReasonUnchangeable) = 0;
217
222
218
223
// Copy this variable and replace all VarAtoms with fresh VarAtoms. Using
219
224
// fresh atoms allows the new variable to solve to different types than the
220
225
// original.
221
- virtual ConstraintVariable *getCopy (Constraints &CS) = 0;
226
+ virtual ConstraintVariable *getCopy (ReasonLoc &Rsn, Constraints &CS) = 0;
222
227
223
228
virtual ~ConstraintVariable (){};
224
229
};
@@ -230,15 +235,15 @@ enum ConsAction { Safe_to_Wild, Wild_to_Safe, Same_to_Same };
230
235
231
236
void constrainConsVarGeq (const std::set<ConstraintVariable *> &LHS,
232
237
const std::set<ConstraintVariable *> &RHS,
233
- Constraints &CS, PersistentSourceLoc *PL ,
238
+ Constraints &CS, const ReasonLoc &Rsn ,
234
239
ConsAction CA, bool DoEqType, ProgramInfo *Info,
235
240
bool HandleBoundsKey = true );
236
241
void constrainConsVarGeq (ConstraintVariable *LHS, const CVarSet &RHS,
237
- Constraints &CS, PersistentSourceLoc *PL ,
242
+ Constraints &CS, const ReasonLoc &Rsn ,
238
243
ConsAction CA, bool DoEqType, ProgramInfo *Info,
239
244
bool HandleBoundsKey = true );
240
245
void constrainConsVarGeq (ConstraintVariable *LHS, ConstraintVariable *RHS,
241
- Constraints &CS, PersistentSourceLoc *PL ,
246
+ Constraints &CS, const ReasonLoc &Rsn ,
242
247
ConsAction CA, bool DoEqType, ProgramInfo *Info,
243
248
bool HandleBoundsKey = true );
244
249
@@ -276,8 +281,7 @@ class PointerVariableConstraint : public ConstraintVariable {
276
281
// This causes problems if the variable is later used as a deeper
277
282
// pointer type. See correctcomputation/checkedc-clang#673.
278
283
static PointerVariableConstraint *
279
- getWildPVConstraint (Constraints &CS, const std::string &Rsn,
280
- PersistentSourceLoc *PSL = nullptr );
284
+ getWildPVConstraint (Constraints &CS, const ReasonLoc &Rsn);
281
285
282
286
// Get constraint variables representing values that are not pointers. If a
283
287
// meaningful name can be assigned to the value, the second method should be
@@ -292,7 +296,7 @@ class PointerVariableConstraint : public ConstraintVariable {
292
296
// by the original constraint variable.
293
297
static PointerVariableConstraint *
294
298
addAtomPVConstraint (PointerVariableConstraint *PVC, ConstAtom *PtrTyp,
295
- Constraints &CS);
299
+ ReasonLoc &Rsn, Constraints &CS);
296
300
297
301
// Return a new constraint variable representing the result of dereferencing
298
302
// the input constraint variable. This is accomplished by first copying the
@@ -518,12 +522,11 @@ class PointerVariableConstraint : public ConstraintVariable {
518
522
void dump () const override { print (llvm::errs ()); }
519
523
void dumpJson (llvm::raw_ostream &O) const override ;
520
524
521
- void constrainToWild (Constraints &CS, const std::string &Rsn) const override ;
522
- void constrainToWild (Constraints &CS, const std::string &Rsn,
523
- PersistentSourceLoc *PL) const override ;
524
- void constrainOuterTo (Constraints &CS, ConstAtom *C, bool DoLB = false ,
525
- bool Soft = false );
525
+ void constrainToWild (Constraints &CS, const ReasonLoc &Rsn) const override ;
526
+ void constrainOuterTo (Constraints &CS, ConstAtom *C, const ReasonLoc &Rsn,
527
+ bool DoLB = false , bool Soft = false );
526
528
void constrainIdxTo (Constraints &CS, ConstAtom *C, unsigned int Idx,
529
+ const ReasonLoc &Rsn,
527
530
bool DoLB = false , bool Soft = false );
528
531
bool anyChanges (const EnvironmentMap &E) const override ;
529
532
bool anyArgumentIsWild (const EnvironmentMap &E);
@@ -535,15 +538,16 @@ class PointerVariableConstraint : public ConstraintVariable {
535
538
bool isConstantArr () const ;
536
539
unsigned long getConstantArrSize () const ;
537
540
538
- void equateArgumentConstraints (ProgramInfo &I) override ;
541
+ void equateArgumentConstraints (ProgramInfo &I, ReasonLoc &Rsn ) override ;
539
542
540
543
bool isPartOfFunctionPrototype () const { return PartOfFuncPrototype; }
541
544
// Add the provided constraint variable as an argument constraint.
542
- bool addArgumentConstraint (ConstraintVariable *DstCons, ProgramInfo &Info);
545
+ bool addArgumentConstraint (ConstraintVariable *DstCons,
546
+ ReasonLoc &Rsn, ProgramInfo &Info);
543
547
// Get the set of constraint variables corresponding to the arguments.
544
548
const std::set<ConstraintVariable *> &getArgumentConstraints () const ;
545
549
546
- PointerVariableConstraint *getCopy (Constraints &CS) override ;
550
+ PointerVariableConstraint *getCopy (ReasonLoc &Rsn, Constraints &CS) override ;
547
551
548
552
// Retrieve the atom at the specified index. This function includes special
549
553
// handling for generic constraint variables to create deeper pointers as
@@ -552,8 +556,8 @@ class PointerVariableConstraint : public ConstraintVariable {
552
556
553
557
~PointerVariableConstraint () override {};
554
558
555
- void equateWithItype (ProgramInfo &CS, const std::string &ReasonUnchangeable,
556
- PersistentSourceLoc *PSL ) override ;
559
+ void equateWithItype (ProgramInfo &CS,
560
+ const ReasonLoc &ReasonUnchangeable ) override ;
557
561
};
558
562
559
563
typedef PointerVariableConstraint PVConstraint;
@@ -582,7 +586,7 @@ class FVComponentVariable {
582
586
: InternalConstraint(nullptr ), ExternalConstraint(nullptr ),
583
587
SourceDeclaration (" " ) {}
584
588
585
- FVComponentVariable (FVComponentVariable *Ot, Constraints &CS);
589
+ FVComponentVariable (FVComponentVariable *Ot, ReasonLoc &Rsn, Constraints &CS);
586
590
587
591
FVComponentVariable (const clang::QualType &QT, const clang::QualType &ITypeT,
588
592
clang::DeclaratorDecl *D, std::string N, ProgramInfo &I,
@@ -609,8 +613,8 @@ class FVComponentVariable {
609
613
InternalConstraint->setGenericIndex (idx);
610
614
}
611
615
612
- void equateWithItype (ProgramInfo &CS, const std::string &ReasonUnchangeable,
613
- PersistentSourceLoc *PSL ) const ;
616
+ void equateWithItype (ProgramInfo &CS,
617
+ const ReasonLoc &ReasonUnchangeable ) const ;
614
618
615
619
bool solutionEqualTo (Constraints &CS, const FVComponentVariable *CV,
616
620
bool ComparePtyp) const ;
@@ -640,7 +644,8 @@ class FunctionVariableConstraint : public ConstraintVariable {
640
644
// Count of type parameters (originally from `_Itype_for_any(...)`).
641
645
int TypeParams;
642
646
643
- void equateFVConstraintVars (ConstraintVariable *CV, ProgramInfo &Info) const ;
647
+ void equateFVConstraintVars (ConstraintVariable *CV, ProgramInfo &Info,
648
+ ReasonLoc &Rsn) const ;
644
649
645
650
public:
646
651
FunctionVariableConstraint (clang::DeclaratorDecl *D, ProgramInfo &I,
@@ -723,24 +728,22 @@ class FunctionVariableConstraint : public ConstraintVariable {
723
728
void dump () const override { print (llvm::errs ()); }
724
729
void dumpJson (llvm::raw_ostream &O) const override ;
725
730
726
- void constrainToWild (Constraints &CS, const std::string &Rsn) const override ;
727
- void constrainToWild (Constraints &CS, const std::string &Rsn,
728
- PersistentSourceLoc *PL) const override ;
731
+ void constrainToWild (Constraints &CS, const ReasonLoc &Rsn) const override ;
729
732
bool anyChanges (const EnvironmentMap &E) const override ;
730
733
bool hasWild (const EnvironmentMap &E, int AIdx = -1 ) const override ;
731
734
bool hasArr (const EnvironmentMap &E, int AIdx = -1 ) const override ;
732
735
bool hasNtArr (const EnvironmentMap &E, int AIdx = -1 ) const override ;
733
736
734
- void equateArgumentConstraints (ProgramInfo &P) override ;
737
+ void equateArgumentConstraints (ProgramInfo &P, ReasonLoc &Rsn ) override ;
735
738
736
- FunctionVariableConstraint *getCopy (Constraints &CS) override ;
739
+ FunctionVariableConstraint *getCopy (ReasonLoc &Rsn, Constraints &CS) override ;
737
740
738
741
bool isOriginallyChecked () const override ;
739
742
bool isSolutionChecked (const EnvironmentMap &E) const override ;
740
743
bool isSolutionFullyChecked (const EnvironmentMap &E) const override ;
741
744
742
- void equateWithItype (ProgramInfo &CS, const std::string &ReasonUnchangeable,
743
- PersistentSourceLoc *PSL ) override ;
745
+ void equateWithItype (ProgramInfo &CS,
746
+ const ReasonLoc &ReasonUnchangeable ) override ;
744
747
745
748
~FunctionVariableConstraint () override {}
746
749
};
0 commit comments