-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Clang] Properly set the value category of dependent unary operators #88740
Conversation
This fixes an assertion in Expr::Classify when a trying to deduce a dependent dereference operator. Fixes llvm#88329
@llvm/pr-subscribers-clang Author: cor3ntin (cor3ntin) ChangesThis fixes an assertion in Expr::Classify when a Fixes #88329 Full diff: https://github.com/llvm/llvm-project/pull/88740.diff 4 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c4a4893aec5cd6..e68c89a70731cd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -528,6 +528,7 @@ Bug Fixes to C++ Support
- Clang now correctly tracks type dependence of by-value captures in lambdas with an explicit
object parameter.
Fixes (#GH70604), (#GH79754), (#GH84163), (#GH84425), (#GH86054), (#GH86398), and (#GH86399).
+- Fix a crash when deducing ``auto`` from an invalid dereference (#GH88329).
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 3808af37ff54a8..e040911b003256 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -14394,9 +14394,16 @@ Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc,
ArrayRef<Expr *> ArgsArray(Args, NumArgs);
if (Input->isTypeDependent()) {
+ ExprValueKind VK = ExprValueKind::VK_PRValue;
+ // [C++26][expr.unary.op][expr.pre.incr]
+ // The * operator yields an lvalue of type
+ // The pre/post increment operators yied an lvalue.
+ if (Opc == UO_PreDec || Opc == UO_PreInc || Opc == UO_Deref)
+ VK = VK_LValue;
+
if (Fns.empty())
- return UnaryOperator::Create(Context, Input, Opc, Context.DependentTy,
- VK_PRValue, OK_Ordinary, OpLoc, false,
+ return UnaryOperator::Create(Context, Input, Opc, Context.DependentTy, VK,
+ OK_Ordinary, OpLoc, false,
CurFPFeatureOverrides());
CXXRecordDecl *NamingClass = nullptr; // lookup ignores member operators
@@ -14405,7 +14412,7 @@ Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc,
if (Fn.isInvalid())
return ExprError();
return CXXOperatorCallExpr::Create(Context, Op, Fn.get(), ArgsArray,
- Context.DependentTy, VK_PRValue, OpLoc,
+ Context.DependentTy, VK, OpLoc,
CurFPFeatureOverrides());
}
diff --git a/clang/test/CXX/over/over.built/ast.cpp b/clang/test/CXX/over/over.built/ast.cpp
index f76606b1f9869a..56a63431269f30 100644
--- a/clang/test/CXX/over/over.built/ast.cpp
+++ b/clang/test/CXX/over/over.built/ast.cpp
@@ -4,11 +4,11 @@ struct A{};
template <typename T, typename U>
auto Test(T* pt, U* pu) {
- // CHECK: UnaryOperator {{.*}} '<dependent type>' prefix '*'
+ // CHECK: UnaryOperator {{.*}} '<dependent type>' lvalue prefix '*'
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *'
(void)*pt;
- // CHECK: UnaryOperator {{.*}} '<dependent type>' prefix '++'
+ // CHECK: UnaryOperator {{.*}} '<dependent type>' lvalue prefix '++'
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *'
(void)(++pt);
diff --git a/clang/test/SemaCXX/overloaded-operator.cpp b/clang/test/SemaCXX/overloaded-operator.cpp
index 49311625d7ab2d..cab21d67a002fe 100644
--- a/clang/test/SemaCXX/overloaded-operator.cpp
+++ b/clang/test/SemaCXX/overloaded-operator.cpp
@@ -682,3 +682,13 @@ namespace nw{
}
}
#endif
+
+#if __cplusplus >= 201703L
+namespace GH88329 {
+
+template <auto T> struct A {};
+template <auto T> A<*T> operator *() { return {}; }
+// expected-error@-1 {{overloaded 'operator*' must have at least one parameter of class or enumeration type}}
+}
+
+#endif
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, good catch!
…lvm#88740) This fixes an assertion in Expr::Classify when a trying to deduce a dependent dereference operator. Fixes llvm#88329
Ping @cor3ntin ^ |
I have limited availability this week, I'll look at that when I can, thanks! |
Fix a regression introduced by llvm#88740 Fixes llvm#92275
This fixes an assertion in Expr::Classify when a
trying to deduce a dependent dereference operator.
Fixes #88329