[PATCH] D46081: [analyzer] Expand conversion check to check more expressions for overflow and underflow

Whisperity via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 26 02:41:46 PDT 2018


whisperity added a comment.

While I understand extending the analyzer to cover more is a good approach, there is `-Wconversion` which seemingly covers this -- or at least the trivial case(?):

  #include <cstdio>
  #include <vector>
  
  void foo(unsigned x)
  {
    printf("%u\n", x);
  }
  
  int main()
  {
    int i = -1;
    foo(i);
  
    std::vector<int> x;
    x[i] = 5;
  }



  $ clang++ -Wconversion -o/dev/null check.cpp 
  check.cpp:12:7: warning: implicit conversion changes signedness: 'int' to 'unsigned int' [-Wsign-conversion]
    foo(i);
    ~~~ ^
  check.cpp:15:5: warning: implicit conversion changes signedness: 'int' to 'std::vector::size_type' (aka 'unsigned long') [-Wsign-conversion]
    x[i] = 5;
    ~ ^


Repository:
  rC Clang

https://reviews.llvm.org/D46081





More information about the cfe-commits mailing list