[LLVMbugs] [Bug 18296] New: Illegal code generated on end of bool function with missing return

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Dec 20 15:41:47 PST 2013


http://llvm.org/bugs/show_bug.cgi?id=18296

            Bug ID: 18296
           Summary: Illegal code generated on end of bool function with
                    missing return
           Product: clang
           Version: 3.3
          Hardware: PC
                OS: FreeBSD
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: amdmi3 at amdmi3.ru
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

clang++ generates illegal code for function returning bool which lacks return
statement.

I know this case is undefined behavior and what compiler does is essentially
legal, but still it would be nice to do something more productive instead of
generating crashing code, like at least emitting an error instead of a warning.

$ cat > test.cc
bool func() {}
int main() {
  func();
  return 0;
}
$ clang++ test.cc -o test
test.cc:1:14: warning: control reaches end of non-void function [-Wreturn-type]
bool func() {}
             ^
1 warning generated.
$ ./test
Illegal instruction

Assembly:

_Z4funcv:                               # @_Z4funcv
    .cfi_startproc
# BB#0:
    pushq    %rbp
.Ltmp2:
    .cfi_def_cfa_offset 16
.Ltmp3:
    .cfi_offset %rbp, -16
    movq    %rsp, %rbp
.Ltmp4:
    .cfi_def_cfa_register %rbp
    ud2                                    ; <--
.Ltmp5:
    .size    _Z4funcv, .Ltmp5-_Z4funcv
    .cfi_endproc

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20131220/a1608295/attachment.html>


More information about the llvm-bugs mailing list