hazohelet created this revision. hazohelet added reviewers: rsmith, tbaeder, shafik, aaron.ballman. Herald added a project: All. hazohelet requested review of this revision. Herald added a project: clang.
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 <https://reviews.llvm.org/D146358> CC @rsmith as the original author Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D148419 Files: 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 -std=c++2b %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/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 -std=c++2b %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:
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits