llvm.dbg.declare constraints

Hi,

In the LLVM documentation it says "there can only be one call to
llvm.dbg.declare for a given concrete local variable."
However we don't seem to be checking it. opt tool can process IR that
violates this rule without complaining. Is this intended, or is it a
bug? What would be the consequence when this constraint is broken?

+Aprantl for debug info IR metadata verifier things

I don’t think the verifier’s rigorously comprehensive - so probably somewhere between “intended/acceptable” and “a bug”.

Not sure what the consequences might be.

The documentation is correct, and the observation that the IR verifier is currently not verifying this property is also correct. Due to the way that dbg.declares are handled by later stages, LLVM can only keep track of one dbg.declare per variable and that is intentional. The dbg.declare intrinsic is supposed to pin a variable to a stack slot, such as in the code that clang emits at -O0. If you need something different, use dbg.value. Adding a verifier check would be appreciated, but it may be a bit of work to get all of LLVM to adhere to it.

– adrian

Thanks. Would there be any consequences if there are multiple
dbg.declare for the same variable, and if they point to different
aliases of the same address?

As I said in my last message, the backend can AFAIK only keep track of one declare per variable so it would be undefined which one survived.

-- adrian