================
@@ -1951,5 +1971,38 @@ TEST_F(LifetimeAnalysisTest, 
LambdaInitCaptureViewByValue) {
   )");
   EXPECT_THAT(Origin("lambda"), HasLoansTo({"obj"}, "after_lambda"));
 }
+
+// ========================================================================= //
+//                    Tests for buildOriginFlowChain
+// ========================================================================= //
+
----------------
usx95 wrote:

Some ideas for more tests.
```
// Self-assignment and cycles
int *a = &tgt;
int *b = a;
a = b;
a = a;
int *s = a;

// Multiple variables assigned in same statement
int tgt = 2;
int *a, *b, *c;
a = b = c = &tgt;  // All get same loan
int *s = a;

// Overwriting - intermediate assignments get overwritten
int *s;
int tgt1 = 1, tgt2 = 2;
int *a = &tgt1;
int *b = a;
int *c = b;
b = &tg2;
s = c;  // Should only track back to tgt2

// Lifetimebound
int* choose(int* [[clang::lifetimebound]] a, 
                     int* [[clang::lifetimebound]] b);
int tgt1 = 1, tgt2 = 2;
int *a = &tgt1;
int *b = &tgt2;
int *result = choose(a, b);
result = choose(result , result);
a = result;
// trace both 'tgt1' and 'tgt2' in 'a'.
```
Non-empty traces should be sufficient to check for these as the number of 
origins is not useful to understand and maintain. These would be more useful 
once we have diagnostic locations.

https://github.com/llvm/llvm-project/pull/196075
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to