On Thu, Jan 9, 2025 at 9:39 PM Qing Zhao <qing.z...@oracle.com> wrote: > > > > > On Jan 9, 2025, at 14:10, Jeff Law <jeffreya...@gmail.com> wrote: > > > > > > > > On 1/9/25 10:48 AM, Qing Zhao wrote: > > > >>> > >>> I think Jeff's patch is not reasonable since it boils down to not diagnose > >>> -Warray-bounds but instead remove those stmts. > >> If these stmts are dead-code that are generated by compiler optimization > >> (NOT from source code), > >> removing them before diagnosis is correct. (To avoid false positive > >> warnings). > > But I don't think we generally know if the problematic statements came from > > user code or were generated by the compiler. > > To help the compiler catches real problems in the source code and avoid false > positive warnings introduced by the compiler transformation, we might need to > add flags in the IR to distinguish this?
Well, the issue is the problematic statements _are_ in user code, just -Warray-bounds is too stupid to look at SCEV for indices and instead relies on weaker value-ranges. It's a problem we're never going to fully solve. Some of the testcases show missed optimizations which we can work on. Some show we diagnose IL we later are able to optimize away, some simply show that users are not always happy with how we decide on suppressing a diagnostic. For the case at hand we should be able to optimize it fully. But optimizing based on UB is always going to be to interact with diagnosing UB, so we have to be careful. Our "late" diagnostics are most problematic here and I'd argue moving those earlier is the first thing we should try. Richard. > > Qing > > > > Jeff > > >