[cfe-dev] Function return not catching the undefined behavior

phy coder via cfe-dev cfe-dev at lists.llvm.org
Thu Jan 20 23:06:35 PST 2022


And if I'm wrong or misunderstand something then please let me know.

On Fri, Jan 21, 2022, 12:00 phy coder <coderphy3 at gmail.com> wrote:

> I'm not sure if this is undefined behavior or not and it may be discussed
> before or not. I was testing some random code snippets to try
> "-fsanitize=undefined" but in this example:
>
> #include<iostream>
>
> char func(int a, int b) {
> int sum = a+b;
> return sum ;
> }
>
> int main() {
> int n;
> char s = func(100,100);
> int t = func(100,100);
> std::cout << "hello" << s << t;
> return 0;
>
> }
>
> I was expecting some kind of undefined behavior here because of some
> overflowing the char return type with integer return type. But
> "-fsanitize=undefined" is not able to catch this . And I got the output
> this : hello�-56
> Kinda weird for me .
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20220121/a91efb31/attachment.html>


More information about the cfe-dev mailing list