[cfe-dev] Strange dimension errors in a custom matrix class

Tony Kelman kelman at berkeley.edu
Sun Feb 9 05:00:23 PST 2014


> This behavior is intended. Your program exhibits undefined behavior
> (control falls off the end of a non-void returning function rather than
> exiting via a return statement with an appropriate object).
>
> Clang provides no guarantees for this code above -O0 (no code is emitted,
> execution may fall into the following function, etc - nasal demons, etc),
> but does generously provide an illegal instruction at -O0 so you can find
> this bug a bit more easily. The warning is also there to help.
>
> In short: make sure you return things from your non-void returning
> functions. Don't let them fall off the end.

Thank you very much for the insight. Interestingly this extremely-reduced
case succeeds on OS X with Apple clang-500.2.79. Since I didn’t get the
"control reaches end of non-void function" warning in the real program,
I suspect this is a case of over-aggressive reduction by creduce. Next
time I'll tell creduce not to accept code that the compiler warns about.

Thanks to Tomasz Miąsko I was able to solve the original problem. The
DMatrix::operator& was taking argument by value and creating unsafe
temporaries. Replacing uses of that operator with the by-reference
elemProduct avoided the dimension errors I was getting.

-Tony




More information about the cfe-dev mailing list