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

            Bug ID: 43546
           Summary: Computed goto generates badrefs: block addresses,
                    constexpr, and lambdas.
           Product: clang
           Version: 9.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangb...@nondot.org
          Reporter: felipe.de.azevedo.piove...@intel.com
                CC: blitzrak...@gmail.com, dgre...@apple.com,
                    erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
                    richard-l...@metafoo.co.uk

The code below miscompiles on Clang 9 & trunk, but not on previous versions:
(Godbolt link for convenience: https://godbolt.org/z/8LG1v3)

We generate global variables with <badrefs> and, as such, the optimizer
completely eliminates the function.

  @labels = private unnamed_addr constant [3 x i8*] [i8*
blockaddress(@"label1", <badref>), i8* blockaddress(@"label2", <badref>), i8*
blockaddress(@"label3", <badref>)], align 16

Note the badrefs! Also, we generate a basic block with no predecessors:

  12: ; No predecessors!
  indirectbr i8* undef, [label <badref>, label <badref>, label <badref>]




```
  enum bytecode : int8_t
  {
    add1,
    add2,
    halt,
  };

  auto run_with_computed_goto(bytecode const* instructions)
  {
    auto value = 0.0;

    constexpr void* labels[] = {
      [bytecode::add1] = &&add1_label,
      [bytecode::add2] = &&add2_label,
      [bytecode::halt] = &&halt_label,
    };

    auto const next = [&] { return labels[*instructions++]; };
    goto* next();

  add1_label:
    value += 1.0;
    goto* next();
  add2_label:
    value += 2.0;
    goto* next();
  halt_label:
    return value;
  }
```

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to