Problem
The lifetime checker currently identifies temporaries by checking if the AllocaOp name starts with "ref.tmp". This string-based detection is fragile and could break if naming conventions change.
Current implementation:
auto name = allocaOp.getName();
// FIXME: "ref.tmp" naming is not reliable. Consider adding a unit attribute
// is_temporary to AllocaOp that is set by CIRGen to definitively mark
// temporaries. This would be more robust than string prefix matching.
if (!name.starts_with("ref.tmp"))
return false;
Proposed Solution
Add a unit attribute is_temporary to AllocaOp that is set by CIRGen when allocating temporaries. This would provide a reliable, semantic way to identify temporaries during lifetime analysis.
Desired approach:
if (!allocaOp.getIsTemporary())
return false;
Context
This issue was identified during PR #2077 review. The FIXME is currently in the codebase at:
- File:
clang/lib/CIR/Dialect/Transforms/LifetimeCheck.cpp
- Lines: 985-987 (as of commit f9a229f)
- Function:
isSkippableTemporary()
Related