This patch makes it possible to handle nonnull attribute violation at callsites in AAUndefinedBehavior.
If null pointer is passed to callee at a callsite and the corresponding argument of callee has nonnull attribute, the behavior of the callee is undefined.
In this patch, violations of argument nonnull attributes is only handled.
But violations of returned nonnull attributes can be handled and I will implement that in a follow-up patch.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/Transforms/IPO/AttributorAttributes.cpp | ||
---|---|---|
2048 | Please add a third argument specifying the instructions to check, i.e. {Instruction::CallSite}. Also, a fourth argument true as a value, like the other too above. | |
llvm/test/Transforms/Attributor/value-simplify.ll | ||
409 ↗ | (On Diff #281140) | Hmm.. We probably need to fix the undefined behavior in this testcase. |
This is cool :)
I thought about this again and I think it will expose the problematic case I mentioned on the call. The Attributor derives attributes, then replaces the value with undef because it is dead, then the thing might be folded to UB/unreachable. Let's directly require the noundef attribute as well. We need to split the AAUB behavior accordingly soon but I'm fine with checking it explicitly here first. That will require tests with and without noundef.
llvm/lib/Transforms/IPO/AttributorAttributes.cpp | ||
---|---|---|
1991 | ||
1996 | You don't need a callee, just use the call base. | |
1998 | I somehow feel checking the attribute first is better. | |
2005 | Move this to the beginning to describe what is happening. Maybe elaborate a bit. | |
2018 | Provide a comment before or at the beginning of this lambda explaining it a bit. | |
2048 | No need to specify call site (which is not an opcode) because this is a specialized version of checkForAllInstructions. The CheckBBLivenessOnly can be provided I guess. |
llvm/lib/Transforms/IPO/AttributorAttributes.cpp | ||
---|---|---|
2048 | Oh my bad. The names are big and I missed completely that it is not checkForAllInstructions. |
- fix comments
- check noundef attribute explicitly
- modify and add tests with noundef attribute
llvm/lib/Transforms/IPO/AttributorAttributes.cpp | ||
---|---|---|
1996 | Do you mean that I don't have to be aware of Callee->arg_size() anywhere? |
LGTM. Some minor nits below. I guess this doesn't affect other tests because of the noundef restriction. We should really derive that one as well.
llvm/lib/Transforms/IPO/AttributorAttributes.cpp | ||
---|---|---|
1996 | Oh, OK. For any variadic function the call can have more operands than the callee arguments. I guess what you really want are the abstract call sites you can get from the call base. Let's keep it like this for now. | |
2007 | I guess the easiest is to check if it is a pointer early on. That should avoid running the code below in case it can never trigger. | |
2021 | Not having a value and having the value undef are also all violations if you will. The former means it is dead anyway, and undef can degenerate to null whenever you want it to. | |
llvm/test/Transforms/Attributor/undefined_behavior.ll | ||
598 | Next up, we can derive noundef for this case (amongst others), given that we actually access the pointer for sure. An undef value would cause UB so %a cannot be undef. Basically the same way we should already derive nonnull for this case. Later ;) |