From: Takuya Shimizu Date: Mon, 17 Apr 2023 13:48:58 +0000 (-0400) Subject: Constexpr evaluator should treat [[gnu::weak]] member pointer comparisons as evaluati... X-Git-Tag: upstream/17.0.6~11367 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a4edc2c9fa35a763fc5f4c9cf6383096a13a9cf6;p=platform%2Fupstream%2Fllvm.git 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 --- diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 9c8a0e1..05189bf 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -312,6 +312,8 @@ Bug Fixes in This Version (`#61417 `_) - Fix crash after suggesting typo correction to constexpr if condition. (`#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 fbe92d0..6bfb3a3 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 0000000..28a5169 --- /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}} +