[clang] [Clang][ExprConstant] fix constant expression did not evaluate to integer (PR #97146)
https://github.com/Backl1ght closed https://github.com/llvm/llvm-project/pull/97146 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][ExprConstant] fix constant expression did not evaluate to integer (PR #97146)
https://github.com/Backl1ght updated https://github.com/llvm/llvm-project/pull/97146 >From 804c18269ab0c8018834a89f286e05c7e479ed42 Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Sat, 29 Jun 2024 15:26:21 +0800 Subject: [PATCH 1/2] fix --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/AST/ExprConstant.cpp | 2 +- clang/test/SemaCXX/eval-crashes.cpp | 10 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index f6431a76b38de..ad129da506b64 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -967,6 +967,7 @@ Bug Fixes to C++ Support - Fixed an assertion failure about invalid conversion when calling lambda. (#GH96205). - Fixed a bug where the first operand of binary ``operator&`` would be transformed as if it was the operand of the address of operator. (#GH97483). +- Fixed an assertion failure about constant expression did not evaluate to integer. (#GH96670). Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 374a3acf7aa26..0ccdc5eaabeef 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -15858,7 +15858,7 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult , } if (const auto *CE = dyn_cast(Exp)) { -if (CE->hasAPValueResult()) { +if (CE->hasAPValueResult() && !CE->getAPValueResult().isLValue()) { Result.Val = CE->getAPValueResult(); IsConst = true; return true; diff --git a/clang/test/SemaCXX/eval-crashes.cpp b/clang/test/SemaCXX/eval-crashes.cpp index 017df977b26b7..0865dafe4bf92 100644 --- a/clang/test/SemaCXX/eval-crashes.cpp +++ b/clang/test/SemaCXX/eval-crashes.cpp @@ -61,3 +61,13 @@ struct array { array() : data(*new int[1][2]) {} }; } + +namespace GH96670 { +inline constexpr long ullNil = -1; + +template +struct Test {}; + +inline constexpr long lNil = -1; +Test c; +} >From f72cad6f736b2555ac15f169b7d8614b2649c7f9 Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Sat, 29 Jun 2024 16:42:07 +0800 Subject: [PATCH 2/2] address comments --- clang/docs/ReleaseNotes.rst| 3 ++- clang/lib/AST/ExprConstant.cpp | 11 +++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ad129da506b64..d60c6fbf15d56 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -967,7 +967,8 @@ Bug Fixes to C++ Support - Fixed an assertion failure about invalid conversion when calling lambda. (#GH96205). - Fixed a bug where the first operand of binary ``operator&`` would be transformed as if it was the operand of the address of operator. (#GH97483). -- Fixed an assertion failure about constant expression did not evaluate to integer. (#GH96670). +- Fixed an assertion failure about a constant expression which is a known integer but is not + evaluated to an integer. (#GH96670). Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 0ccdc5eaabeef..e0c9ef68cb448 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -15858,10 +15858,13 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult , } if (const auto *CE = dyn_cast(Exp)) { -if (CE->hasAPValueResult() && !CE->getAPValueResult().isLValue()) { - Result.Val = CE->getAPValueResult(); - IsConst = true; - return true; +if (CE->hasAPValueResult()) { + APValue APV = CE->getAPValueResult(); + if (!APV.isLValue()) { +Result.Val = std::move(APV); +IsConst = true; +return true; + } } // The SubExpr is usually just an IntegerLiteral. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][ExprConstant] fix constant expression did not evaluate to integer (PR #97146)
https://github.com/Backl1ght updated https://github.com/llvm/llvm-project/pull/97146 >From 7e14846e93df9f86b994c526b0da1f729c9b7cd4 Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Sat, 29 Jun 2024 15:26:21 +0800 Subject: [PATCH 1/2] fix --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/AST/ExprConstant.cpp | 2 +- clang/test/SemaCXX/eval-crashes.cpp | 10 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index f6431a76b38de..ad129da506b64 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -967,6 +967,7 @@ Bug Fixes to C++ Support - Fixed an assertion failure about invalid conversion when calling lambda. (#GH96205). - Fixed a bug where the first operand of binary ``operator&`` would be transformed as if it was the operand of the address of operator. (#GH97483). +- Fixed an assertion failure about constant expression did not evaluate to integer. (#GH96670). Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 374a3acf7aa26..0ccdc5eaabeef 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -15858,7 +15858,7 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult , } if (const auto *CE = dyn_cast(Exp)) { -if (CE->hasAPValueResult()) { +if (CE->hasAPValueResult() && !CE->getAPValueResult().isLValue()) { Result.Val = CE->getAPValueResult(); IsConst = true; return true; diff --git a/clang/test/SemaCXX/eval-crashes.cpp b/clang/test/SemaCXX/eval-crashes.cpp index 017df977b26b7..0865dafe4bf92 100644 --- a/clang/test/SemaCXX/eval-crashes.cpp +++ b/clang/test/SemaCXX/eval-crashes.cpp @@ -61,3 +61,13 @@ struct array { array() : data(*new int[1][2]) {} }; } + +namespace GH96670 { +inline constexpr long ullNil = -1; + +template +struct Test {}; + +inline constexpr long lNil = -1; +Test c; +} >From 247ea9d7257abd284823ec1ef61d79b3102fc89c Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Sat, 29 Jun 2024 16:42:07 +0800 Subject: [PATCH 2/2] address comments --- clang/docs/ReleaseNotes.rst| 3 ++- clang/lib/AST/ExprConstant.cpp | 11 +++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ad129da506b64..d60c6fbf15d56 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -967,7 +967,8 @@ Bug Fixes to C++ Support - Fixed an assertion failure about invalid conversion when calling lambda. (#GH96205). - Fixed a bug where the first operand of binary ``operator&`` would be transformed as if it was the operand of the address of operator. (#GH97483). -- Fixed an assertion failure about constant expression did not evaluate to integer. (#GH96670). +- Fixed an assertion failure about a constant expression which is a known integer but is not + evaluated to an integer. (#GH96670). Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 0ccdc5eaabeef..e0c9ef68cb448 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -15858,10 +15858,13 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult , } if (const auto *CE = dyn_cast(Exp)) { -if (CE->hasAPValueResult() && !CE->getAPValueResult().isLValue()) { - Result.Val = CE->getAPValueResult(); - IsConst = true; - return true; +if (CE->hasAPValueResult()) { + APValue APV = CE->getAPValueResult(); + if (!APV.isLValue()) { +Result.Val = std::move(APV); +IsConst = true; +return true; + } } // The SubExpr is usually just an IntegerLiteral. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][ExprConstant] fix constant expression did not evaluate to integer (PR #97146)
Backl1ght wrote: > I'm concerned that we're calling EvaluateKnownConstInt on an lvalue; that > might indicate there's something wrong with the AST. Usually there should be > an lvalue-to-rvalue cast somewhere. @efriedma-quic lvalue-to-rvalue cast is done here at https://github.com/llvm/llvm-project/blob/aec7670b5d6354b63b011c9ed0632b70983b0328/clang/lib/AST/ExprConstant.cpp#L15829-L15835 https://github.com/llvm/llvm-project/pull/97146 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][ExprConstant] fix constant expression did not evaluate to integer (PR #97146)
https://github.com/Backl1ght updated https://github.com/llvm/llvm-project/pull/97146 >From 5a443296eecbdf90d1cf274c3e52797be380bdd3 Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Sat, 29 Jun 2024 15:26:21 +0800 Subject: [PATCH 1/2] fix --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/AST/ExprConstant.cpp | 2 +- clang/test/SemaCXX/eval-crashes.cpp | 10 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index feba3c7ba8d77..8ec1c105cef9f 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -936,6 +936,7 @@ Bug Fixes to C++ Support forward-declared class. (#GH93512). - Fixed a bug in access checking inside return-type-requirement of compound requirements. (#GH93788). - Fixed an assertion failure about invalid conversion when calling lambda. (#GH96205). +- Fixed an assertion failure about constant expression did not evaluate to integer. (#GH96670). Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 374a3acf7aa26..0ccdc5eaabeef 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -15858,7 +15858,7 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult , } if (const auto *CE = dyn_cast(Exp)) { -if (CE->hasAPValueResult()) { +if (CE->hasAPValueResult() && !CE->getAPValueResult().isLValue()) { Result.Val = CE->getAPValueResult(); IsConst = true; return true; diff --git a/clang/test/SemaCXX/eval-crashes.cpp b/clang/test/SemaCXX/eval-crashes.cpp index 017df977b26b7..0865dafe4bf92 100644 --- a/clang/test/SemaCXX/eval-crashes.cpp +++ b/clang/test/SemaCXX/eval-crashes.cpp @@ -61,3 +61,13 @@ struct array { array() : data(*new int[1][2]) {} }; } + +namespace GH96670 { +inline constexpr long ullNil = -1; + +template +struct Test {}; + +inline constexpr long lNil = -1; +Test c; +} >From 7950d951b30013bac73af9a9028d932e1c48800e Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Sat, 29 Jun 2024 16:42:07 +0800 Subject: [PATCH 2/2] address comments --- clang/docs/ReleaseNotes.rst| 3 ++- clang/lib/AST/ExprConstant.cpp | 11 +++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 8ec1c105cef9f..46b22f43b9b71 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -936,7 +936,8 @@ Bug Fixes to C++ Support forward-declared class. (#GH93512). - Fixed a bug in access checking inside return-type-requirement of compound requirements. (#GH93788). - Fixed an assertion failure about invalid conversion when calling lambda. (#GH96205). -- Fixed an assertion failure about constant expression did not evaluate to integer. (#GH96670). +- Fixed an assertion failure about a constant expression which is a known integer but is not + evaluated to an integer. (#GH96670). Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 0ccdc5eaabeef..e0c9ef68cb448 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -15858,10 +15858,13 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult , } if (const auto *CE = dyn_cast(Exp)) { -if (CE->hasAPValueResult() && !CE->getAPValueResult().isLValue()) { - Result.Val = CE->getAPValueResult(); - IsConst = true; - return true; +if (CE->hasAPValueResult()) { + APValue APV = CE->getAPValueResult(); + if (!APV.isLValue()) { +Result.Val = std::move(APV); +IsConst = true; +return true; + } } // The SubExpr is usually just an IntegerLiteral. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][ExprConstant] fix constant expression did not evaluate to integer (PR #97146)
https://github.com/Backl1ght created https://github.com/llvm/llvm-project/pull/97146 fixes https://github.com/llvm/llvm-project/issues/96670 The cause is that we might return a lvalue here at https://github.com/llvm/llvm-project/blob/3e53c97d33210db68188e731e93ee48dbaeeae32/clang/lib/AST/ExprConstant.cpp#L15861-L15865 This PR will make sure we return a rvalue in `FastEvaluateAsRValue`. >From 5a443296eecbdf90d1cf274c3e52797be380bdd3 Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Sat, 29 Jun 2024 15:26:21 +0800 Subject: [PATCH] fix --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/AST/ExprConstant.cpp | 2 +- clang/test/SemaCXX/eval-crashes.cpp | 10 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index feba3c7ba8d77..8ec1c105cef9f 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -936,6 +936,7 @@ Bug Fixes to C++ Support forward-declared class. (#GH93512). - Fixed a bug in access checking inside return-type-requirement of compound requirements. (#GH93788). - Fixed an assertion failure about invalid conversion when calling lambda. (#GH96205). +- Fixed an assertion failure about constant expression did not evaluate to integer. (#GH96670). Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 374a3acf7aa26..0ccdc5eaabeef 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -15858,7 +15858,7 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult , } if (const auto *CE = dyn_cast(Exp)) { -if (CE->hasAPValueResult()) { +if (CE->hasAPValueResult() && !CE->getAPValueResult().isLValue()) { Result.Val = CE->getAPValueResult(); IsConst = true; return true; diff --git a/clang/test/SemaCXX/eval-crashes.cpp b/clang/test/SemaCXX/eval-crashes.cpp index 017df977b26b7..0865dafe4bf92 100644 --- a/clang/test/SemaCXX/eval-crashes.cpp +++ b/clang/test/SemaCXX/eval-crashes.cpp @@ -61,3 +61,13 @@ struct array { array() : data(*new int[1][2]) {} }; } + +namespace GH96670 { +inline constexpr long ullNil = -1; + +template +struct Test {}; + +inline constexpr long lNil = -1; +Test c; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] fix assertion failure about invalid conversion when calling lambda (PR #96431)
https://github.com/Backl1ght closed https://github.com/llvm/llvm-project/pull/96431 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] fix assertion failure about invalid conversion when calling lambda (PR #96431)
https://github.com/Backl1ght updated https://github.com/llvm/llvm-project/pull/96431 >From ce317e4c2f1bca3e81b81ac8909c576b14a16a6b Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Sun, 23 Jun 2024 21:44:03 +0800 Subject: [PATCH] fix --- clang/docs/ReleaseNotes.rst| 1 + clang/lib/Sema/SemaOverload.cpp| 2 +- clang/test/SemaCXX/lambda-call.cpp | 11 +++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/lambda-call.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index da967fcdda808..feba3c7ba8d77 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -935,6 +935,7 @@ Bug Fixes to C++ Support - Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a forward-declared class. (#GH93512). - Fixed a bug in access checking inside return-type-requirement of compound requirements. (#GH93788). +- Fixed an assertion failure about invalid conversion when calling lambda. (#GH96205). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index ee921c825b2a4..f8f55ce6526ac 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -12169,7 +12169,7 @@ static void NoteFunctionCandidate(Sema , OverloadCandidate *Cand, case ovl_fail_bad_conversion: { unsigned I = (Cand->IgnoreObjectArgument ? 1 : 0); for (unsigned N = Cand->Conversions.size(); I != N; ++I) - if (Cand->Conversions[I].isBad()) + if (Cand->Conversions[I].isInitialized() && Cand->Conversions[I].isBad()) return DiagnoseBadConversion(S, Cand, I, TakingCandidateAddress); // FIXME: this currently happens when we're called from SemaInit diff --git a/clang/test/SemaCXX/lambda-call.cpp b/clang/test/SemaCXX/lambda-call.cpp new file mode 100644 index 0..2c5b8b9a4b176 --- /dev/null +++ b/clang/test/SemaCXX/lambda-call.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -std=c++23 -verify -fsyntax-only %s + +namespace GH96205 { + +void f() { + auto l = [](this auto& self, int) -> void { self("j"); }; // expected-error {{no matching function for call to object of type}} \ +// expected-note {{no known conversion from 'const char[2]' to 'int'}} + l(3); // expected-note {{requested here}} +} + +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] fix assertion failure about invalid conversion when calling lambda (PR #96431)
https://github.com/Backl1ght created https://github.com/llvm/llvm-project/pull/96431 fixes https://github.com/llvm/llvm-project/issues/96205 The cause is that some `Conversions[ConvIdx]` here is not initialized https://github.com/llvm/llvm-project/blob/eb76bc38ffc286e62fdb8f8d897b5de04b2575be/clang/lib/Sema/SemaOverload.cpp#L7888-L7901 and we do not check whether `Cand->Conversions[I]` is initialized or not here. https://github.com/llvm/llvm-project/blob/eb76bc38ffc286e62fdb8f8d897b5de04b2575be/clang/lib/Sema/SemaOverload.cpp#L12148-L12158 >From f508b255f72e691908a625dc104c0624ab232f66 Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Sun, 23 Jun 2024 21:44:03 +0800 Subject: [PATCH] fix --- clang/docs/ReleaseNotes.rst| 1 + clang/lib/Sema/SemaOverload.cpp| 2 +- clang/test/SemaCXX/lambda-call.cpp | 11 +++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/lambda-call.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 9c8f8c4a4fbaf..d13558040b7c0 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -915,6 +915,7 @@ Bug Fixes to C++ Support - Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a forward-declared class. (#GH93512). - Fixed a bug in access checking inside return-type-requirement of compound requirements. (#GH93788). +- Fixed an assertion failure about invalid conversion when calling lambda. (#GH96205). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index fb4ff72e42eb5..b866364028d09 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -12148,7 +12148,7 @@ static void NoteFunctionCandidate(Sema , OverloadCandidate *Cand, case ovl_fail_bad_conversion: { unsigned I = (Cand->IgnoreObjectArgument ? 1 : 0); for (unsigned N = Cand->Conversions.size(); I != N; ++I) - if (Cand->Conversions[I].isBad()) + if (Cand->Conversions[I].isInitialized() && Cand->Conversions[I].isBad()) return DiagnoseBadConversion(S, Cand, I, TakingCandidateAddress); // FIXME: this currently happens when we're called from SemaInit diff --git a/clang/test/SemaCXX/lambda-call.cpp b/clang/test/SemaCXX/lambda-call.cpp new file mode 100644 index 0..2c5b8b9a4b176 --- /dev/null +++ b/clang/test/SemaCXX/lambda-call.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -std=c++23 -verify -fsyntax-only %s + +namespace GH96205 { + +void f() { + auto l = [](this auto& self, int) -> void { self("j"); }; // expected-error {{no matching function for call to object of type}} \ +// expected-note {{no known conversion from 'const char[2]' to 'int'}} + l(3); // expected-note {{requested here}} +} + +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix access checking inside return-type-requirement of compound requirements (PR #95651)
https://github.com/Backl1ght closed https://github.com/llvm/llvm-project/pull/95651 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix access checking inside return-type-requirement of compound requirements (PR #95651)
https://github.com/Backl1ght updated https://github.com/llvm/llvm-project/pull/95651 >From 64ee10bf71d79c97f45779dbbd9f74e85a5676ee Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Sat, 15 Jun 2024 16:56:00 +0800 Subject: [PATCH] fix --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaTemplateInstantiate.cpp| 2 +- .../expr.prim.req/compound-requirement.cpp| 36 +++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 7ac0fa0141b47..9c8f8c4a4fbaf 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -914,6 +914,7 @@ Bug Fixes to C++ Support - Clang now diagnoses explicit specializations with storage class specifiers in all contexts. - Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a forward-declared class. (#GH93512). +- Fixed a bug in access checking inside return-type-requirement of compound requirements. (#GH93788). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 863cc53c55afa..1fe1fe9d4f833 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -2735,7 +2735,7 @@ TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) { if (TPLInst.isInvalid()) return nullptr; TemplateParameterList *TPL = TransformTemplateParameterList(OrigTPL); -if (!TPL) +if (!TPL || Trap.hasErrorOccurred()) TransRetReq.emplace(createSubstDiag(SemaRef, Info, [&] (llvm::raw_ostream& OS) { RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint() diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp index b7366207882f9..dc0e84280e056 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp @@ -189,3 +189,39 @@ namespace std_example { template struct C5_check {}; // expected-note{{because 'short' does not satisfy 'C5'}} using c5 = C5_check; // expected-error{{constraints not satisfied for class template 'C5_check' [with T = short]}} } + +namespace access_checks { +namespace in_return_type_requirement { + +// https://github.com/llvm/llvm-project/issues/93788 +template +concept is_assignable = requires(From from, To to) { + from = to; +}; + +template +class trait { + public: + using public_type = int; + private: + using private_type = int; +}; + +template +concept has_field = requires(T t) { + { t.field } -> is_assignable::private_type>; // expected-note {{'private_type' is a private member}} +}; +template +concept has_field2 = requires(T t) { + { t.field } -> is_assignable::public_type>; +}; + +struct A { + int field; +}; +static_assert(has_field); // expected-error {{static assertion failed}} \ + // expected-note {{because 'A' does not satisfy 'has_field'}} +static_assert(has_field2); + +} // namespace access_checks +} // namespace in_return_type_requirement ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix access checking inside return-type-requirement of compound requirements (PR #95651)
https://github.com/Backl1ght updated https://github.com/llvm/llvm-project/pull/95651 >From 1c283900fc4bc984ebd917ead6ddd8c5d0364d80 Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Sat, 15 Jun 2024 16:56:00 +0800 Subject: [PATCH] fix --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaTemplateInstantiate.cpp| 2 +- .../expr.prim.req/compound-requirement.cpp| 36 +++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 7ac0fa0141b47..9c8f8c4a4fbaf 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -914,6 +914,7 @@ Bug Fixes to C++ Support - Clang now diagnoses explicit specializations with storage class specifiers in all contexts. - Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a forward-declared class. (#GH93512). +- Fixed a bug in access checking inside return-type-requirement of compound requirements. (#GH93788). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 863cc53c55afa..1fe1fe9d4f833 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -2735,7 +2735,7 @@ TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) { if (TPLInst.isInvalid()) return nullptr; TemplateParameterList *TPL = TransformTemplateParameterList(OrigTPL); -if (!TPL) +if (!TPL || Trap.hasErrorOccurred()) TransRetReq.emplace(createSubstDiag(SemaRef, Info, [&] (llvm::raw_ostream& OS) { RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint() diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp index b7366207882f9..dc0e84280e056 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp @@ -189,3 +189,39 @@ namespace std_example { template struct C5_check {}; // expected-note{{because 'short' does not satisfy 'C5'}} using c5 = C5_check; // expected-error{{constraints not satisfied for class template 'C5_check' [with T = short]}} } + +namespace access_checks { +namespace in_return_type_requirement { + +// https://github.com/llvm/llvm-project/issues/93788 +template +concept is_assignable = requires(From from, To to) { + from = to; +}; + +template +class trait { + public: + using public_type = int; + private: + using private_type = int; +}; + +template +concept has_field = requires(T t) { + { t.field } -> is_assignable::private_type>; // expected-note {{'private_type' is a private member}} +}; +template +concept has_field2 = requires(T t) { + { t.field } -> is_assignable::public_type>; +}; + +struct A { + int field; +}; +static_assert(has_field); // expected-error {{static assertion failed}} \ + // expected-note {{because 'A' does not satisfy 'has_field'}} +static_assert(has_field2); + +} // namespace access_checks +} // namespace in_return_type_requirement ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix access checking inside return-type-requirement of compound requirements (PR #95651)
https://github.com/Backl1ght updated https://github.com/llvm/llvm-project/pull/95651 >From 49f0d1aff888b2a96ed3a19d8d2e30d367caf14f Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Sat, 15 Jun 2024 16:56:00 +0800 Subject: [PATCH] fix --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaTemplateInstantiate.cpp| 2 +- .../expr.prim.req/compound-requirement.cpp| 36 +++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 36efeb8c70cca..3717e573419e7 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -858,6 +858,7 @@ Bug Fixes to C++ Support - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). +- Fixed a bug in access checking inside return-type-requirement of compound requirements. (#GH93788). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 863cc53c55afa..1fe1fe9d4f833 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -2735,7 +2735,7 @@ TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) { if (TPLInst.isInvalid()) return nullptr; TemplateParameterList *TPL = TransformTemplateParameterList(OrigTPL); -if (!TPL) +if (!TPL || Trap.hasErrorOccurred()) TransRetReq.emplace(createSubstDiag(SemaRef, Info, [&] (llvm::raw_ostream& OS) { RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint() diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp index b7366207882f9..dc0e84280e056 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp @@ -189,3 +189,39 @@ namespace std_example { template struct C5_check {}; // expected-note{{because 'short' does not satisfy 'C5'}} using c5 = C5_check; // expected-error{{constraints not satisfied for class template 'C5_check' [with T = short]}} } + +namespace access_checks { +namespace in_return_type_requirement { + +// https://github.com/llvm/llvm-project/issues/93788 +template +concept is_assignable = requires(From from, To to) { + from = to; +}; + +template +class trait { + public: + using public_type = int; + private: + using private_type = int; +}; + +template +concept has_field = requires(T t) { + { t.field } -> is_assignable::private_type>; // expected-note {{'private_type' is a private member}} +}; +template +concept has_field2 = requires(T t) { + { t.field } -> is_assignable::public_type>; +}; + +struct A { + int field; +}; +static_assert(has_field); // expected-error {{static assertion failed}} \ + // expected-note {{because 'A' does not satisfy 'has_field'}} +static_assert(has_field2); + +} // namespace access_checks +} // namespace in_return_type_requirement ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix access checking inside return-type-requirement of compound requirements (PR #95651)
https://github.com/Backl1ght created https://github.com/llvm/llvm-project/pull/95651 fixes https://github.com/llvm/llvm-project/issues/93788 . >From 7911a757d6b97a12baf465d0fe1a9442ca2ee76b Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Sat, 15 Jun 2024 16:56:00 +0800 Subject: [PATCH] fix --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaTemplateInstantiate.cpp| 2 +- .../expr.prim.req/compound-requirement.cpp| 36 +++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 36efeb8c70cca..3717e573419e7 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -858,6 +858,7 @@ Bug Fixes to C++ Support - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). +- Fixed a bug in access checking inside return-type-requirement of compound requirements. (#GH93788). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 863cc53c55afa..1fe1fe9d4f833 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -2735,7 +2735,7 @@ TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) { if (TPLInst.isInvalid()) return nullptr; TemplateParameterList *TPL = TransformTemplateParameterList(OrigTPL); -if (!TPL) +if (!TPL || Trap.hasErrorOccurred()) TransRetReq.emplace(createSubstDiag(SemaRef, Info, [&] (llvm::raw_ostream& OS) { RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint() diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp index b7366207882f9..dc0e84280e056 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp @@ -189,3 +189,39 @@ namespace std_example { template struct C5_check {}; // expected-note{{because 'short' does not satisfy 'C5'}} using c5 = C5_check; // expected-error{{constraints not satisfied for class template 'C5_check' [with T = short]}} } + +namespace access_checks { +namespace in_return_type_requirement { + +// https://github.com/llvm/llvm-project/issues/93788 +template +concept is_assignable = requires(From from, To to) { + from = to; +}; + +template +class trait { + public: + using public_type = int; + private: + using private_type = int; +}; + +template +concept has_field = requires(T t) { + { t.field } -> is_assignable::private_type>; // expected-note {{'private_type' is a private member}} +}; +template +concept has_field2 = requires(T t) { + { t.field } -> is_assignable::public_type>; +}; + +struct A { + int field; +}; +static_assert(has_field); // expected-error {{static assertion failed}} \ + // expected-note {{because 'A' does not satisfy 'has_field'}} +static_assert(has_field2); + +} // namespace access_checks +} // namespace in_return_type_requirement ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix typo (PR #73644)
https://github.com/Backl1ght closed https://github.com/llvm/llvm-project/pull/73644 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix typo (PR #73644)
https://github.com/Backl1ght updated https://github.com/llvm/llvm-project/pull/73644 >From 1381fd047b27a019166b6c9552c55afaa916ee39 Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Tue, 28 Nov 2023 21:18:49 +0800 Subject: [PATCH] [clang] fix typo --- clang/lib/Sema/SemaInit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index c0c321f0f200d21..50ee0a5acb5586a 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -10628,7 +10628,7 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer( bool AllowExplicit = !Kind.isCopyInit() || ListInit; - // Return true is the candidate is added successfully, false otherwise. + // Return true if the candidate is added successfully, false otherwise. auto addDeductionCandidate = [&](FunctionTemplateDecl *TD, CXXDeductionGuideDecl *GD, DeclAccessPair FoundDecl, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[openmp] [clang] [llvm] [clang] fix typo (PR #73644)
https://github.com/Backl1ght updated https://github.com/llvm/llvm-project/pull/73644 >From a417fb4d421cc28115bb2ea2062fb400586a7042 Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Tue, 28 Nov 2023 21:18:49 +0800 Subject: [PATCH] [clang] fix typo --- clang/lib/Sema/SemaInit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index c0c321f0f200d21..50ee0a5acb5586a 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -10628,7 +10628,7 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer( bool AllowExplicit = !Kind.isCopyInit() || ListInit; - // Return true is the candidate is added successfully, false otherwise. + // Return true if the candidate is added successfully, false otherwise. auto addDeductionCandidate = [&](FunctionTemplateDecl *TD, CXXDeductionGuideDecl *GD, DeclAccessPair FoundDecl, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix typo (PR #73644)
https://github.com/Backl1ght created https://github.com/llvm/llvm-project/pull/73644 None >From a417fb4d421cc28115bb2ea2062fb400586a7042 Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Tue, 28 Nov 2023 21:18:49 +0800 Subject: [PATCH] [clang] fix typo --- clang/lib/Sema/SemaInit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index c0c321f0f200d21..50ee0a5acb5586a 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -10628,7 +10628,7 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer( bool AllowExplicit = !Kind.isCopyInit() || ListInit; - // Return true is the candidate is added successfully, false otherwise. + // Return true if the candidate is added successfully, false otherwise. auto addDeductionCandidate = [&](FunctionTemplateDecl *TD, CXXDeductionGuideDecl *GD, DeclAccessPair FoundDecl, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits