<div dir="ltr">Hi Florian,<div><br></div><div>Thank you for the suggestions. I am able to get += and -= work for matrices and should be able to create a patch for review soon, after I am done writing lit tests.<div><br></div><div>Cheers,</div><div>Saurabh</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Mar 3, 2021 at 10:30 AM Florian Hahn <<a href="mailto:florian_hahn@apple.com">florian_hahn@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">Hi,<div><br></div><div><div><br><blockquote type="cite"><div>On Mar 2, 2021, at 20:10, Saurabh Jha via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:</div><br><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi LLVM people,<div><br></div></div></div></div></div></div></div></div></div></div></div></div></blockquote><div><br></div>Llvm-dev is usually used to discuss issues related to llvm itself. As this email is related to Clang internals, cfe-dev would be more suitable (added as CC).</div><div><br><blockquote type="cite"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>I am new to clang/llvm and have been hacking on it for about three weeks now.  I am trying to implement compound assignment operators, +=, -=, and *=, for matrices. Here are the bug <a href="https://bugs.llvm.org/show_bug.cgi?id=46164" target="_blank">details</a>.</div><div><br></div></div></div></div></div></div></div></div></div></div></div></div></blockquote><div><br></div>Thank you very much for taking a look at the issue!</div><div><br><blockquote type="cite"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>I have a lit test that tries to do a "a += b" for matrices a and b. Here's its <a href="https://godbolt.org/z/eM7x1q" target="_blank">trace</a>  (courtesy Florian Hahn). Clang fails on this <a href="https://github.com/llvm/llvm-project/blob/ca5247bb1770a1dfa56b78303d99f1cc9a0a06ee/clang/include/clang/AST/Type.h#L677" target="_blank">assertion</a>. And this is because when we do a static cast from a Stmt instance to a CompoundAssignOperator <a href="https://github.com/llvm/llvm-project/blob/ca5247bb1770a1dfa56b78303d99f1cc9a0a06ee/clang/include/clang/AST/StmtVisitor.h#L76" target="_blank">here</a>, we are not assigning the correct QualType to the LHS. Concretely, here's what I found in my debugging.</div><div dir="ltr"><br></div># printing out S<br>(lldb) p S<br>(std::__add_pointer_helper<clang::Stmt, true>::type) $0 = 0x0000000011621f70<br><br></div><div># cast S to CompoundAssignOperator</div><div dir="ltr">(lldb) p ((CompoundAssignOperator *) S)<br>(clang::CompoundAssignOperator *) $1 = 0x0000000011621f70<br><br></div><div># access ComputationLHSType attribute of casted S. The QualType is NULL.</div><div dir="ltr">(lldb) p ((CompoundAssignOperator *) S)->ComputationLHSType<br>(clang::QualType) $2 = {<br>  Value = (Value = 0)<br>}<br><br></div><div># access ComputationResultType attribute of casted S.</div><div dir="ltr">(lldb) p ((CompoundAssignOperator *) S)->ComputationResultType<br>(clang::QualType) $3 = {<br>  Value = (Value = 291641504)<br>}<br><br>So I think it's working correctly for ComputationResultType but is somehow assigning null to ComputationLHSType's QualType.Value. This is interesting because if I try to cast S to something like BinaryOperator and cast its operands to Expr, the types are coming out correctly.</div></div></div></div></div></div></div></div></div></div></div></blockquote><br></div><div>You are correct I think, the key issue is that we assign the wrong type to LHS (null instead of the matrix type of the binop result). The problem is that we do not properly set CompLHSTy for matrix expressions (see <a href="https://github.com/llvm/llvm-project/blob/ca5247bb1770a1dfa56b78303d99f1cc9a0a06ee/clang/lib/Sema/SemaExpr.cpp#L10518" target="_blank">https://github.com/llvm/llvm-project/blob/ca5247bb1770a1dfa56b78303d99f1cc9a0a06ee/clang/lib/Sema/SemaExpr.cpp#L10518</a> and compare to what’s done for vector types above). I think if that is fixed, things should work out as expected.</div><div><br></div><div>Cheers,</div><div>Florian</div><br></div></div></blockquote></div>