[llvm] r370925 - [Attributor][NFC] Add assertion to guard against accidental misuse

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 09:36:54 PDT 2019


Author: jdoerfert
Date: Wed Sep  4 09:36:54 2019
New Revision: 370925

URL: http://llvm.org/viewvc/llvm-project?rev=370925&view=rev
Log:
[Attributor][NFC] Add assertion to guard against accidental misuse

Modified:
    llvm/trunk/include/llvm/Transforms/IPO/Attributor.h

Modified: llvm/trunk/include/llvm/Transforms/IPO/Attributor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/IPO/Attributor.h?rev=370925&r1=370924&r2=370925&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/IPO/Attributor.h (original)
+++ llvm/trunk/include/llvm/Transforms/IPO/Attributor.h Wed Sep  4 09:36:54 2019
@@ -674,7 +674,10 @@ struct Attributor {
     // Put the attribute in the lookup map structure and the container we use to
     // keep track of all attributes.
     IRPosition &IRP = AA.getIRPosition();
-    AAMap[IRP][&AAType::ID] = &AA;
+    auto &KindToAbstractAttributeMap = AAMap[IRP];
+    assert(!KindToAbstractAttributeMap.count(&AAType::ID) &&
+           "Attribute already in map!");
+    KindToAbstractAttributeMap[&AAType::ID] = &AA;
     AllAbstractAttributes.push_back(&AA);
     return AA;
   }
@@ -821,8 +824,7 @@ private:
 
     // Lookup the abstract attribute of type AAType. If found, return it after
     // registering a dependence of QueryingAA on the one returned attribute.
-    const auto &KindToAbstractAttributeMap =
-        AAMap.lookup(const_cast<IRPosition &>(IRP));
+    const auto &KindToAbstractAttributeMap = AAMap.lookup(IRP);
     if (AAType *AA = static_cast<AAType *>(
             KindToAbstractAttributeMap.lookup(&AAType::ID))) {
       // Do not register a dependence on an attribute with an invalid state.




More information about the llvm-commits mailing list