[PATCH] D104827: [DebugInfo] Enforce implicit constraints on `distinct` MDNodes

Scott Linder via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 23 17:12:27 PDT 2021


scott.linder created this revision.
Herald added subscribers: dexonsmith, jdoerfert, hiraditya.
scott.linder requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.

Another potential 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 the
nodes where they are applicable.

Change-Id: Ia8bdc1a8d87f00e920196320235cc4019ec703e9


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104827

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104827.354113.patch
Type: text/x-patch
Size: 37872 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210624/f3cb695e/attachment.bin>


More information about the llvm-commits mailing list