[PATCH] D134488: [llvm] Assert two ValIDs are the same kind before comparing

Leonard Chan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 22 15:16:46 PDT 2022


leonardchan created this revision.
leonardchan added reviewers: phosek, MaskRay.
leonardchan added a project: LLVM.
Herald added a subscriber: StephenFan.
Herald added a project: All.
leonardchan requested review of this revision.

I suspect the reason for why D134234 <https://reviews.llvm.org/D134234> was failing sometimes is because "operator<" for a ValID could compare ValIDs of different kinds but have the same non-active values and return an incorrect result. This is an issue if I attempt to store ValIDs of different kinds in an std::map but we compare different "active" values. For example, if I create an std::map and store some ValIDs of kind t_GlobalName, then I insert a ValID of kind t_GlobalID, the current "operator<" will see that one of the operands is a t_GlobalID and compare it against the UIntVal of other items in the map, but the other items in the map don't set UIntVal because they're not t_GlobalIDs, so I compare against a dummy/uninitialized value.

It seems pretty easy to add mixed ValID kinds into an std::map in LLParser, so this just asserts that when doing the comparison that both ValIDs are the same kind.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134488

Files:
  llvm/include/llvm/AsmParser/LLParser.h


Index: llvm/include/llvm/AsmParser/LLParser.h
===================================================================
--- llvm/include/llvm/AsmParser/LLParser.h
+++ llvm/include/llvm/AsmParser/LLParser.h
@@ -81,6 +81,7 @@
     }
 
     bool operator<(const ValID &RHS) const {
+      assert(Kind == RHS.Kind && "Comparing ValIDs of different kinds");
       if (Kind == t_LocalID || Kind == t_GlobalID)
         return UIntVal < RHS.UIntVal;
       assert((Kind == t_LocalName || Kind == t_GlobalName ||


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134488.462306.patch
Type: text/x-patch
Size: 500 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220922/794431f8/attachment.bin>


More information about the llvm-commits mailing list