Access to undefined local variables in IR

Dear all,

I have a question regarding access to undefined (or out of scope) local
variables in LLVM IR.

If I have a program like:

define i32 @f(i32 %i) nounwind {
  %1 = add i32 %i, 1
  ret i32 %1
}

define i32 @g() nounwind {
  %1 = add i32 %i, 1
  ret i32 %1
}

define i32 @main() nounwind {
  %1 = call i32 @g()
  ret i32 %1
}

Would that be a valid LLVM IR program (note the access to %i outside of
f)? If so, what happens when accessing an undefined local variable? Is
there a reference that I could cite in a scientific paper where this is
described?

Thank you very much,

  Thomas

1 Like

No, this is not valid.

$opt /tmp/test.ll
opt: /tmp/test.ll:8:16: error: use of undefined value '%i'
   %1 = add i32 %i, 1

Tobias