[llvm] [CFIInserter] Improve `CSRSavedLocation` struct. (PR #168869)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 11 07:54:52 PST 2025


================
@@ -277,10 +319,19 @@ void CFIInstrInserter::calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo) {
       case MCCFIInstruction::OpValOffset:
         break;
       }
-      if (CSRReg || CSROffset) {
-        CSRSavedLocation Loc(CSRReg, CSROffset);
-        auto [It, Inserted] = CSRLocMap.insert({CFI.getRegister(), Loc});
-        if (!Inserted && It->second != Loc) {
+      assert((bool)CSRReg + (bool)CSROffset <= 1 &&
+             "A register can only be at an offset from CFA or in another "
+             "register, but not both!");
+      CSRSavedLocation CSRLoc;
+      if (CSRReg)
+        CSRLoc = CSRSavedLocation::createRegister(*CSRReg);
+      else if (CSROffset)
+        CSRLoc = CSRSavedLocation::createCFAOffset(*CSROffset);
+      if (CSRLoc.isValid()) {
+        auto It = CSRLocMap.find(CFI.getRegister());
----------------
preames wrote:

Please use the insert idiom from the prior code.  

https://github.com/llvm/llvm-project/pull/168869


More information about the llvm-commits mailing list