llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang] missed integer overflow warning with CXXTemporary values

Open lnihlen opened this issue 3 years ago • 4 comments

compiler explorer link: https://godbolt.org/z/Wd318Mdrx

typedef long long int64_t;

template<typename T>
class u_ptr {
  T *ptr;
public:
  u_ptr(const u_ptr&) = delete;
  u_ptr &operator=(const u_ptr&) = delete;
  u_ptr(u_ptr &&other) : ptr(other.ptr) { other.ptr = 0; }
  u_ptr(T *ptr) : ptr(ptr) { }
  ~u_ptr() { delete ptr; }
};

u_ptr<bool> Wrap(int64_t x) {
    return nullptr;
}

int64_t Pass(int64_t x) { return x; }

int main(int argc, char* argv[]) {
    // This trips -Winteger-overflow:
    int64_t x = Pass(30 * 24 * 60 * 59 * 1000);
    
    // This doesn't trip -Winteger-overflow.
    auto r = Wrap(Pass(30 * 24 * 60 * 59 * 1000));
    
    return 0;
}

Patch coming shortly.

lnihlen avatar Jun 30 '23 19:06 lnihlen

@llvm/issue-subscribers-bug

llvmbot avatar Jun 30 '23 19:06 llvmbot

Patch at https://reviews.llvm.org/D154253

lnihlen avatar Jun 30 '23 19:06 lnihlen

@llvm/issue-subscribers-clang-frontend

llvmbot avatar Jun 30 '23 20:06 llvmbot

Related: https://github.com/llvm/llvm-project/issues/58944

shafik avatar Jun 30 '23 21:06 shafik