llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.64k stars 11.84k forks source link

Value not read message given on wrong line #7237

Open llvmbot opened 14 years ago

llvmbot commented 14 years ago
Bugzilla Link 6865
Version unspecified
OS MacOS X
Attachments screenshot of clang false "advice"
Reporter LLVM Bugzilla Contributor
CC @tkremenek

Extended Description

Definitively a totally nonsense error, or I am wrong? See the attachment to see in the class Block.m what clang tell me as error!!!! (both with SDK 3.2 and 4.0beta)

1) First of all, the value is incremented in each line (and to increment something you need either to read the prev value or to use black magic, my guess is clang does the first way...)

2) Second after this block is created I MUST use this value FOREACH block with no exceptions to add it in the 2D engine Cocos2d... Look at the [self addChild...] I use to pass this value generated before, how this crazy clang could think that the value is never read???

for (int i = 0; i < [playerOne.currentBlock.bricks count]; i++) { Brick brick = [playerOne.currentBlock.bricks objectAtIndex:i]; brick.bColumn += 4; brick.bRow += 18; brick.position = ccp(pad + brick.bColumn (side + 3), pad + brick.bRow * side); [blockOne.bricks addObject:brick]; [self addChild:[playerOne.currentBlock.bricks objectAtIndex:i] z:1 tag:brick.myTag]; }

Thank you!

llvmbot commented 14 years ago

This does look bogus, although it might be referring to the 'tag++' on the last line (in which case the diagnostic is in the wrong place).

YOU'RE ABSOLUTELY RIGHT!

The bug is just in that the message is in the first line instead of the last... I posted two test projects, the first where you can reproduce this bogus message on Block.m ln12 (the message should be on ln15) and a second project with no error (putting ++tag instead of tag++) things that it would be far more easy to understand if clang would give the error in the right place! Isn't it?

I hope this bug post did not bore you and will help to contribute to the general LLVM quality! (a great product) Thank you very much

llvmbot commented 14 years ago

Test program without bug

llvmbot commented 14 years ago

Test program with bug

tkremenek commented 14 years ago

First, thanks for the bug report. Comments inline.

Definitively a totally nonsense error, or I am wrong? See the attachment to see in the class Block.m what clang tell me as error!!!! (both with SDK 3.2 and 4.0beta)

1) First of all, the value is incremented in each line (and to increment something you need either to read the prev value or to use black magic, my guess is clang does the first way...)

This does look bogus, although it might be referring to the 'tag++' on the last line (in which case the diagnostic is in the wrong place). Could you provide a self-contained example so that I can try and reproduce it?

2) Second after this block is created I MUST use this value FOREACH block with no exceptions to add it in the 2D engine Cocos2d... Look at the [self addChild...] I use to pass this value generated before, how this crazy clang could think that the value is never read???

for (int i = 0; i < [playerOne.currentBlock.bricks count]; i++) { Brick brick = [playerOne.currentBlock.bricks objectAtIndex:i]; brick.bColumn += 4; brick.bRow += 18; brick.position = ccp(pad + brick.bColumn (side + 3), pad + brick.bRow

  • side); [blockOne.bricks addObject:brick]; [self addChild:[playerOne.currentBlock.bricks objectAtIndex:i] z:1 tag:brick.myTag]; }

I'm not following this example, since it isn't related to the screenshot. Without a full example, I can't tell how this value of 'tag' relates to the other one. In the screenshot, the 'tag' that is modified is a parameter value, since after the last "tag++" it certainly isn't read after it is modified.

If you don't feel comfortable attaching an example to bugzilla (which is literally source code I can run through the analyzer), alternatively you can email me or file a bug through bugreporter.apple.com.

llvmbot commented 14 years ago

assigned to @tkremenek