)]}'
{
  "commit": "9c049f4eb807b46397e6f33b0a7fd8a06b5e2e54",
  "tree": "ba0fa1f6394d9ae7a53d63ba9e94a30c26467da9",
  "parents": [
    "f4d19f74bcd0ca496de729b46dd2d8a80fda1d29"
  ],
  "author": {
    "name": "Jakub Jelinek",
    "email": "jakub@redhat.com",
    "time": "Wed Dec 03 16:07:29 2025 +0100"
  },
  "committer": {
    "name": "Jakub Jelinek",
    "email": "jakub@gcc.gnu.org",
    "time": "Mon Dec 08 08:07:49 2025 +0100"
  },
  "message": "switchconv: Fix up inbound checks for switch types wider than sizetype [PR122943]\n\nIn r14-8302 I\u0027ve changed switchconv to narrow the CONSTRUCTOR indexes and\nthe runtime SSA_NAME indexing into the arrays to at most sizetype for\ntypes wider than that (__int128, large _BitInt, for -m32 long long too).\nThe switchconv partitioning ensures that one partition isn\u0027t larger than\nthat and having CONSTRUCTOR with _BitInt(1024) indexes was causing all kinds\nof problems.\n\nUnfortunately, as the following testcase shows, while doing that is\ndesirable, the later gen_inbound_check call uses the lhs of m_arr_ref_first\nstatement to determine the type and value that should be compared for the\ninbound check (against the highest possible bound cast to the lhs type).\nSo the PR113491 r14-8302 change broke those inbound checks, instead of\nbeing done in unsigned type corresponding to the precision of the switch\nexpression they are now sometimes done using sizetype.  That is of course\nwrong.\n\nSo the following patch fixes it by doing the tidx computation in steps,\none is the utype subtraction, which has m_arr_ref_first as the last\ninstruction, and then if needed there is a cast to sizetype if utype is\nwider than that.  When gen_inbound_check is called, it adds the inbound\ncheck after the m_arr_ref_first instruction and the additional cast is\nthen inside of the guarded block.\n\nSo e.g. in bar for -m32 this patch changes:\n unsigned char bar (long long int val)\n {\n   unsigned char result;\n-  sizetype _7;\n+  sizetype _6;\n+  long long unsigned int _7;\n\n   \u003cbb 2\u003e :\n-  _7 \u003d (sizetype) val_3(D);\n+  _7 \u003d (long long unsigned int) val_3(D);\n   if (_7 \u003c\u003d 2)\n     goto \u003cbb 4\u003e; [INV]\n   else\n     goto \u003cbb 3\u003e; [INV]\n\n   \u003cbb 3\u003e :\n \u003cL7\u003e:\n-  result_5 \u003d 1;\n+  result_4 \u003d 1;\n   goto \u003cbb 5\u003e; [100.00%]\n\n   \u003cbb 4\u003e :\n \u003cL8\u003e:\n-  result_6 \u003d CSWTCH.2[_7];\n+  _6 \u003d (sizetype) _7;\n+  result_5 \u003d CSWTCH.2[_6];\n\n   \u003cbb 5\u003e :\n-  # result_1 \u003d PHI \u003cresult_6(4), result_5(3)\u003e\n+  # result_1 \u003d PHI \u003cresult_5(4), result_4(3)\u003e\n \u003cL9\u003e:\n \u003cL6\u003e:\n   return result_1;\n\n }\n\n2025-12-03  Jakub Jelinek  \u003cjakub@redhat.com\u003e\n\n\tPR tree-optimization/122943\n\t* tree-switch-conversion.cc (switch_conversion::build_arrays):\n\tAlways gimplify subtraction in utype without cast to tidxtype\n\tand set m_arr_ref_first to the last stmt of that.  Remove unneeded\n\tupdate_stmt call.  If tidxtype is not utype, append after that stmt\n\tcast to tidxtype and set tidx to the lhs of that cast.\n\n\t* gcc.c-torture/execute/pr122943.c: New test.\n\n(cherry picked from commit 45f3501bdaa4544293e2c391506819c8cff5fcca)\n",
  "tree_diff": [
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "a41777cb42237a5e5287fcd59d4d6413b76978ee",
      "new_mode": 33188,
      "new_path": "gcc/testsuite/gcc.c-torture/execute/pr122943.c"
    },
    {
      "type": "modify",
      "old_id": "39a8a893eddeeb70a4f5a8ed7869874c46f77360",
      "old_mode": 33188,
      "old_path": "gcc/tree-switch-conversion.cc",
      "new_id": "28046f332efe1b858ccac1d86fca96224717b0d3",
      "new_mode": 33188,
      "new_path": "gcc/tree-switch-conversion.cc"
    }
  ]
}
