)]}'
{
  "commit": "6e09d4a6e6e62e585fe1237a0094f80f8aeef2fa",
  "tree": "02ac80c35cb96b1acad21353df5d1b33aa114bbe",
  "parents": [
    "9f0fb75b8e121a93b0f63dd823fa86ffd44e8e5d"
  ],
  "author": {
    "name": "Nick Alcock",
    "email": "nick.alcock@oracle.com",
    "time": "Tue Jun 11 20:33:03 2024 +0100"
  },
  "committer": {
    "name": "Nick Alcock",
    "email": "nick.alcock@oracle.com",
    "time": "Tue Jun 18 13:20:32 2024 +0100"
  },
  "message": "libctf: prohibit addition of enums with overlapping enumerator constants\n\nlibctf has long prohibited addition of enums with overlapping constants in a\nsingle enum, but now that we are properly considering enums with overlapping\nconstants to be conflciting types, we can go further and prohibit addition\nof enumeration constants to a dict if they already exist in any enum in that\ndict: the same rules as C itself.\n\nWe do this in a fashion vaguely similar to what we just did in the\ndeduplicator, by considering enumeration constants as identifiers and adding\nthem to the core type/identifier namespace, ctf_dict_t.ctf_names.  This is a\nlittle fiddly, because we do not want to prohibit opening of existing dicts\ninto which the deduplicator has stuffed enums with overlapping constants!\nWe just want to prohibit the addition of *new* enumerators that violate that\nrule.  Even then, it\u0027s fine to add overlapping enumerator constants as long\nas at least one of them is in a non-root type.  (This is essential for\nproper deduplicator operation in cu-mapped mode, where multiple compilation\nunits can be smashed into one dict, with conflicting types marked as\nhidden: these types may well contain overlapping enumerators.)\n\nSo, at open time, keep track of all enums observed, then do a third pass\nthrough the enums alone, adding each enumerator either to the ctf_names\ntable as a mapping from the enumerator name to the enum it is part of (if\nnot already present), or to a new ctf_conflicting_enums hashtable that\ntracks observed duplicates. (The latter is not used yet, but will be soon.)\n\n(We need to do a third pass because it\u0027s quite possible to have an enum\ncontaining an enumerator FOO followed by a type FOO: since they\u0027re processed\nin order, the enumerator would be processed before the type, and at that\nstage it seems nonconflicting.  The easiest fix is to run through the\nenumerators after all type names are interned.)\n\nAt ctf_add_enumerator time, if the enumerator to which we are adding a type\nis root-visible, check for an already-present name and error out if found,\nthen intern the new name in the ctf_names table as is done at open time.\n\n(We retain the existing code which scans the enum itself for duplicates\nbecause it is still an error to add an enumerator twice to a\nnon-root-visible enum type; but we only need to do this if the enum is\nnon-root-visible, so the cost of enum addition is reduced.)\n\nTested in an upcoming commit.\n\nlibctf/\n\t* ctf-impl.h (ctf_dict_t) \u003cctf_names\u003e: Augment comment.\n        \u003cctf_conflicting_enums\u003e: New.\n\t(ctf_dynset_elements): New.\n\t* ctf-hash.c (ctf_dynset_elements): Implement it.\n\t* ctf-open.c (init_static_types): Split body into...\n        (init_static_types_internal): ... here.  Count enumerators;\n        keep track of observed enums in pass 2; populate ctf_names and\n        ctf_conflicting_enums with enumerators in a third pass.\n\t(ctf_dict_close): Free ctf_conflicting_enums.\n\t* ctf-create.c (ctf_add_enumerator): Prohibit addition of duplicate\n        enumerators in root-visible enum types.\n\ninclude/\n\t* ctf-api.h (CTF_ADD_NONROOT): Describe what non-rootness\n        means for enumeration constants.\n\t(ctf_add_enumerator):  The name is not a misnomer.\n        We now require that enumerators have unique names.\n        Document the non-rootness of enumerators.\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "85734afcac284c2f5e3aa5e91aa76d7db9b380f4",
      "old_mode": 33188,
      "old_path": "include/ctf-api.h",
      "new_id": "d7bdbdd0dacfc883b8a83f89210f36fe0b707902",
      "new_mode": 33188,
      "new_path": "include/ctf-api.h"
    },
    {
      "type": "modify",
      "old_id": "073006b24ea9c8e28f2e31827fd504dd25dbb8e8",
      "old_mode": 33188,
      "old_path": "libctf/ctf-create.c",
      "new_id": "d67460309185ceaaffb9bd0d610a81dca2c26ef7",
      "new_mode": 33188,
      "new_path": "libctf/ctf-create.c"
    },
    {
      "type": "modify",
      "old_id": "77b8478479e79877e9ffb6d05e237c928b4ae279",
      "old_mode": 33188,
      "old_path": "libctf/ctf-hash.c",
      "new_id": "a52f96db105aa27557f8e28b6dedfe2127acaaee",
      "new_mode": 33188,
      "new_path": "libctf/ctf-hash.c"
    },
    {
      "type": "modify",
      "old_id": "eb89f8b46450b920211fbde663ff8d3272c24ee0",
      "old_mode": 33188,
      "old_path": "libctf/ctf-impl.h",
      "new_id": "ec0b4feb328a01011089d4bea626b141bb1c989b",
      "new_mode": 33188,
      "new_path": "libctf/ctf-impl.h"
    },
    {
      "type": "modify",
      "old_id": "59c6ed0622a5ddac0230f1a65a25cebe5707468b",
      "old_mode": 33188,
      "old_path": "libctf/ctf-open.c",
      "new_id": "2ae0a696c3ab50f47f06530a1ad88067ee17bc47",
      "new_mode": 33188,
      "new_path": "libctf/ctf-open.c"
    }
  ]
}
