================
@@ -615,7 +634,7 @@ BuiltinTypeMethodBuilder 
&BuiltinTypeMethodBuilder::dereference(T Ptr) {
   Expr *Deref =
       UnaryOperator::Create(DeclBuilder.SemaRef.getASTContext(), PtrExpr,
                             UO_Deref, PtrExpr->getType()->getPointeeType(),
-                            VK_PRValue, OK_Ordinary, SourceLocation(),
+                            VK_LValue, OK_Ordinary, SourceLocation(),
----------------
kmpeng wrote:

It actually seems like this was implemented incorrectly before and should have 
always been lvalue. This is the rationale Justin gave:

> Consider https://godbolt.org/z/cbz3fcfY1 and https://godbolt.org/z/jPKK85hxq 
> - the dereference (ie `UnaryOperator '*'`) is an LValue in every instance. 
> Also consider [the cpp 
> reference](https://en.cppreference.com/w/cpp/language/value_category.html), 
> which includes in the list/examples of lvalue categories `*p`, like so: 
`*p, the built-in indirection expression;`
This makes sense, because the result of dereferencing a pointer is a valid 
thing to assign something to (the "Left" side of an assignment expression).

As to why I actually had to change it, the `UnaryOperator` being an rvalue was 
making it go through the wrong function in `ExprConstant.cpp` 
(`VectorExprEvaluator::VisitUnaryOperator` instead of 
`LValueExprEvaluator::VisitUnaryDeref`) and it was hitting an invalid cast

https://github.com/llvm/llvm-project/pull/176058
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to