In http://reviews.llvm.org/D10634#199554, @danielmarjamaki wrote:

> Here is a bigger log with more warnings.
>  https://drive.google.com/file/d/0BykPmWrCOxt2aGtRNTY4eXQ1OU0/view
>
> there are some cases where I don't think there should be a warning.. for 
> instance some compound assignments:
>
> args.c:990:9: warning: assigning negative value to unsigned variable loses 
> sign and may cause undesired runtime behavior 
> [clang-analyzer-alpha.core.LossOfSignAssign]
>
>   tmp /= 10;
>       ^
>
> read.c:4940:13: warning: assigning negative value to unsigned variable loses 
> sign and may cause undesired runtime behavior 
> [clang-analyzer-alpha.core.LossOfSignAssign]
>
>   value >>= 7;
>         ^
>   
>
> I am not an expert but it seems strange to me that clang seems to think that 
> 10 and 7 are negative. Can you investigate this?


Here's a short test case that shows the problem:

  1  void safe_mul(unsigned long x) {
  2    unsigned long multiplier = 1000000000000000000; 
  3    while (x > 0) {
  4      multiplier /= 10;
  5    }
  6  }

I may be wrong here, but I believe that the warning is due to an overflow 
during constant folding of the initializer, which causes the RHS to be treated 
as negative.


http://reviews.llvm.org/D10634




_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to