Skip to content

[Bug]: typeof.exprreferences out-of-scope variables in rare cases #725

@Jezurko

Description

@Jezurko

VAST version

master

LLVM version

18.1.8

Operating system

Linux (Solus)

Description

({
  int x = 5;
  typeof(x) y = x;
  y;
})

generates

 hl.typeof.expr "(x)" {
            %3 = hl.expr : !hl.lvalue<!hl.int> {
              %4 = unsup.stmt "DeclRefExpr" : !hl.int
              hl.value.yield %4 : !hl.int
            }
            hl.type.yield %3 : !hl.lvalue<!hl.int>
          } : !hl.int
          %2 = hl.stmt.expr : !hl.typeof.expr<"(x)"> {
            %3 = hl.var @x : !hl.lvalue<!hl.int> = {
              %7 = hl.const #core.integer<0> : !hl.int
              hl.value.yield %7 : !hl.int
            }
            %4 = hl.var @y : !hl.lvalue<!hl.typeof.expr<"(x)">> = {
              %7 = hl.ref %3 : (!hl.lvalue<!hl.int>) -> !hl.lvalue<!hl.int>
              %8 = hl.implicit_cast %7 LValueToRValue : !hl.lvalue<!hl.int> -> !hl.int
              hl.value.yield %8 : !hl.int
            }
            %5 = hl.ref %4 : (!hl.lvalue<!hl.typeof.expr<"(x)">>) -> !hl.lvalue<!hl.typeof.expr<"(x)">>
            %6 = hl.implicit_cast %5 LValueToRValue : !hl.lvalue<!hl.typeof.expr<"(x)">> -> !hl.typeof.expr<"(x)">
            hl.value.yield %6 : !hl.typeof.expr<"(x)">
          }

The issue is unsupported DeclRefExpr in the typeof.expr region, that refers to x that is in the scope of the stmt.expr.
This is caused by visiting the return type of the stmt.expr

Steps to Reproduce

Run vast-front to hl

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions