[llvm-bugs] [Bug 51021] New: Wrong code with throwing const function

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jul 8 04:29:34 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51021

            Bug ID: 51021
           Summary: Wrong code with throwing const function
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Keywords: miscompilation
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: harald at gigawatt.nl
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

The GCC developers have clarified that the function attributes const and pure
do not imply that the functions do not throw. clang does assume that and as
such miscompiles the following program:

  __attribute__((const)) void f() {
    throw 0;
  }

  int main() {
    try {
      f();
    } catch(int i) {
      return 0;
    }

    return 1;
  }

This program should return 0, not 1.

Godbolt link: https://godbolt.org/z/jj1PG7o78

(Please ignore the warning emitted by GCC, 'const' attribute on function
returning 'void'; I have reported that as part of
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101376.)

-- 
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/20210708/c2efec35/attachment.html>


More information about the llvm-bugs mailing list