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

phy coder via cfe-dev cfe-dev at lists.llvm.org
Thu Jan 20 22:30:41 PST 2022


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/063025e8/attachment.html>


More information about the cfe-dev mailing list