[PATCH] D33910: [ubsan] Detect invalid unsigned pointer index expression (clang)

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 5 15:34:32 PDT 2017


rsmith added a comment.

Looks good, with a couple of tweaks (and corresponding test changes).



================
Comment at: lib/CodeGen/CGExprScalar.cpp:3910-3911
         (Opcode == BO_Add) ? SAddIntrinsic : SMulIntrinsic, {LHS, RHS});
     OffsetOverflows = Builder.CreateOr(
         OffsetOverflows, Builder.CreateExtractValue(ResultAndOverflow, 1));
     return Builder.CreateExtractValue(ResultAndOverflow, 0);
----------------
Reverse the order of operands here; Builder will simplify `or` instructions with a constant RHS.


================
Comment at: lib/CodeGen/CGExprScalar.cpp:3963-3965
+    ValidGEP = Builder.CreateAnd(
+        NoOffsetOverflow,
+        Builder.CreateSelect(PosOrZeroOffset, PosOrZeroValid, NegValid));
----------------
Likewise reverse the operand order here....


================
Comment at: lib/CodeGen/CGExprScalar.cpp:3967
+  } else {
+    ValidGEP = Builder.CreateAnd(NoOffsetOverflow, PosOrZeroValid);
+  }
----------------
... and here.


https://reviews.llvm.org/D33910





More information about the cfe-commits mailing list