Author: Takuya Shimizu Date: 2023-04-17T09:50:46-04:00 New Revision: a4edc2c9fa35a763fc5f4c9cf6383096a13a9cf6
URL: https://github.com/llvm/llvm-project/commit/a4edc2c9fa35a763fc5f4c9cf6383096a13a9cf6 DIFF: https://github.com/llvm/llvm-project/commit/a4edc2c9fa35a763fc5f4c9cf6383096a13a9cf6.diff LOG: Constexpr evaluator should treat [[gnu::weak]] member pointer comparisons as evaluation failure This patch fixes the wrong signal from the constexpr evaluator that [[gnu::weak]] member pointer comparison is valid, while it is emitting notes on them. I found a crashing case fixed by this change and added it as a test case: https://godbolt.org/z/8391fGjGn I noticed this while I was working on D146358. Differential Revision: https://reviews.llvm.org/D148419 Added: clang/test/SemaCXX/crash-lambda-weak-attr.cpp Modified: clang/docs/ReleaseNotes.rst clang/lib/AST/ExprConstant.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 9c8a0e1faa32..05189bfb6aba 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -312,6 +312,8 @@ Bug Fixes in This Version (`#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 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index fbe92d054d6b..6bfb3a37b243 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -13142,12 +13142,12 @@ EvaluateComparisonBinaryOperator(EvalInfo &Info, const BinaryOperator *E, 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: diff --git a/clang/test/SemaCXX/crash-lambda-weak-attr.cpp b/clang/test/SemaCXX/crash-lambda-weak-attr.cpp new file mode 100644 index 000000000000..28a516942393 --- /dev/null +++ b/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}} + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits