This patch fixes a crash that happens because of an assertion failure in C mode only. The assertion failure happens because of a cast to a C++ record decl in code that assumes (correctly, AFAIK) that overloaded operator handling is used in C++ mode only.

This patch approaches this problem in the following manner: when clang isn't in C++ mode, it exits early from the method 'Sema::CreateOverloadedBinOp'. The operator handling is performed using the 'Sema::CreateBuiltinBinOp' method when exiting the previously mentioned method. I think that this approach works because, AFAIK, clang doesn't support operator overloading without LangOpts.CPlusPlus, so it doesn't need to handle the overloading in the same way, and redirecting to builtin operator handling deals with the C operators correctly. I also tried other approaches and strategies but they didn't seem to work as well as this one.

I'm not familiar with all the intricacies of Sema, and I realize that this might be the wrong approach for this problem. Please let me know if this a sound strategy or not.

It looks like the bug is in Sema::BuildBinOp -- in C, it should call CorrectDelayedTyposInExpr before doing almost anything else. The relevant code is currently in CreateBuiltinBinOp, which is too late. Moving that code to the start of BuildBinOp should solve the problem.

I updated the patch with a approach that you suggested - now Sema::CreateOverloadedBinOp isn't called in C mode (I have an assertion for this in Sema::CreateOverloadedBinOp, but I'll commit it separately after).

I also tried moving the CorrectDelayedTyposInExpr code from Sema::CreateBuiltinBinOp to Sema::BuildBinOp as you suggested, but it didn't seem to have any effect whatsoever - it didn't seem to change the behavior of anything with respect to this bug or llvm's test suite. Therefore, I decided to leave it in its original location in this diff. Perhaps I've misunderstood your suggestion?