Author: Youngsuk Kim Date: 2024-11-22T04:51:09-05:00 New Revision: ef206446f2bbcb1bacc73d7611a96c457f59499f
URL: https://github.com/llvm/llvm-project/commit/ef206446f2bbcb1bacc73d7611a96c457f59499f DIFF: https://github.com/llvm/llvm-project/commit/ef206446f2bbcb1bacc73d7611a96c457f59499f.diff LOG: [clang] Warn const integer-overflow of member in temporary struct bound to rvalue reference (#117225) Fixes #46755 --------- Co-authored-by: Sirraide <aeternalm...@gmail.com> Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaChecking.cpp clang/test/SemaCXX/integer-overflow.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 4847437ef1f8bd..54145b28154eb4 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -580,6 +580,9 @@ Improvements to Clang's diagnostics - Improved error recovery for function call arguments with trailing commas (#GH100921). +- 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..a49605e4867651 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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits