)]}'
{
  "commit": "40fc3ea0c8a0e912f603b448416bd4768cadd390",
  "tree": "3e706936e8ad730e50596f1d9b74a2e8e472425c",
  "parents": [
    "862f51587e0c4c8977f7635e9a65a0f1d6ffdcb8"
  ],
  "author": {
    "name": "Dan Liew",
    "email": "dan@su-root.co.uk",
    "time": "Wed Aug 27 21:07:15 2025 +0100"
  },
  "committer": {
    "name": "Copybara-Service",
    "email": "copybara-worker@google.com",
    "time": "Wed Aug 27 13:11:19 2025 -0700"
  },
  "message": "[UBSan][BoundsSafety] Implement support for more expressive \"trap reasons\" (#154618)\n\nIn 29992cfd628ed5b968ccb73b17ed0521382ba317 (#145967) support was added\nfor \"trap reasons\" on traps emitted in UBSan in trapping mode (e.g.\n`-fsanitize-trap\u003dundefined`). This improved the debugging experience by\nattaching the reason for trapping as a string on the debug info on trap\ninstructions. Consumers such as LLDB can display this trap reason string\nwhen the trap is reached.\n\nA limitation of that patch is that the trap reason string is hard-coded\nfor each `SanitizerKind` even though the compiler actually has much more\ninformation about the trap available at compile time that could be shown\nto the user.\n\nThis patch is an incremental step in fixing that. It consists of two\nmain steps.\n\n**1. Introduce infrastructure for building trap reason strings**\n\nTo make it convenient to construct trap reason strings this patch\nre-uses Clang\u0027s powerful diagnostic infrastructure to provide a\nconvenient API for constructing trap reason strings. This is achieved\nby:\n\n* Introducing a new `Trap` diagnostic kind to represent trap diagnostics\nin TableGen files.\n* Adding a new `Trap` diagnostic component. While this part probably\nisn\u0027t technically necessary it seemed like I should follow the existing\nconvention used by the diagnostic system.\n* Adding `DiagnosticTrapKinds.td` to describe the different trap\nreasons.\n* Add the `TrapReasonBuilder` and `TrapReason` classes to provide an\ninterface for constructing trap reason strings and the trap category.\nNote this API while similar to `DiagnosticBuilder` has different\nsemantics which are described in the code comments. In particular the\nbehavior when the destructor is called is very different.\n* Adding `CodeGenModule::BuildTrapReason()` as a convenient constructor\nfor the `TrapReasonBuilder`.\n\nThis use of the diagnostic system is a little unusual in that the\nemitted trap diagnostics aren\u0027t actually consumed by normal diagnostic\nconsumers (e.g. the console). Instead the `TrapReasonBuilder` is just\nused to format a string, so in effect the builder is somewhat analagous\nto \"printf\". However, re-using the diagnostics system in this way brings\na several benefits:\n\n* The powerful diagnostic templating languge (e.g. `%select`) can be\nused.\n* Formatting Clang data types (e.g. `Type`, `Expr`, etc.) just work\nout-of-the-box.\n* Describing trap reasons in tablegen files opens the door for\ntranslation to different languages in the future.\n* The `TrapReasonBuilder` API is very similar to `DiagnosticBuilder`\nwhich makes it easy to use by anyone already familiar with Clang\u0027s\ndiagnostic system.\n\nWhile UBSan is the first consumer of this new infrastructure the intent\nis to use this to overhaul how trap reasons are implemented in the\n`-fbounds-safety` implementation (currently exists downstream).\n\n**2. Apply the new infrastructure to UBSan checks for arithmetic\noverflow**\n\nTo demonstrate using `TrapReasonBuilder` this patch applies it to UBSan\ntraps for arithmetic overflow. The intention is that we would\niteratively switch to using the `TrapReasonBuilder` for all UBSan traps\nwhere it makes sense in future patches.\n\nPreviously for code like\n\n```\nint test(int a, int b) { return a + b; }\n```\n\nThe trap reason string looked like\n\n```\nUndefined Behavior Sanitizer: Integer addition overflowed\n```\n\nnow the trap message looks like:\n\n```\nUndefined Behavior Sanitizer: signed integer addition overflow in \u0027a + b\u0027\n```\n\nThis string is much more specific because\n\n* It explains if signed or unsigned overflow occurred\n* It actually shows the expression that overflowed\n\nOne possible downside of this approach is it may blow up Debug info size\nbecause now there can be many more distinct trap reason strings. To\nallow users to avoid this a new driver/cc1 flag\n`-fsanitize-debug-trap-reasons\u003d` has been added which can either be\n`none` (disable trap reasons entirely), `basic` (use the per\n`SanitizerKind` hard coded strings), and `detailed` (use the new\nexpressive trap reasons implemented in this patch). The default is\n`detailed` to give the best out-of-the-box debugging experience. The\nexisting `-fsanitize-debug-trap-reasons` and\n`-fno-sanitize-debug-trap-reasons` have been kept for compatibility and\nare aliases of the new flag with `detailed` and `none` arguments passed\nrespectively.\n\nrdar://158612755\n\nGitOrigin-RevId: f1ee0473209e31b0d05f589e9091ffbbcc60be31\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "3ad9e566a5d93cb0f16bd2dff69f3ec2d8252300",
      "old_mode": 33188,
      "old_path": "docs/ReleaseNotes.rst",
      "new_id": "84e499e5d0ab9fd16882099e0220e09d2157bae5",
      "new_mode": 33188,
      "new_path": "docs/ReleaseNotes.rst"
    },
    {
      "type": "modify",
      "old_id": "a946b4a640ac61b6a4bdd157b9ae3cc28c61c131",
      "old_mode": 33188,
      "old_path": "include/clang/Basic/AllDiagnosticKinds.inc",
      "new_id": "2d08bb05259703ad45eabf30a27ca650e46577c9",
      "new_mode": 33188,
      "new_path": "include/clang/Basic/AllDiagnosticKinds.inc"
    },
    {
      "type": "modify",
      "old_id": "3b782732c1507fa7011e3a0f9a2c7cea11b182c9",
      "old_mode": 33188,
      "old_path": "include/clang/Basic/AllDiagnostics.h",
      "new_id": "78e5428ddbfff558c2583229ac4b462f3406164b",
      "new_mode": 33188,
      "new_path": "include/clang/Basic/AllDiagnostics.h"
    },
    {
      "type": "modify",
      "old_id": "0cf661a57dfa8cc42346571646ede61b1221270e",
      "old_mode": 33188,
      "old_path": "include/clang/Basic/CMakeLists.txt",
      "new_id": "81736006a21a0f86c25dcb1320171f29cf1c88fd",
      "new_mode": 33188,
      "new_path": "include/clang/Basic/CMakeLists.txt"
    },
    {
      "type": "modify",
      "old_id": "b96ec750680046a409052e2061a2fe2c12ad958d",
      "old_mode": 33188,
      "old_path": "include/clang/Basic/CodeGenOptions.def",
      "new_id": "fda0da99b60c0715dfcd8db9e633b9c6841405cc",
      "new_mode": 33188,
      "new_path": "include/clang/Basic/CodeGenOptions.def"
    },
    {
      "type": "modify",
      "old_id": "cdeedd5b4eac6e40c8fbaddf8771ae7e120ab59e",
      "old_mode": 33188,
      "old_path": "include/clang/Basic/CodeGenOptions.h",
      "new_id": "5d5cf250b56b9e70b89e4e5d6c898db37d5834d7",
      "new_mode": 33188,
      "new_path": "include/clang/Basic/CodeGenOptions.h"
    },
    {
      "type": "modify",
      "old_id": "cee5bed665d0a0ba5e315c08fb74601d8395615b",
      "old_mode": 33188,
      "old_path": "include/clang/Basic/Diagnostic.h",
      "new_id": "af26a04d94889daa95414ca986e7d22486cb9139",
      "new_mode": 33188,
      "new_path": "include/clang/Basic/Diagnostic.h"
    },
    {
      "type": "modify",
      "old_id": "65b19f3feea4fab824b02710ce2f30fb038b6483",
      "old_mode": 33188,
      "old_path": "include/clang/Basic/Diagnostic.td",
      "new_id": "53b1db265ccd038b59fea88e347d3bc268f7ea3a",
      "new_mode": 33188,
      "new_path": "include/clang/Basic/Diagnostic.td"
    },
    {
      "type": "modify",
      "old_id": "17fecd346f03ebfc2d85bc4f0de8d1c9d6e3e44a",
      "old_mode": 33188,
      "old_path": "include/clang/Basic/DiagnosticIDs.h",
      "new_id": "06446cf580389cd412acf775a79167ff0092c976",
      "new_mode": 33188,
      "new_path": "include/clang/Basic/DiagnosticIDs.h"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "da8bd257037e9a9a40c022870a2c7f24f1812e67",
      "new_mode": 33188,
      "new_path": "include/clang/Basic/DiagnosticTrap.h"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "c17a88d4fb4fb47275ba5d7fb783a5714be57768",
      "new_mode": 33188,
      "new_path": "include/clang/Basic/DiagnosticTrapKinds.td"
    },
    {
      "type": "modify",
      "old_id": "82e8212bee12d524f539b98d94f9eea76cb87c63",
      "old_mode": 33188,
      "old_path": "include/clang/Driver/Options.td",
      "new_id": "b1ae3cf6525b807b9ad62fcb3a037408bc404347",
      "new_mode": 33188,
      "new_path": "include/clang/Driver/Options.td"
    },
    {
      "type": "modify",
      "old_id": "e33e843db6a44c52f8db5c421a68741a21a577a8",
      "old_mode": 33188,
      "old_path": "lib/Basic/Diagnostic.cpp",
      "new_id": "dc3778bbf339cf2c453e5e5d791d9d03299a1c4c",
      "new_mode": 33188,
      "new_path": "lib/Basic/Diagnostic.cpp"
    },
    {
      "type": "modify",
      "old_id": "73f24a82d4c7560a23282dab05d0fdafd5af705f",
      "old_mode": 33188,
      "old_path": "lib/Basic/DiagnosticIDs.cpp",
      "new_id": "a1d9d0f34d20dca3d4ebcef42b224b517d90ebfa",
      "new_mode": 33188,
      "new_path": "lib/Basic/DiagnosticIDs.cpp"
    },
    {
      "type": "modify",
      "old_id": "eeaf68dfd0521b51b84de7dc76070b415a10cba8",
      "old_mode": 33188,
      "old_path": "lib/CodeGen/CGExpr.cpp",
      "new_id": "844b445b98c1d3dc88324789ef0f0aed5ff5ec5d",
      "new_mode": 33188,
      "new_path": "lib/CodeGen/CGExpr.cpp"
    },
    {
      "type": "modify",
      "old_id": "2338cbd74f0023615501cb764970943219a3e00e",
      "old_mode": 33188,
      "old_path": "lib/CodeGen/CGExprScalar.cpp",
      "new_id": "2eff3a387593cf772cb9d5bd816286766f45cc4d",
      "new_mode": 33188,
      "new_path": "lib/CodeGen/CGExprScalar.cpp"
    },
    {
      "type": "modify",
      "old_id": "0f2a352886e7f8d90aece602c066b182ba5dd4a3",
      "old_mode": 33188,
      "old_path": "lib/CodeGen/CMakeLists.txt",
      "new_id": "ad9ef91c781a8734fcc026ca3d3c7df53022acab",
      "new_mode": 33188,
      "new_path": "lib/CodeGen/CMakeLists.txt"
    },
    {
      "type": "modify",
      "old_id": "a562a6a1ea6e163329a3f1492a3fd0a5280620d1",
      "old_mode": 33188,
      "old_path": "lib/CodeGen/CodeGenFunction.h",
      "new_id": "c02ac18ec0198dec30a6d01e424f73c906520eaa",
      "new_mode": 33188,
      "new_path": "lib/CodeGen/CodeGenFunction.h"
    },
    {
      "type": "modify",
      "old_id": "705d9a3cb9de317f3225d9cb51a1f8d3c7867c9a",
      "old_mode": 33188,
      "old_path": "lib/CodeGen/CodeGenModule.h",
      "new_id": "b4b3a1766204517cb0dbf050f2fd72e05039a6bc",
      "new_mode": 33188,
      "new_path": "lib/CodeGen/CodeGenModule.h"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "5881229bf747d76f1e527f9d518b3de160b90f15",
      "new_mode": 33188,
      "new_path": "lib/CodeGen/TrapReasonBuilder.cpp"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "b16cae482153a99fbe135c6a57f6b20b2a949ef5",
      "new_mode": 33188,
      "new_path": "lib/CodeGen/TrapReasonBuilder.h"
    },
    {
      "type": "modify",
      "old_id": "54f0e63b9807010b9369be296caa240dc34dc2c0",
      "old_mode": 33188,
      "old_path": "lib/Driver/SanitizerArgs.cpp",
      "new_id": "7ce1afe6f2e6a6ac2d7c843562459bf7d37a9efe",
      "new_mode": 33188,
      "new_path": "lib/Driver/SanitizerArgs.cpp"
    },
    {
      "type": "modify",
      "old_id": "225778d68833de9da82209f479756cf0beb4832b",
      "old_mode": 33188,
      "old_path": "test/DebugInfo/Generic/ubsan-trap-reason-add-overflow.c",
      "new_id": "862d434d291bc729cf5a436fd0ad3634b72aa706",
      "new_mode": 33188,
      "new_path": "test/DebugInfo/Generic/ubsan-trap-reason-add-overflow.c"
    },
    {
      "type": "modify",
      "old_id": "5cc16d154bf6850146b1367fca5605a63acf5c9e",
      "old_mode": 33188,
      "old_path": "test/DebugInfo/Generic/ubsan-trap-reason-flag.c",
      "new_id": "2968e6bd2ade41ffb8543d4ca631e15c43735858",
      "new_mode": 33188,
      "new_path": "test/DebugInfo/Generic/ubsan-trap-reason-flag.c"
    },
    {
      "type": "modify",
      "old_id": "cf9a0b4e7439cb9e85fecb7b8224a7ef4eefa296",
      "old_mode": 33188,
      "old_path": "test/DebugInfo/Generic/ubsan-trap-reason-mul-overflow.c",
      "new_id": "ba3928d0c2e63a12b8a11f8df59fb45e86e5d95e",
      "new_mode": 33188,
      "new_path": "test/DebugInfo/Generic/ubsan-trap-reason-mul-overflow.c"
    },
    {
      "type": "modify",
      "old_id": "62aa7fc953dad8b2cf4279a9444a42de018ea855",
      "old_mode": 33188,
      "old_path": "test/DebugInfo/Generic/ubsan-trap-reason-sub-overflow.c",
      "new_id": "596d777fa4360ca0a2be818c1d75004913fa9bd6",
      "new_mode": 33188,
      "new_path": "test/DebugInfo/Generic/ubsan-trap-reason-sub-overflow.c"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "5a0ccde015939439f0d16d89c2d0774c8a27e44d",
      "new_mode": 33188,
      "new_path": "test/Driver/fsanitize-debug-trap-reasons.c"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "82b33eaf1cb277b16a4998443f56d3bcfa37a2f2",
      "new_mode": 33188,
      "new_path": "test/Frontend/fsanitize-debug-trap-reasons.c"
    },
    {
      "type": "modify",
      "old_id": "9f9647126dd8a0f48d5ce1f5444f411ffc15ddcd",
      "old_mode": 33188,
      "old_path": "tools/diagtool/ListWarnings.cpp",
      "new_id": "ce24f11bd14111ee463a0b1db268066444861868",
      "new_mode": 33188,
      "new_path": "tools/diagtool/ListWarnings.cpp"
    }
  ]
}
