[LLVMbugs] [Bug 21330] New: clang-cl miscompiles insertion of struct value into std::map

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Oct 21 15:28:14 PDT 2014


            Bug ID: 21330
           Summary: clang-cl miscompiles insertion of struct value into
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: hans at chromium.org
                CC: david.majnemer at gmail.com, llvmbugs at cs.uiuc.edu,
                    rnk at google.com
    Classification: Unclassified

Example derived from a Chromium unit test:

#include <map>
#include <stdio.h>
#include <string>

struct CrashKey {
  const char *name;
  size_t val;

std::map<std::string, CrashKey> map;

int main() {
  const CrashKey keys[] = { { "foo", 42 }, { "bar", 7 } };

  for (int i = 0; i < sizeof keys / sizeof keys[0] ; ++i)
    map.insert(std::make_pair(keys[i].name, keys[i]));

  for (auto i : map)
    printf("key: %s, %d\n", i.second.name, i.second.val);

  return 0;

Compiled with clang-cl /Ox, this prints
key: bar, 0
key: foo, 0

Compiled without optimization, or with MSVC, it prints:
key: bar, 7
key: foo, 42

I think this regressed sometime last night.

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/20141021/44f4c7f8/attachment.html>

More information about the llvm-bugs mailing list