================
@@ -697,13 +742,189 @@ CapturedZoneInfo captureZoneInfo(const ExtractionZone
&ExtZone) {
if (!DeclInfo)
DeclInfo = Info.createDeclInfo(D, ZoneRelative::OutsideFunc);
DeclInfo->markOccurence(CurrentLocation);
- // FIXME: check if reference mutates the Decl being referred.
+ return true;
+ }
+
+ // Conservatively marks D as possibly mutated: used both for actual
+ // direct mutations (assignment, increment/decrement, ...) and for
+ // constructs that alias D in a way we don't want to trace further (a
+ // reference bound to D, D's address taken, D captured by reference in a
+ // lambda, ...). We never try to determine whether such an alias is
+ // itself later mutated -- that would require searching beyond this one
+ // occurrence, which is exactly the cost this design avoids (and what
+ // makes ExprMutationAnalyzer prohibitively slow). The price is
+ // that we sometimes keep a parameter non-const where a full alias
+ // analysis could prove it safe to const; we never get this wrong in the
+ // other, unsafe direction.
+ void markPossiblyMutated(const Decl *D) {
+ if (!D || CurrentLocation != ZoneRelative::Inside)
+ return;
+ if (auto *DeclInfo = Info.getDeclInfoFor(D))
+ DeclInfo->IsPossiblyMutated = true;
+ }
+ void markPossiblyMutated(const Expr *E) {
+ markPossiblyMutated(underlyingDecl(E));
----------------
ArcsinX wrote:
`markPossiblyMutated(const Expr *E)` is called from `VisitVarDecl()` and if
the initializer is a conditional expression (e.g. `int &A = B ? C : D;`),
`underlyingDecl()` will return `nullptr` because it doesn't unpack `?:`.
https://github.com/llvm/llvm-project/pull/225666
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits