[PATCH] D99362: Verify the LLVMContext for Attributes.

Nick Lewycky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 25 11:34:46 PDT 2021


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

Attributes don't know their parent Context. Instead of using extra memory to store that, we have the verifier query the Attribute with a prospective parent LLVMContext and the Attribute checks whether its contents exists in that context's FoldingSet.

In order to check whether the attribute exists in the FoldingSet, we add FoldingSet::Contains. To my surprise, the interface to FoldingSet only include mutable accessors, except for bucket_begin/end which has zero users in the LLVM monorepo this patch.

There's also another oddity I noticed while working on this patch. There are methods to create attributes with types which also take a context. If I check for nullptr Type* in attributes in the verifier, there are none in a run of the llvm testsuite. However, the C API does create these things in LLVMCreateEnumAttribute. I'm not sure what the intended state is here, but I'm thinking that the Attribute::get* functions that take Context+Type should either remove the Context or assert that the Type's Context matches the supplied Context when the Type is not null.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99362

Files:
  llvm/include/llvm/ADT/FoldingSet.h
  llvm/include/llvm/IR/Attributes.h
  llvm/lib/IR/Attributes.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/unittests/ADT/FoldingSet.cpp
  llvm/unittests/IR/AttributesTest.cpp
  llvm/unittests/IR/VerifierTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99362.333367.patch
Type: text/x-patch
Size: 9791 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210325/38ca8d79/attachment.bin>


More information about the llvm-commits mailing list