[PATCH] D154253: [clang] detect integer overflow through temporary values

2023-06-30 Thread Lucile Rose Nihlen via Phabricator via cfe-commits
lnihlen updated this revision to Diff 536466.
lnihlen added a comment.

remove extrneous clang::


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154253

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaCXX/integer-overflow.cpp


Index: clang/test/SemaCXX/integer-overflow.cpp
===
--- clang/test/SemaCXX/integer-overflow.cpp
+++ clang/test/SemaCXX/integer-overflow.cpp
@@ -214,3 +214,32 @@
   int a = -(1<<31); // expected-warning {{overflow in expression; result is 
-2147483648 with type 'int'}}
 }
 }
+
+#if __cplusplus >= 201103L
+namespace GH63629 {
+typedef long long int64_t;
+
+template
+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 Wrap(int64_t x) {
+return nullptr;
+}
+
+int64_t Pass(int64_t x) { return x; }
+
+int m() {
+int64_t x = Pass(30 * 24 * 60 * 59 * 1000);  // expected-warning 
{{overflow in expression; result is -1746167296 with type 'int'}}
+auto r = Wrap(Pass(30 * 24 * 60 * 59 * 1000));  // expected-warning 
{{overflow in expression; result is -1746167296 with type 'int'}}
+return 0;
+}
+}
+#endif
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15212,6 +15212,8 @@
   Exprs.append(Message->arg_begin(), Message->arg_end());
 else if (auto Construct = dyn_cast(E))
   Exprs.append(Construct->arg_begin(), Construct->arg_end());
+else if (auto Temporary = dyn_cast(E))
+  Exprs.push_back(Temporary->getSubExpr());
 else if (auto Array = dyn_cast(E))
   Exprs.push_back(Array->getIdx());
 else if (auto Compound = dyn_cast(E))
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -544,6 +544,8 @@
   (`#48512 `_).
 - Fixed a failing assertion when parsing incomplete destructor.
   (`#63503 `_)
+- Fixed a missed integer overflow warning with temporary values.
+  (`#63629 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/integer-overflow.cpp
===
--- clang/test/SemaCXX/integer-overflow.cpp
+++ clang/test/SemaCXX/integer-overflow.cpp
@@ -214,3 +214,32 @@
   int a = -(1<<31); // expected-warning {{overflow in expression; result is -2147483648 with type 'int'}}
 }
 }
+
+#if __cplusplus >= 201103L
+namespace GH63629 {
+typedef long long int64_t;
+
+template
+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 Wrap(int64_t x) {
+return nullptr;
+}
+
+int64_t Pass(int64_t x) { return x; }
+
+int m() {
+int64_t x = Pass(30 * 24 * 60 * 59 * 1000);  // expected-warning {{overflow in expression; result is -1746167296 with type 'int'}}
+auto r = Wrap(Pass(30 * 24 * 60 * 59 * 1000));  // expected-warning {{overflow in expression; result is -1746167296 with type 'int'}}
+return 0;
+}
+}
+#endif
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15212,6 +15212,8 @@
   Exprs.append(Message->arg_begin(), Message->arg_end());
 else if (auto Construct = dyn_cast(E))
   Exprs.append(Construct->arg_begin(), Construct->arg_end());
+else if (auto Temporary = dyn_cast(E))
+  Exprs.push_back(Temporary->getSubExpr());
 else if (auto Array = dyn_cast(E))
   Exprs.push_back(Array->getIdx());
 else if (auto Compound = dyn_cast(E))
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -544,6 +544,8 @@
   (`#48512 `_).
 - Fixed a failing assertion when parsing incomplete destructor.
   (`#63503 `_)
+- Fixed a missed integer overflow warning with temporary values.
+  (`#63629 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mai

[PATCH] D154253: [clang] detect integer overflow through temporary values

2023-06-30 Thread Lucile Rose Nihlen via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb776e2a0b03e: [clang] detect integer overflow through 
temporary values (authored by lnihlen).

Changed prior to commit:
  https://reviews.llvm.org/D154253?vs=536466&id=536478#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154253

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaCXX/integer-overflow.cpp


Index: clang/test/SemaCXX/integer-overflow.cpp
===
--- clang/test/SemaCXX/integer-overflow.cpp
+++ clang/test/SemaCXX/integer-overflow.cpp
@@ -214,3 +214,32 @@
   int a = -(1<<31); // expected-warning {{overflow in expression; result is 
-2147483648 with type 'int'}}
 }
 }
+
+#if __cplusplus >= 201103L
+namespace GH63629 {
+typedef long long int64_t;
+
+template
+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 Wrap(int64_t x) {
+return nullptr;
+}
+
+int64_t Pass(int64_t x) { return x; }
+
+int m() {
+int64_t x = Pass(30 * 24 * 60 * 59 * 1000);  // expected-warning 
{{overflow in expression; result is -1746167296 with type 'int'}}
+auto r = Wrap(Pass(30 * 24 * 60 * 59 * 1000));  // expected-warning 
{{overflow in expression; result is -1746167296 with type 'int'}}
+return 0;
+}
+}
+#endif
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15212,6 +15212,8 @@
   Exprs.append(Message->arg_begin(), Message->arg_end());
 else if (auto Construct = dyn_cast(E))
   Exprs.append(Construct->arg_begin(), Construct->arg_end());
+else if (auto Temporary = dyn_cast(E))
+  Exprs.push_back(Temporary->getSubExpr());
 else if (auto Array = dyn_cast(E))
   Exprs.push_back(Array->getIdx());
 else if (auto Compound = dyn_cast(E))
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -561,6 +561,8 @@
   when an immediate invocation appears as a part of an expression that produces
   temporaries.
   (`#60709 `_).
+- Fixed a missed integer overflow warning with temporary values.
+  (`#63629 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/integer-overflow.cpp
===
--- clang/test/SemaCXX/integer-overflow.cpp
+++ clang/test/SemaCXX/integer-overflow.cpp
@@ -214,3 +214,32 @@
   int a = -(1<<31); // expected-warning {{overflow in expression; result is -2147483648 with type 'int'}}
 }
 }
+
+#if __cplusplus >= 201103L
+namespace GH63629 {
+typedef long long int64_t;
+
+template
+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 Wrap(int64_t x) {
+return nullptr;
+}
+
+int64_t Pass(int64_t x) { return x; }
+
+int m() {
+int64_t x = Pass(30 * 24 * 60 * 59 * 1000);  // expected-warning {{overflow in expression; result is -1746167296 with type 'int'}}
+auto r = Wrap(Pass(30 * 24 * 60 * 59 * 1000));  // expected-warning {{overflow in expression; result is -1746167296 with type 'int'}}
+return 0;
+}
+}
+#endif
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15212,6 +15212,8 @@
   Exprs.append(Message->arg_begin(), Message->arg_end());
 else if (auto Construct = dyn_cast(E))
   Exprs.append(Construct->arg_begin(), Construct->arg_end());
+else if (auto Temporary = dyn_cast(E))
+  Exprs.push_back(Temporary->getSubExpr());
 else if (auto Array = dyn_cast(E))
   Exprs.push_back(Array->getIdx());
 else if (auto Compound = dyn_cast(E))
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -561,6 +561,8 @@
   when an immediate invocation appears as a part of an expression that produces
   temporaries.
   (`#60709 `_).
+- Fixed a missed integer overflow warning with temporary values.
+  (`#63629 `_)
 
 Bug Fixes to Compiler Builtins
 

[PATCH] D154253: [clang] detect integer overflow through temporary values

2023-06-30 Thread Lucile Rose Nihlen via Phabricator via cfe-commits
lnihlen created this revision.
Herald added a project: All.
lnihlen requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes GH63629.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154253

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaCXX/integer-overflow.cpp


Index: clang/test/SemaCXX/integer-overflow.cpp
===
--- clang/test/SemaCXX/integer-overflow.cpp
+++ clang/test/SemaCXX/integer-overflow.cpp
@@ -214,3 +214,32 @@
   int a = -(1<<31); // expected-warning {{overflow in expression; result is 
-2147483648 with type 'int'}}
 }
 }
+
+#if __cplusplus >= 201103L
+namespace GH63629 {
+typedef long long int64_t;
+
+template
+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 Wrap(int64_t x) {
+return nullptr;
+}
+
+int64_t Pass(int64_t x) { return x; }
+
+int m() {
+int64_t x = Pass(30 * 24 * 60 * 59 * 1000);  // expected-warning 
{{overflow in expression; result is -1746167296 with type 'int'}}
+auto r = Wrap(Pass(30 * 24 * 60 * 59 * 1000));  // expected-warning 
{{overflow in expression; result is -1746167296 with type 'int'}}
+return 0;
+}
+}
+#endif
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15212,6 +15212,8 @@
   Exprs.append(Message->arg_begin(), Message->arg_end());
 else if (auto Construct = dyn_cast(E))
   Exprs.append(Construct->arg_begin(), Construct->arg_end());
+else if (auto Temporary = dyn_cast(E))
+  Exprs.push_back(Temporary->getSubExpr());
 else if (auto Array = dyn_cast(E))
   Exprs.push_back(Array->getIdx());
 else if (auto Compound = dyn_cast(E))


Index: clang/test/SemaCXX/integer-overflow.cpp
===
--- clang/test/SemaCXX/integer-overflow.cpp
+++ clang/test/SemaCXX/integer-overflow.cpp
@@ -214,3 +214,32 @@
   int a = -(1<<31); // expected-warning {{overflow in expression; result is -2147483648 with type 'int'}}
 }
 }
+
+#if __cplusplus >= 201103L
+namespace GH63629 {
+typedef long long int64_t;
+
+template
+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 Wrap(int64_t x) {
+return nullptr;
+}
+
+int64_t Pass(int64_t x) { return x; }
+
+int m() {
+int64_t x = Pass(30 * 24 * 60 * 59 * 1000);  // expected-warning {{overflow in expression; result is -1746167296 with type 'int'}}
+auto r = Wrap(Pass(30 * 24 * 60 * 59 * 1000));  // expected-warning {{overflow in expression; result is -1746167296 with type 'int'}}
+return 0;
+}
+}
+#endif
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15212,6 +15212,8 @@
   Exprs.append(Message->arg_begin(), Message->arg_end());
 else if (auto Construct = dyn_cast(E))
   Exprs.append(Construct->arg_begin(), Construct->arg_end());
+else if (auto Temporary = dyn_cast(E))
+  Exprs.push_back(Temporary->getSubExpr());
 else if (auto Array = dyn_cast(E))
   Exprs.push_back(Array->getIdx());
 else if (auto Compound = dyn_cast(E))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154253: [clang] detect integer overflow through temporary values

2023-06-30 Thread Lucile Rose Nihlen via Phabricator via cfe-commits
lnihlen updated this revision to Diff 536413.
lnihlen added a comment.

Add release note.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154253

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaCXX/integer-overflow.cpp


Index: clang/test/SemaCXX/integer-overflow.cpp
===
--- clang/test/SemaCXX/integer-overflow.cpp
+++ clang/test/SemaCXX/integer-overflow.cpp
@@ -214,3 +214,32 @@
   int a = -(1<<31); // expected-warning {{overflow in expression; result is 
-2147483648 with type 'int'}}
 }
 }
+
+#if __cplusplus >= 201103L
+namespace GH63629 {
+typedef long long int64_t;
+
+template
+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 Wrap(int64_t x) {
+return nullptr;
+}
+
+int64_t Pass(int64_t x) { return x; }
+
+int m() {
+int64_t x = Pass(30 * 24 * 60 * 59 * 1000);  // expected-warning 
{{overflow in expression; result is -1746167296 with type 'int'}}
+auto r = Wrap(Pass(30 * 24 * 60 * 59 * 1000));  // expected-warning 
{{overflow in expression; result is -1746167296 with type 'int'}}
+return 0;
+}
+}
+#endif
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15212,6 +15212,8 @@
   Exprs.append(Message->arg_begin(), Message->arg_end());
 else if (auto Construct = dyn_cast(E))
   Exprs.append(Construct->arg_begin(), Construct->arg_end());
+else if (auto Temporary = dyn_cast(E))
+  Exprs.push_back(Temporary->getSubExpr());
 else if (auto Array = dyn_cast(E))
   Exprs.push_back(Array->getIdx());
 else if (auto Compound = dyn_cast(E))
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -544,6 +544,8 @@
   (`#48512 `_).
 - Fixed a failing assertion when parsing incomplete destructor.
   (`#63503 `_)
+- Fixed a missed integer overflow warning with temporary values.
+  (`#63629 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/integer-overflow.cpp
===
--- clang/test/SemaCXX/integer-overflow.cpp
+++ clang/test/SemaCXX/integer-overflow.cpp
@@ -214,3 +214,32 @@
   int a = -(1<<31); // expected-warning {{overflow in expression; result is -2147483648 with type 'int'}}
 }
 }
+
+#if __cplusplus >= 201103L
+namespace GH63629 {
+typedef long long int64_t;
+
+template
+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 Wrap(int64_t x) {
+return nullptr;
+}
+
+int64_t Pass(int64_t x) { return x; }
+
+int m() {
+int64_t x = Pass(30 * 24 * 60 * 59 * 1000);  // expected-warning {{overflow in expression; result is -1746167296 with type 'int'}}
+auto r = Wrap(Pass(30 * 24 * 60 * 59 * 1000));  // expected-warning {{overflow in expression; result is -1746167296 with type 'int'}}
+return 0;
+}
+}
+#endif
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15212,6 +15212,8 @@
   Exprs.append(Message->arg_begin(), Message->arg_end());
 else if (auto Construct = dyn_cast(E))
   Exprs.append(Construct->arg_begin(), Construct->arg_end());
+else if (auto Temporary = dyn_cast(E))
+  Exprs.push_back(Temporary->getSubExpr());
 else if (auto Array = dyn_cast(E))
   Exprs.push_back(Array->getIdx());
 else if (auto Compound = dyn_cast(E))
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -544,6 +544,8 @@
   (`#48512 `_).
 - Fixed a failing assertion when parsing incomplete destructor.
   (`#63503 `_)
+- Fixed a missed integer overflow warning with temporary values.
+  (`#63629 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/li

[PATCH] D154253: [clang] detect integer overflow through temporary values

2023-06-30 Thread Lucile Rose Nihlen via Phabricator via cfe-commits
lnihlen added a comment.

Added release note, fixed commit log. PTAL, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154253

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