https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77722

            Bug ID: 77722
           Summary: -fsanitize=undefined doesn't give runtime error in
                    function without return value, unless at least 2
                    instructions
           Product: gcc
           Version: 6.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jamespharvey20 at gmail dot com
  Target Milestone: ---

[test.cpp]
----------
int func() {
}
int main() {
   func();
}
----------

$ g++ test.cpp -fsanitize=undefined -O0
$ ./a.out
(No runtime error)

----------
int func() {
   int a = 5;
}
----------

$ ./a.out
(No runtime error)

----------
int func() {
   int a = 5;
   int b = 5;
}
----------

$ ./a.out
test.cpp:1:5: runtime error: execution reached the end of a value-returning
function without returning a value

I'm not sure what (if any) relation there is in the gcc to clang fsanitize
code.  But, clang 3.8.1's fsanitize=undefined gives a runtime error on all 3
above versions of func().

As a note, -Wreturn-type does issue a warning even for an empty version of
func(), so it does catch the situation, but fsanitize=undefined does not.

Reply via email to