Fix for the issue :https://github.com/llvm/llvm-project/issues/59580
Where we don't emit the inbounds flag for the GEP when wrapv is enabled .
Differential D142872
Honor the fwrapv option when generating the inbounds GEP . umesh.kalappa0 on Jan 30 2023, 12:19 AM. Authored by
Details
Fix for the issue :https://github.com/llvm/llvm-project/issues/59580 Where we don't emit the inbounds flag for the GEP when wrapv is enabled .
Diff Detail
Unit Tests Event TimelineComment Actions CreateConstArrayGEP currently always creates an inbounds GEP. You need to modify it make inbounds optional or use a different method, not suppress it in the constant folding infrastructure. Comment Actions You also shouldn't need to introduce any new handling for the fwrapv option. I'm not sure how exactly it is currently threaded through, but there must be existing handling for it already. For example, there is isSignedOverflowDefined() on LangOptions. Comment Actions Thank you very much for the feedback and We tried calling other overload like "CreateConstGEP" ,but that didn't help due to below call from "ConstantFoldGetElementPtr" ,that was recursive call from "ConstantExpr::getGetElementPtr" .
So we thought of disabling the call like "ConstantExpr::getGetElementPtr" with InBounds=true for wrapv and changes has its consensus so we end up changes that is shared for review. Comment Actions @umesh.kalappa0 This issue should be fixed by https://github.com/llvm/llvm-project/commit/5f01a626dd0615df49773d419c75aeb33666ee83. Can you please give it another try? Comment Actions I've found another bug in LLVM, fixed with https://github.com/llvm/llvm-project/commit/78f88082de3627ea04501c83a08f52cf1e60b4f7. After that change, the test case from https://github.com/llvm/llvm-project/issues/59580 appears to be handled correctly, it contains this in the final IR: br i1 icmp ugt (ptr getelementptr ([0 x i8], ptr @end, i64 0, i64 536870911), ptr @end), label %if.then, label %if.else9 As such, I'm not sure if we actually need any change in Clang, as it seems like this was ultimately due to LLVM bugs. At least we would need a different test case, as the inbounds.c test case is already getting compiled correctly without this patch.
Comment Actions The original issue has been fixed by the mentioned LLVM changes. As such, I don't think we need to actually do anything on the Clang side. Please let me know if you're still seeing issues in some case... |
These changes shouldn't be needed anymore.