llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Youngsuk Kim (JOE1994)

<details>
<summary>Changes</summary>

Fixes #<!-- -->46755

---
Full diff: https://github.com/llvm/llvm-project/pull/117225.diff


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+2-1) 
- (modified) clang/test/SemaCXX/integer-overflow.cpp (+6) 


``````````diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8c81de341937ca..8820ba0fb24b38 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -578,6 +578,9 @@ Improvements to Clang's diagnostics
 
 - Clang now omits shadowing warnings for parameter names in explicit object 
member functions (#GH95707).
 
+- For an rvalue reference bound to a temporary struct with an integer member, 
Clang will detect constant integer overflow
+  in the initializer for the integer member (#GH46755).
+
 Improvements to Clang's time-trace
 ----------------------------------
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2fd990750ed212..e36cb318c61885 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -12048,7 +12048,8 @@ void Sema::CheckForIntOverflow (const Expr *E) {
              New && New->isArray()) {
       if (auto ArraySize = New->getArraySize())
         Exprs.push_back(*ArraySize);
-    }
+    } else if (const auto *Mte = dyn_cast<MaterializeTemporaryExpr>(OriginalE))
+      Exprs.push_back(Mte->getSubExpr());
   } while (!Exprs.empty());
 }
 
diff --git a/clang/test/SemaCXX/integer-overflow.cpp 
b/clang/test/SemaCXX/integer-overflow.cpp
index d1cc8bee566f6b..73a4e88ee6c098 100644
--- a/clang/test/SemaCXX/integer-overflow.cpp
+++ b/clang/test/SemaCXX/integer-overflow.cpp
@@ -246,4 +246,10 @@ int m() {
     return 0;
 }
 }
+
+namespace GH46755 {
+void f() {
+    struct { int v; } &&r = {512 * 1024 * 1024 * 1024}; // expected-warning 
{{overflow in expression; result is 0 with type 'int'}}
+}
+}
 #endif

``````````

</details>


https://github.com/llvm/llvm-project/pull/117225
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to