[PATCH] D33084: [GISel]: Fix undefined behavior while accessing DefaultAction map

Aditya Nandakumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 10 19:03:01 PDT 2017


aditya_nandakumar created this revision.

We end up dereferencing the end iterator here when the Aspect doesn't exist in the DefaultAction map.
Check for end iterator.


Repository:
  rL LLVM

https://reviews.llvm.org/D33084

Files:
  include/llvm/CodeGen/GlobalISel/LegalizerInfo.h


Index: include/llvm/CodeGen/GlobalISel/LegalizerInfo.h
===================================================================
--- include/llvm/CodeGen/GlobalISel/LegalizerInfo.h
+++ include/llvm/CodeGen/GlobalISel/LegalizerInfo.h
@@ -153,8 +153,12 @@
     do {
       Ty = NextType(Ty);
       auto ActionIt = Map.find(Ty);
-      if (ActionIt == Map.end())
-        Action = DefaultActions.find(Aspect.Opcode)->second;
+      if (ActionIt == Map.end()) {
+        auto DefaultIt = DefaultActions.find(Aspect.Opcode);
+        if (DefaultIt == DefaultActions.end())
+          return LLT();
+        Action = DefaultIt->second;
+      }
       else
         Action = ActionIt->second;
     } while(Action != Legal);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33084.98572.patch
Type: text/x-patch
Size: 713 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170511/6d10c075/attachment.bin>


More information about the llvm-commits mailing list