[all-commits] [llvm/llvm-project] 8cd35a: [DebugInfo] Enforce implicit constraints on `disti...

Scott Linder via All-commits all-commits at lists.llvm.org
Mon Jun 28 14:20:32 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 8cd35ad854ab4458fd509447359066ea3578b494
      https://github.com/llvm/llvm-project/commit/8cd35ad854ab4458fd509447359066ea3578b494
  Author: Scott Linder <Scott.Linder at amd.com>
  Date:   2021-06-28 (Mon, 28 Jun 2021)

  Changed paths:
    M llvm/docs/LangRef.rst
    M llvm/docs/SourceLevelDebugging.rst
    M llvm/include/llvm/AsmParser/LLParser.h
    M llvm/include/llvm/IR/Metadata.def
    M llvm/lib/AsmParser/LLParser.cpp
    M llvm/lib/Bitcode/Reader/MetadataLoader.cpp
    M llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
    M llvm/lib/CodeGen/MIRParser/MIParser.cpp
    M llvm/lib/IR/AsmWriter.cpp
    M llvm/lib/IR/DebugInfoMetadata.cpp
    M llvm/lib/IR/LLVMContextImpl.cpp
    M llvm/lib/IR/LLVMContextImpl.h
    M llvm/lib/IR/Metadata.cpp
    A llvm/test/Assembler/invalid-diarglist-outside-function.ll
    A llvm/test/Assembler/invalid-diexpression-distinct.ll
    A llvm/test/Bitcode/DIExpression-is-distinct-upgrade.ll
    A llvm/test/Bitcode/DIExpression-is-distinct-upgrade.ll.bc

  Log Message:
  -----------
  [DebugInfo] Enforce implicit constraints on `distinct` MDNodes

Add UNIQUED and DISTINCT properties in Metadata.def and use them to
implement restrictions on the `distinct` property of MDNodes:

* DIExpression can currently be parsed from IR or read from bitcode
  as `distinct`, but this property is silently dropped when printing
  to IR. This causes accepted IR to fail to round-trip. As DIExpression
  appears inline at each use in the canonical form of IR, it cannot
  actually be `distinct` anyway, as there is no syntax to describe it.
* Similarly, DIArgList is conceptually always uniqued. It is currently
  restricted to only appearing in contexts where there is no syntax for
  `distinct`, but for consistency it is treated equivalently to
  DIExpression in this patch.
* DICompileUnit is already restricted to always being `distinct`, but
  along with adding general support for the inverse restriction I went
  ahead and described this in Metadata.def and updated the parser to be
  general. Future nodes which have this restriction can share this
  support.

The new UNIQUED property applies to DIExpression and DIArgList, and
forbids them to be `distinct`. It also implies they are canonically
printed inline at each use, rather than via MDNode ID.

The new DISTINCT property applies to DICompileUnit, and requires it to
be `distinct`.

A potential alternative change is to forbid the non-inline syntax for
DIExpression entirely, as is done with DIArgList implicitly by requiring
it appear in the context of a function. For example, we would forbid:

    !named = !{!0}
    !0 = !DIExpression()

Instead we would only accept the equivalent inlined version:

    !named = !{!DIExpression()}

This essentially removes the ability to create a `distinct` DIExpression
by construction, as there is no syntax for `distinct` inline. If this
patch is accepted as-is, the result would be that the non-canonical
version is accepted, but the following would be an error and produce a diagnostic:

    !named = !{!0}
    ; error: 'distinct' not allowed for !DIExpression()
    !0 = distinct !DIExpression()

Also update some documentation to consistently use the inline syntax for
DIExpression, and to describe the restrictions on `distinct` for nodes
where applicable.

Reviewed By: StephenTozer, t-tye

Differential Revision: https://reviews.llvm.org/D104827




More information about the All-commits mailing list