[cfe-dev] Function return not catching the undefined behavior
Jessica Clarke via cfe-dev
cfe-dev at lists.llvm.org
Fri Jan 21 07:06:35 PST 2022
This is implementation-defined, not undefined. C99 6.3.1.3p3:
Otherwise, the new type is signed and the value cannot be represented in it; either the result is implementation-defined or an implementation-defined signal is raised.
Jess
> On 21 Jan 2022, at 07:16, Craig Topper via cfe-dev <cfe-dev at lists.llvm.org> wrote:
>
> 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 <mailto: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 <mailto: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 <mailto:cfe-dev at lists.llvm.org>
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev <https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev>
> _______________________________________________
> 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/20220121/25c37e7d/attachment.html>
More information about the cfe-dev
mailing list