[llvm-dev] Should we enable -Wrange-loop-analysis?
Justin Bogner via llvm-dev
llvm-dev at lists.llvm.org
Fri Mar 18 17:35:25 PDT 2016
Mehdi Amini <mehdi.amini at apple.com> writes:
> What does this warning look like (and what cases does it catch)? Also
> does it have false positive?
I ran it on LLVM and clang and it only caught real (albeit minor)
problems.
Here, someone wrote & instead of * by mistake:
SelectionDAGBuilder.cpp:2382:22: error: loop variable 'U' is always a copy because the range of type 'llvm::iterator_range<llvm::Value::user_iterator_impl<const llvm::User> >' does not return a reference [-Werror,-Wrange-loop-analysis]
for (const auto &U : User->users()) {
^
SelectionDAGBuilder.cpp:2382:10: note: use non-reference type 'const llvm::User *'
for (const auto &U : User->users()) {
^~~~~~~~~~~~~~~
Here, we're copying this struct for no good reason (someone missed a *):
LoopLoadElimination.cpp:439:47: error: loop variable 'Cand' of type 'const (anonymous namespace)::StoreToLoadForwardingCandidate' creates a copy from type 'const (anonymous namespace)::StoreToLoadForwardingCandidate' [-Werror,-Wrange-loop-analysis]
for (const StoreToLoadForwardingCandidate Cand : StoreToLoadDependences) {
^
LoopLoadElimination.cpp:439:10: note: use reference type 'const (anonymous namespace)::StoreToLoadForwardingCandidate &' to prevent copying
for (const StoreToLoadForwardingCandidate Cand : StoreToLoadDependences) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> --
> Mehdi
>
> On Mar 18, 2016, at 5:12 PM, Justin Bogner via llvm-dev <llvm-dev at lists.llvm.org> wrote:
>
> This is a pretty nice warning. Should we enable it for LLVM's build when
> the host compiler supports it?
>
> Benjamin Kramer via llvm-commits <llvm-commits at lists.llvm.org> writes:
>> Author: d0k
>> Date: Mon Feb 22 07:11:58 2016
>> New Revision: 261524
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=261524&view=rev
>> Log:
>> Fix some abuse of auto flagged by clang's -Wrange-loop-analysis.
>>
>> Modified:
>> llvm/trunk/lib/Target/PowerPC/PPCBoolRetToInt.cpp
>> llvm/trunk/lib/Transforms/Utils/MemorySSA.cpp
>> llvm/trunk/tools/sancov/sancov.cc
More information about the llvm-dev
mailing list