[llvm-dev] Why does a DISubprogram need to be distinct?

David Blaikie via llvm-dev llvm-dev at lists.llvm.org
Fri Sep 25 16:36:45 PDT 2020


On Fri, Sep 25, 2020 at 4:08 PM Adrian Prantl <aprantl at apple.com> wrote:
>
> First — thanks for fixing the test for me!

I'm a bit curious about the test - any idea how it came to be, if it's
invalid? Did we produce such bitcode in the past and don't anymore -
what's the rule about backwards compatibility here, then? It seems
like any time we regenerate a bitcode compat test that's questionable
because it means we won't be compatible with that bitcode we said we
should be compatible with?

> We have two kinds of DISubprograms:
> - uniqued DISubprograms are part of the type system and describe function *types*. They don't have a unit: field, because they want to be uniqued across compile units.
> - distinct DISubprograms describe one specific function definition. They belong to a compile unit and thus have a unit: field.
>
> You are only supposed to attach distinct DISubprograms to function definitions. Several places in CodeGen will unconditionally dereference the unit: field and crash if it isn't there.

But do they have to be distinct? They have different fields (as you
say, declaration DISubprograms don't have a "unit:" field, definition
DISubprograms do have a unit: field that refers to a (itself distinct)
DICompileUnit)

> We actually had a weaker form of the check I added to Verifier already in place (https://github.com/llvm/llvm-project/blob/51cad041e0cb26597c7ccc0fbfaa349b8fffbcda/llvm/lib/IR/Verifier.cpp#L1186), but it didn't cover the specific testcase I added in https://reviews.llvm.org/rGe17f52d623cc146b7d9bf5a2e02965043508b4c4.
>
> -- adrian


More information about the llvm-dev mailing list