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

Craig Topper via cfe-dev cfe-dev at lists.llvm.org
Thu Jan 20 23:16:16 PST 2022


I'm not sure that is undefined behavior, but it is caught by
-fsanitize=integer

~Craig


On Thu, Jan 20, 2022 at 11:06 PM phy coder via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> 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 .
>>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20220120/729a3b6b/attachment-0001.html>


More information about the cfe-dev mailing list