[PATCH] D94180: [SimplifyCFG] Optimize CFG when null is passed to a function with nonnull argument.

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 6 12:06:33 PST 2021


xbolva00 added inline comments.


================
Comment at: llvm/lib/Transforms/Utils/SimplifyCFG.cpp:6600
+        if (Arg == I &&
+            CB->paramHasAttr(CB->getArgOperandNo(&Arg), Attribute::NonNull))
+          return true;
----------------
jdoerfert wrote:
> nikic wrote:
> > Two issues:
> > 
> > 1. I believe this is subtle incorrect in conjunction with the GEP rule above. Accessing memory at `gep null, x` is always UB, but passing it to a nonnull argument isn't UB as long as x is not zero.
> > 
> > 2. I'm not sure what the current state on this is (@aqjune), but I believe the plan is to make passing null to nonnull argument poison rather than UB. This optimization would only be valid using nonnull + noundef.
> FWIW, I'm, forever, in favor of making nonnull violation poison not UB.

1, but here we only care about foo(null) and not foo(gep null, x).
See C->isNullValue() check.

2, ok, I was wondering about noundef too..


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94180/new/

https://reviews.llvm.org/D94180



More information about the llvm-commits mailing list