[PATCH] D148419: [clang][AST] Constexpr evaluator should treat [[gnu::weak]] member pointer comparisons as evaluation failure
Takuya Shimizu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 17 05:53:17 PDT 2023
hazohelet updated this revision to Diff 514179.
hazohelet added a comment.
Address comments from @aaron.ballman
- Added release note
- Do not specify std c++ version in test code
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D148419/new/
https://reviews.llvm.org/D148419
Files:
clang/docs/ReleaseNotes.rst
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/crash-lambda-weak-attr.cpp
Index: clang/test/SemaCXX/crash-lambda-weak-attr.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/crash-lambda-weak-attr.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct Weak {
+ [[gnu::weak]]void weak_method();
+};
+static_assert([](){ return &Weak::weak_method != nullptr; }()); // expected-error {{static assertion expression is not an integral constant expression}} \
+ // expected-note {{comparison against pointer to weak member 'Weak::weak_method' can only be performed at runtime}} \
+ // expected-note {{in call to}}
+
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -13142,12 +13142,12 @@
if (LHSValue.getDecl() && LHSValue.getDecl()->isWeak()) {
Info.FFDiag(E, diag::note_constexpr_mem_pointer_weak_comparison)
<< LHSValue.getDecl();
- return true;
+ return false;
}
if (RHSValue.getDecl() && RHSValue.getDecl()->isWeak()) {
Info.FFDiag(E, diag::note_constexpr_mem_pointer_weak_comparison)
<< RHSValue.getDecl();
- return true;
+ return false;
}
// C++11 [expr.eq]p2:
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -309,6 +309,8 @@
(`#61417 <https://github.com/llvm/llvm-project/issues/61417>`_)
- Fix crash after suggesting typo correction to constexpr if condition.
(`#61885 <https://github.com/llvm/llvm-project/issues/61885>`_)
+- Clang constexpr evaluator now treats comparison of [[gnu::weak]]-attributed
+ member pointer as an invalid expression.
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148419.514179.patch
Type: text/x-patch
Size: 1991 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230417/a836e9de/attachment.bin>
More information about the cfe-commits
mailing list