<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Mar 2, 2021, at 20:10, Saurabh Jha via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class="">Hi LLVM people,<div class=""><br class=""></div></div></div></div></div></div></div></div></div></div></div></div></blockquote><div><br class=""></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 class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class="">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" class="">details</a>.</div><div class=""><br class=""></div></div></div></div></div></div></div></div></div></div></div></div></blockquote><div><br class=""></div>Thank you very much for taking a look at the issue!</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class="">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" class="">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" class="">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" class="">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" class=""><br class=""></div># printing out S<br class="">(lldb) p S<br class="">(std::__add_pointer_helper<clang::Stmt, true>::type) $0 = 0x0000000011621f70<br class=""><br class=""></div><div class=""># cast S to CompoundAssignOperator</div><div dir="ltr" class="">(lldb) p ((CompoundAssignOperator *) S)<br class="">(clang::CompoundAssignOperator *) $1 = 0x0000000011621f70<br class=""><br class=""></div><div class=""># access ComputationLHSType attribute of casted S. The QualType is NULL.</div><div dir="ltr" class="">(lldb) p ((CompoundAssignOperator *) S)->ComputationLHSType<br class="">(clang::QualType) $2 = {<br class=""> Value = (Value = 0)<br class="">}<br class=""><br class=""></div><div class=""># access ComputationResultType attribute of casted S.</div><div dir="ltr" class="">(lldb) p ((CompoundAssignOperator *) S)->ComputationResultType<br class="">(clang::QualType) $3 = {<br class=""> Value = (Value = 291641504)<br class="">}<br class=""><br class="">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 class=""></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" class="">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 class=""></div><div>Cheers,</div><div>Florian</div><br class=""></div></body></html>