bansan added a comment.
Herald added a subscriber: StephenFan.

I just made a test:

  #include <cstdint>
  #include <vector>
  
  int64_t f(int x) {
    return 1024 * 1024 * 1024 * x;
  }
  
  void g(int x) {
    std::vector<int> b;
    b.reserve(1024 * 1024 * 1024 * x);
  }
  
  int main() {
    f(1024);
    g(1024);
  }

The fixed code:

  #include <cstddef>
  #include <cstdint>
  #include <vector>
  
  int64_t f(int x) {
    return static_cast<int64_t>(1024 * 1024 * 1024 * x);
  }
  
  void g(int x) {
    std::vector<int> b;
    b.reserve(static_cast<size_type>(1024 * 1024 * 1024 * x));
  }
  
  int main() {
    f(1024);
    g(1024);
  }

For the first test, I still think that the auto fix should be `return 
static_cast<int64_t>(1024) * 1024 * 1024 * x;` to have the good result.

For the second test, the type is the internal type of `std::vector`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141058/new/

https://reviews.llvm.org/D141058

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to