Skip to content

[CIR][LifetimeCheck] Add is_temporary unit attribute to AllocaOp for reliable temporary detection #2113

@ivanmurashko

Description

@ivanmurashko

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions