{"id":348781,"date":"2023-06-14T15:01:25","date_gmt":"2023-06-14T15:01:25","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=348781"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=348781","title":{"rendered":"<span>\u041f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e\u0431 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430\u0445. \u0421\u043a\u0430\u0437 \u0442\u0440\u0435\u0442\u0438\u0439: \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u042d\u0442\u043e \u0446\u0438\u043a\u043b \u0441\u0442\u0430\u0442\u0435\u0439 \u043e\u0431 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430\u0445 \u0432\u043e\u043e\u0431\u0449\u0435 \u0438 LLVM \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438. \u0421\u043c\u043e\u0442\u0440\u0438 \u0432\u0441\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430:<\/p>\n<ol>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/articles\/735152\/\" rel=\"noopener noreferrer nofollow\">SSA \u0444\u043e\u0440\u043c\u0430<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/articles\/737646\/\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/a><\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/p>\n<\/li>\n<\/ol>\n<p>\u0412\u043e\u043e\u0431\u0449\u0435-\u0442\u043e, \u0442\u0440\u0435\u0442\u044c\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u043b\u0430 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\u0445. \u041d\u043e \u043f\u043e\u043a\u0430 \u044f \u043f\u0440\u0438\u043a\u0438\u0434\u044b\u0432\u0430\u043b \u0435\u0451 \u043f\u043b\u0430\u043d, \u0441\u0442\u0430\u043b\u043e \u044f\u0441\u043d\u043e, \u0447\u0442\u043e \u0431\u0435\u0437 \u043e\u0441\u0432\u0435\u0449\u0435\u043d\u0438\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0430\u0441\u043f\u0435\u043a\u0442\u043e\u0432 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u043e\u0435 \u0438\u0437 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0445 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0439 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u044b\u0439 \u0448\u0430\u0433, \u043f\u0440\u0435\u0436\u0434\u0435, \u0447\u0435\u043c \u043e\u043a\u0443\u043d\u0430\u0442\u044c\u0441\u044f \u0432 \u043e\u043c\u0443\u0442 \u0441 \u0433\u043e\u043b\u043e\u0432\u043e\u0439.<\/p>\n<p>\u041d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u043c\u043d\u043e\u0433\u0438\u0435 \u0441\u043b\u044b\u0448\u0430\u043b\u0438, \u0447\u0442\u043e \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 (undefined behavior, UB) &#8212; \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u044b\u0439 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u0445 \u0431\u0430\u0433\u043e\u0432, \u0438\u043d\u043e\u0433\u0434\u0430 \u043e\u0447\u0435\u043d\u044c \u0437\u0430\u0431\u0430\u0432\u043d\u044b\u0445, \u0438\u043d\u043e\u0433\u0434\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e <a href=\"https:\/\/blog.tchatzigiannakis.com\/undefined-behavior-can-literally-erase-your-hard-disk\/\" rel=\"noopener noreferrer nofollow\">\u0436\u0443\u0442\u043a\u0438\u0445<\/a>. \u0422\u0435\u043c\u0430 \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u043e\u0434\u043d\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u043e\u0441\u0432\u0435\u0449\u0430\u043b\u0430\u0441\u044c \u0438 \u043d\u0430 \u0425\u0430\u0431\u0440\u0435, \u043d\u0430\u0432\u0441\u043a\u0438\u0434\u043a\u0443 <a href=\"https:\/\/habr.com\/ru\/articles\/136283\/\" rel=\"noopener noreferrer nofollow\">\u0440\u0430\u0437<\/a>, <a href=\"https:\/\/habr.com\/ru\/articles\/341048\/\" rel=\"noopener noreferrer nofollow\">\u0434\u0432\u0430<\/a>, <a href=\"https:\/\/habr.com\/ru\/companies\/pvs-studio\/articles\/276657\/\" rel=\"noopener noreferrer nofollow\">\u0442\u0440\u0438 <\/a>(\u0438 \u0434\u0430\u0436\u0435 \u0446\u0435\u043b\u044b\u0439 \u0442\u0435\u0433 \u0435\u0441\u0442\u044c). \u041e\u0434\u043d\u0430\u043a\u043e \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e \u0434\u0430\u043d\u043d\u043e\u0439 \u0442\u0435\u043c\u0435 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u044b \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u0441\u0442\u0440\u0435\u043b\u0438\u0442\u044c \u0441\u0435\u0431\u0435 \u043d\u043e\u0433\u0443, \u0433\u043e\u043b\u043e\u0432\u0443 \u0438\u043b\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0441\u0436\u0435\u0447\u044c \u0441\u0432\u043e\u0439 \u0436\u0451\u0441\u0442\u043a\u0438\u0439 \u0434\u0438\u0441\u043a, \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0432 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043a\u043e\u0434. \u042f \u0436\u0435 \u043d\u0430\u043c\u0435\u0440\u0435\u043d \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0430\u043a\u0446\u0435\u043d\u0442 \u043d\u0430 \u0442\u043e\u043c, \u0437\u0430\u0447\u0435\u043c \u0430\u0432\u0442\u043e\u0440\u044b \u044f\u0437\u044b\u043a\u043e\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b\u0438 \u0432\u0441\u0435\u0439 \u044d\u0442\u043e\u0439 \u043a\u0440\u0430\u0441\u043e\u0442\u044b, \u0438 \u043a\u0430\u043a \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u0435\u0451 \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0437 \u043d\u0435\u0451 \u043f\u0435\u0440\u0444\u043e\u043c\u0430\u043d\u0441. \u0412\u0441\u0451 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u044b\u043c\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0438\u0437 LLVM \u0438 \u043f\u0440\u0438\u0441\u044b\u043f\u0430\u043d\u043e \u0431\u0430\u0439\u043a\u0430\u043c\u0438 \u0438\u0437 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430, \u0442\u0430\u043a \u0447\u0442\u043e \u043d\u0430\u043b\u0438\u0432\u0430\u0439\u0442\u0435 \u0441\u0435\u0431\u0435 \u0447\u0430\u0439, \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0439\u0442\u0435\u0441\u044c \u043f\u043e\u0443\u0434\u043e\u0431\u043d\u0435\u0435, \u0438 \u043f\u043e\u0433\u043d\u0430\u043b\u0438.<\/p>\n<h2>\u041a\u043e\u0440\u043e\u0442\u043a\u043e \u043e \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0435<\/h2>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 undefined behavior, \u0442\u043e \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0434\u043b\u044f \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u043b\u0435\u043d\u0438\u044f. \u041d\u0430\u0447\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0441\u043e \u0441\u0442\u0430\u0442\u044c\u0438 \u0432 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Undefined_behavior\" rel=\"noopener noreferrer nofollow\">\u0412\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u0438<\/a>, \u0430 \u0434\u0430\u043b\u044c\u0448\u0435 \u0433\u0443\u0433\u043b\u0438\u0442\u044c \u043f\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u0430\u043c \u0438 \u043d\u0430\u0441\u043b\u0430\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u0434\u0435\u0441\u044f\u0442\u043a\u0430\u043c\u0438 \u0438\u0441\u0442\u043e\u0440\u0438\u0439 \u043d\u0430 \u0442\u0435\u043c\u0443 &#171;\u044f \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u044e, \u043a\u0430\u043a\u043e\u0433\u043e \u0447\u0451\u0440\u0442\u0430 \u043c\u043e\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0435 \u0442\u0430\u043a, \u043a\u0430\u043a \u043c\u043d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f&#187; \u0438\u043b\u0438 &#171;1001 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0442\u0441\u0442\u0440\u0435\u043b\u0438\u0442\u044c \u0441\u0435\u0431\u0435 \u043d\u043e\u0433\u0443 \u0434\u043b\u044f \u0447\u0430\u0439\u043d\u0438\u043a\u043e\u0432&#187;. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0437\u0430\u0431\u0430\u0432\u043d\u044b, \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0441 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u043e, \u0447\u0442\u043e \u0432 \u044f\u0437\u044b\u043a\u0430\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (\u0438 \u043e\u0441\u043e\u0431\u043e \u044d\u0442\u0438\u043c \u0441\u043b\u0430\u0432\u0435\u043d \u0421++ \u0438 \u0435\u043c\u0443 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435) \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u0444\u0440\u0430\u0437\u044b \u0442\u0438\u043f\u0430<\/p>\n<blockquote>\n<p>When signed integer arithmetic operation overflows (the result does not fit in the result type), the behavior is undefined<\/p>\n<\/blockquote>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u0432\u0441\u0451 \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e: \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c, \u0432\u0430\u043c \u043f\u043e\u0432\u0435\u0437\u0451\u0442, \u0438 \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e \u043c\u043e\u0434\u0443\u043b\u044e <em>2<sup>n<\/sup><\/em>, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u0432\u0435\u0437\u0451\u0442 \u0447\u0443\u0442\u044c \u043c\u0435\u043d\u044c\u0448\u0435, \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c 0 \u0438\u043b\u0438 SINT_MAX, \u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c, \u0432\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0443\u0434\u0430\u043b\u0438\u0442 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433, \u0430 \u0436\u0451\u0441\u0442\u043a\u0438\u0439 \u0434\u0438\u0441\u043a \u0441\u0433\u043e\u0440\u0438\u0442 \u0441\u0438\u043d\u0438\u043c \u043f\u043b\u0430\u043c\u0435\u043d\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0432\u044b \u0441\u043b\u043e\u0436\u0438\u043b\u0438 \u0434\u0432\u0430 \u0447\u0438\u0441\u043b\u0430.<\/p>\n<p>\u0412\u043e\u0442 \u043a\u0440\u0430\u0442\u043a\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u0441 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c:<\/p>\n<ul>\n<li>\n<p>\u041f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u043a\u043e\u0432\u043e\u0439 \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u043a\u0438<\/p>\n<\/li>\n<li>\n<p>\u0414\u0435\u043b\u0435\u043d\u0438\u0435 (\u0438\u043b\u0438 \u0432\u0437\u044f\u0442\u0438\u0435 \u043e\u0441\u0442\u0430\u0442\u043a\u0430) \u043d\u0430 0<\/p>\n<\/li>\n<li>\n<p>\u0420\u0430\u0437\u044b\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 (\u0442.\u0435. \u0447\u0442\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c) nullptr \u0438\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u043d\u0435\u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u0430)<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p>\u0411\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0431\u0435\u0437 \u0441\u0430\u0439\u0434-\u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u0413\u043e\u043d\u043a\u0430 \u043f\u0440\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0435\u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>\u0438 \u0442.\u043f.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0411\u043b\u0430\u0433\u0438\u043c\u0438 \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u0438\u044f\u043c\u0438<\/h3>\n<p>\u0412 \u043d\u0430\u0448\u0435\u0439 \u0441\u0440\u0435\u0434\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u043c &#171;demon optimizer&#187; &#8212; \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0439 \u0433\u0438\u043f\u043e\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0432\u043e\u0434, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043c\u043e\u0436\u0435\u0442 \u0441\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f UB, \u0438 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u0442\u0430\u0440\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u043d\u043e\u0441\u0438\u0442\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0439 \u0443\u0440\u043e\u043d (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c &#171;rm -rf \/&#187; \u0432\u0435\u0437\u0434\u0435, \u043a\u043e\u0433\u0434\u0430 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0445\u043e\u0442\u044c \u043a\u0430\u043a\u0430\u044f-\u0442\u043e \u0437\u043d\u0430\u043a\u043e\u0432\u0430\u044f \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u043a\u0430). \u041f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0441\u0442\u0430\u0432\u0438\u0442 \u0441\u0435\u0431\u0435 \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u0440\u0438 \u043c\u0430\u043b\u0435\u0439\u0448\u0435\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u0430\u0433\u0430\u0434\u0438\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0443. \u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432\u0441\u0451 \u0445\u0443\u0436\u0435: \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0433\u0430\u0434\u0438\u0442\u044c \u0435\u043c\u0443, \u0438\u0441\u043a\u0440\u0435\u043d\u043d\u0435 \u0441\u0442\u0430\u0440\u0430\u044f\u0441\u044c \u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043e\u0431\u0440\u043e.<\/p>\n<p>\u041d\u0435 \u0442\u0430\u043a \u0434\u0430\u0432\u043d\u043e \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430\u0445 \u0434\u0438\u0432\u0438\u043b\u0438\u0441\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438: \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 clang \u0443\u043c\u0443\u0434\u0440\u0438\u043b\u0441\u044f \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e never_called<\/p>\n<pre><code class=\"cpp\">#include &lt;iostream>  int main() {     int cnt = 0;     while (cnt++ != -1) {}     return 0; }  void never_called() {     std::cout &lt;&lt; \"You are screwed\" &lt;&lt; std::endl; } <\/code><\/pre>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u043f\u0440\u0438\u043d\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c &#171;rm -rf \/&#187;, \u0438 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f. \u041f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043d\u0435\u0442\u0440\u0443\u0434\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u0435\u0441\u043b\u0438 \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0432 <a href=\"https:\/\/godbolt.org\/z\/GM87qhnsz\" rel=\"noopener noreferrer nofollow\">godbolt<\/a>: <\/p>\n<pre><code class=\"assembly\">main:                                   # @main never_called():                      # @never_called()         push    rbx         mov     rbx, qword ptr [rip + std::cout@GOTPCREL]         lea     rsi, [rip + .L.str]         mov     edx, 15         mov     rdi, rbx         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::__ostream_insert&lt;char, std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;, char const*, long)@PLT         mov     rax, qword ptr [rbx]         mov     rax, qword ptr [rax - 24]         mov     rbx, qword ptr [rbx + rax + 240]         test    rbx, rbx         je      .LBB1_5         cmp     byte ptr [rbx + 56], 0         je      .LBB1_3         movzx   eax, byte ptr [rbx + 67]         jmp     .LBB1_4 .LBB1_3:         mov     rdi, rbx         call    std::ctype&lt;char>::_M_widen_init() const@PLT         mov     rax, qword ptr [rbx]         mov     rdi, rbx         mov     esi, 10         call    qword ptr [rax + 48] .LBB1_4:         movsx   esi, al         mov     rdi, qword ptr [rip + std::cout@GOTPCREL]         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >::put(char)@PLT         mov     rdi, rax         pop     rbx         jmp     std::basic_ostream&lt;char, std::char_traits&lt;char> >::flush()@PLT               # TAILCALL .LBB1_5:         call    std::__throw_bad_cast()@PLT .L.str:         .asciz  \"You are screwed\"<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u043f\u0440\u044f\u043c\u043e \u0437\u0430 \u043c\u0435\u0442\u043a\u043e\u0439 main \u0438\u0434\u0451\u0442 \u043c\u0435\u0442\u043a\u0430 \u043d\u0430\u0447\u0430\u043b\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 never_called, \u0438 \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0435\u0439 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u043f\u043e\u0439\u0434\u0451\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0435\u0433\u043e \u0434\u0430\u043b\u044c\u0448\u0435 \u0441\u043f\u043b\u043e\u0448\u043d\u044f\u043a\u043e\u043c. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0441\u0445\u0435\u043c\u0443 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u044d\u0442\u043e <a href=\"https:\/\/godbolt.org\/z\/o65ro3KMa\" rel=\"noopener noreferrer nofollow\">\u0441\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c<\/a>.<\/p>\n<ol>\n<li>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0443 \u0421++, \u0437\u043d\u0430\u043a\u043e\u0432\u043e\u0435 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 &#8212; \u044d\u0442\u043e UB. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e cnt, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0431\u044b\u043b\u043e \u0440\u0430\u0432\u043d\u043e \u043d\u0443\u043b\u044e \u0438 \u0448\u043b\u043e \u0432\u0432\u0435\u0440\u0445, \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c. \u041e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043e\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438, \u043d\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e UB, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u043d\u0430 \u044d\u0442\u043e \u043d\u0430\u043f\u043b\u0435\u0432\u0430\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 &#171;cnt != -1&#187; \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0432 &#171;true&#187;, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 cnt &#8212; \u043d\u0435\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435, \u0430 -1 &#8212; \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435, \u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u043e\u043d\u0438 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0440\u0430\u0432\u043d\u044b.<\/p>\n<\/li>\n<li>\n<p>\u0426\u0438\u043a\u043b while (true) {} &#8212; \u044d\u0442\u043e \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0431\u0435\u0437 \u0441\u0430\u0439\u0434-\u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432, \u0442\u043e \u0435\u0441\u0442\u044c UB. \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0441\u0447\u0438\u0442\u0430\u0435\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u0441\u044e\u0434\u0430 \u043f\u0440\u0438\u0448\u043b\u0438, \u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0451 \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440&#8230; \u041d\u0438\u0447\u0435\u0433\u043e. \u0412\u043e\u043e\u0431\u0449\u0435. \u041c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0446\u0438\u043a\u043b \u0438 \u0432\u0435\u0441\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 return&#8217;\u043e\u043c.<\/p>\n<\/li>\n<\/ol>\n<p>\u041e\u0431\u0430 \u0440\u0430\u0437\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0441\u0434\u0435\u043b\u0430\u043b \u043d\u0435\u0447\u0442\u043e \u0443\u043c\u043d\u043e\u0435 \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435. \u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u0447\u0438\u0441\u0435\u043b \u0438 \u0437\u0430\u043c\u0435\u043d\u0430 \u0435\u0433\u043e \u043d\u0430 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 &#8212; \u044d\u0442\u043e \u0431\u043b\u0430\u0433\u043e. \u0412\u0430\u043c \u043d\u0435 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u043d\u0430 \u044d\u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043d\u044b\u0439 \u0442\u0430\u043a\u0442. \u0427\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430, \u0442\u043e \u0442\u0443\u0442 \u043e \u0431\u043b\u0430\u0433\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043f\u043e\u0440\u0438\u0442\u044c, \u043d\u043e \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u043a\u0442\u043e-\u0442\u043e \u0431\u044b \u043f\u043e\u0441\u043b\u0435 while (true) {} \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0446\u0435\u043b\u0443\u044e \u0433\u043e\u0440\u0443 \u043a\u043e\u0434\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440. \u043f\u043e \u043e\u0448\u0438\u0431\u043a\u0435. \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u0431\u044b \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0435\u0451 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0442\u0430\u0449\u0438\u0442\u044c \u0434\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u043a\u043e\u043d\u0446\u0430, \u0442\u0440\u0430\u0442\u044f \u043d\u0430 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0441\u0432\u043e\u0451 \u0432\u0440\u0435\u043c\u044f, \u043f\u0440\u0438\u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f. \u0423\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u044d\u0442\u043e, \u0435\u0433\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 &#8212; \u044d\u0442\u043e \u0442\u043e\u0436\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435 \u0434\u043b\u044f \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u0441\u0430\u043c\u043e\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u0412\u044b\u0445\u043e\u0434\u0438\u0442, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0431\u0440\u043e, \u0430 \u0441\u0434\u0435\u043b\u0430\u043b \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u043e\u043f\u0430\u0441\u043d\u0443\u044e \u0435\u0440\u0443\u043d\u0434\u0443.<\/p>\n<h2>UB &#8212; \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/h2>\n<p>\u041c\u043d\u043e\u0433\u0438\u0435 \u0437\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c: \u043d\u0443 \u0445\u043e\u0440\u043e\u0448\u043e, \u0440\u0430\u0437 UB &#8212; \u044d\u0442\u043e, \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e, \u043e\u0447\u0435\u043d\u044c \u0441\u0442\u0440\u0430\u0448\u043d\u043e \u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0443\u0436\u0430\u0441\u043d\u044b\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c warning \u0432 \u0442\u0435\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u0445, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043a\u043e\u0434? \u041c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0446\u0438\u0439 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<p>\u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u044f\u0437\u044b\u043a\u0430\u0445 \u0432\u0440\u043e\u0434\u0435 \u0421++ \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043c\u043e\u0433\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 <strong>\u043f\u0440\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445<\/strong>. \u0414\u0435\u043b\u0435\u043d\u0438\u0435 \u0432\u0435\u0434\u0451\u0442 \u043a UB <strong>\u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438<\/strong> \u0437\u043d\u0430\u043c\u0435\u043d\u0430\u0442\u0435\u043b\u044c \u0440\u0430\u0432\u0435\u043d \u043d\u0443\u043b\u044e. \u0412\u0440\u044f\u0434 \u043b\u0438 \u043a\u0442\u043e-\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0442\u0430\u043c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 0 (\u0442\u0430\u043a\u043e\u0435 \u0431\u044b\u0432\u0430\u0435\u0442, \u043d\u043e \u044d\u0442\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u0443\u0447\u0435\u0431\u043d\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430, \u0430 \u043d\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438), \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e &lt;\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 1> \/ &lt;\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 2>, \u0438 \u0447\u0435\u043c\u0443 \u0440\u0430\u0432\u043d\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 2 &#8212; \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c \u043c\u043e\u0436\u0435\u0442 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0446\u0438\u043a\u043b while (true), \u043d\u043e \u0438 \u0446\u0438\u043a\u043b \u0441 \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u043c, \u043d\u0435 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c\u044b\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u043e\u0435, \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u0441\u0442\u0438\u043d\u043d\u043e. \u0422\u0430\u043a\u0436\u0435 \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u0435 x + y \u043c\u043e\u0436\u0435\u0442 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 \u043e\u0434\u043d\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 (\u0438 \u043f\u043e\u0440\u043e\u0434\u0438\u0442\u044c UB), \u0430 \u043c\u043e\u0436\u0435\u0442 \u0438 \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0438\u0442\u044c\u0441\u044f.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u0438 \u0438\u043c\u0435\u0442\u044c \u0442\u0430\u043a\u043e\u0439 warning, \u043e\u043d \u0431\u044b \u0432\u044b\u043b\u0435\u0442\u0430\u043b \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u0432\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u041e\u0447\u0435\u043d\u044c \u0440\u0435\u0434\u043a\u043e \u043a\u043e\u0433\u0434\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u043c\u043e\u0436\u043d\u043e \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0438 \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043f\u0440\u0435\u0434\u043c\u0435\u0442 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f\/\u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043d\u043e\u0439 \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0441\u0442\u0438\/\u043d\u0443\u043b\u0451\u0432\u043e\u0441\u0442\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u0421\u0442\u0440\u043e\u0433\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442, constexpr&#8217;\u043e\u0432 \u0438 \u0438\u0445 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0445, \u0434\u0430 \u0438 \u0442\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 (\u0438\u043d\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u043e\u043b\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0437\u0430\u043d\u0438\u043c\u0430\u043b\u0441\u044f \u044d\u0442\u0438\u043c \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435). \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0442\u043e, \u0431\u0443\u0434\u0435\u0442 \u043b\u0438 \u0432\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u043d\u0435\u0442, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0445\u043e\u0434\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0451\u043c \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"cpp\">int foo(int x) {   int sum = 0;   for (int i = 0; i &lt; 1000; i++)     if (cond(i))       sum += i \/ x;   return sum; }<\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0438 \u0434\u0432\u0443\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439:<\/p>\n<ul>\n<li>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u0441 x = 0<\/p>\n<\/li>\n<li>\n<p>cond(i) \u0432\u0435\u0440\u043d\u0451\u0442 true \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u0440\u0430\u0437<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 0, \u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0430\u0432\u043e \u0437\u0430\u043a\u0440\u0430\u0448\u0438\u0442\u044c\u0441\u044f, \u043f\u043e\u0432\u0438\u0441\u043d\u0443\u0442\u044c, \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u043d\u0438\u0431\u0443\u0434\u044c \u0435\u0440\u0443\u043d\u0434\u0443 \u0438 \u0442.\u0434. \u041e\u0434\u043d\u0430\u043a\u043e \u0441\u0430\u043c \u0444\u0430\u043a\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u0432 \u043d\u0435\u0439 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0435\u0449\u0451 \u043d\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 UB.<\/p>\n<h2>\u041d\u0435\u0438\u0437\u0431\u0435\u0436\u043d\u043e\u0435 UB \u043f\u0443\u0442\u0435\u0448\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/h2>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u0440\u0438 \u043a\u0430\u043a\u043e\u043c-\u0442\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442, \u0442\u043e \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, <strong>\u0433\u0434\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u0438 \u043a\u043e\u0433\u0434\u0430<\/strong> \u043e\u043d\u043e \u043f\u0440\u043e\u044f\u0432\u0438\u0442\u0441\u044f. \u041f\u0440\u0438\u0432\u0435\u0434\u0451\u043c \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"cpp\">void foo(int *ptr) {   printf(\"Before the loop\\n\");   for (int i = 0; i &lt; 1000; i++) {     printf(\"Before check\\n\");     if (i == 17)       *ptr = 1;     printf(\"After check\\n\");   }   printf(\"After the loop the loop\\n\"); }<\/code><\/pre>\n<p>\u0427\u0435\u043b\u043e\u0432\u0435\u043a\u0443 \u043d\u0430\u0438\u0432\u043d\u043e\u043c\u0443 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0441 ptr = nullptr \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c:<\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0442\u043e\u0447\u043d\u043e \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 &#171;Before the loop&#187;;<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0442\u043e\u0447\u043d\u043e 17 \u0440\u0430\u0437 \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u043f\u0430\u0440\u0443 &#171;Before check&#187;\/&#187;After check&#187;;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0442\u043e\u043c \u0434\u043b\u044f i = 17 \u0435\u0449\u0451 \u0440\u0430\u0437 \u0442\u043e\u0447\u043d\u043e \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442\u0441\u044f &#171;Before check&#187;, \u0430 \u0432\u043e\u0442 \u0434\u0430\u043b\u044c\u0448\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438 \u043a\u0440\u0430\u0448\/\u0437\u0430\u0432\u0438\u0441\u0430\u043d\u0438\u0435\/\u043b\u0438\u0431\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u0442\u0440\u0430\u043d\u043d\u043e\u0435.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u043e\u0435 \u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442, \u0435\u0441\u043b\u0438 \u0434\u0443\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0440\u043e\u0432\u043d\u043e \u0442\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438, \u0438 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0436\u0435. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u044b \u0442\u0430\u043a \u043d\u0435 \u0434\u0435\u043b\u0430\u044e\u0442. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u043f\u043e\u043b\u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0430\u0432\u043e \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0439:<\/p>\n<ul>\n<li>\n<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435 i == 17 \u0441\u0442\u0430\u043d\u0435\u0442 \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u043c (\u043f\u0440\u0438\u0447\u0451\u043c \u0442\u043e\u043b\u044c\u043a\u043e 1 \u0440\u0430\u0437) \u0432 \u0445\u043e\u0434\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0430\u043f\u0438\u0441\u044c \u0435\u0434\u0438\u043d\u0438\u0446\u044b \u0432 *ptr \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u043b\u0438\u0448\u043d\u044e\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0432 \u0446\u0438\u043a\u043b\u0435, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0430\u0432\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439:<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"cpp\">void foo(int *ptr) {   *ptr = 1;   printf(\"Before the loop\\n\");   for (int i = 0; i &lt; 1000; i++) {     printf(\"Before check\\n\");     printf(\"After check\\n\");   }   printf(\"After the loop the loop\\n\"); }  void foo(int *ptr) {   printf(\"Before the loop\\n\");   for (int i = 0; i &lt; 1000; i++) {     printf(\"Before check\\n\");     printf(\"After check\\n\");   }   printf(\"After the loop the loop\\n\");   *ptr = 1; }  void foo(int *ptr) {   printf(\"Before the loop\\n\");   for (int i = 0; i &lt; 17; i++) {     printf(\"Before check\\n\");     printf(\"After check\\n\");   }   *ptr = 1;   for (int i = 17; i &lt; 1000; i++) {     printf(\"Before check\\n\");     printf(\"After check\\n\");   }   printf(\"After the loop the loop\\n\"); }<\/code><\/pre>\n<p>\u041d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b, \u043d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0438 \u044d\u0442\u0438\u0445. UB &#8212; \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435. \u0415\u0441\u043b\u0438 ptr != nullptr, \u0442\u043e \u0435\u0433\u043e \u0432 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435\u0442, \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u044b \u0432 \u044d\u0442\u0443 \u043f\u0430\u043c\u044f\u0442\u044c \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u043f\u0440\u0438\u043d\u0442\u043e\u0432, \u0438 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0439 \u0432 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u0432\u044b \u043d\u0435 \u0443\u0432\u0438\u0434\u0438\u0442\u0435. \u041e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u043b\u0438 ptr == nullptr, \u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0430\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a: \u0440\u0430\u0437 UB \u043d\u0435\u0438\u0437\u0431\u0435\u0436\u043d\u043e \u0441\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0432 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 (\u0430 \u044d\u0442\u043e \u0442\u0430\u043a, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e i == 17 \u0442\u043e\u0447\u043d\u043e \u0441\u0442\u0430\u043d\u0435\u0442 true \u0440\u0430\u043d\u043e \u0438\u043b\u0438 \u043f\u043e\u0437\u0434\u043d\u043e), \u0442\u043e \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442. \u0412\u0441\u044f \u044d\u0442\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 . \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u043b\u0438 \u043a\u0440\u0430\u0448 (\u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442) \u0441\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0434\u043e \u0438\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u0446\u0438\u043a\u043b\u0430 \u0438 \u043f\u0440\u0438\u043d\u0442\u043e\u0432, \u0442\u043e \u044d\u0442\u043e \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e. UB &#8212; \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043d\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u0430 \u0432\u0441\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044d\u0442\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0437\u0430\u043a\u0440\u0430\u0448\u0438\u0442\u0441\u044f \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u043d \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u0440\u0438\u043d\u0442, \u0438\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u043d \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 &#8212; \u0438 \u0442\u043e, \u0438 \u0434\u0440\u0443\u0433\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e. \u0414\u0430\u043d\u043d\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442, \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u0430\u0433\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 UB, \u0442\u0430\u043a \u0441\u043b\u043e\u0436\u043d\u043e \u0434\u0438\u0430\u0433\u043d\u043e\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043e\u0431\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044f \u043f\u0440\u0438\u043d\u0442\u0430\u043c\u0438, \u0432 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0435\u043c \u0440\u0435\u0436\u0438\u043c\u0435. \u041b\u0443\u0447\u0448\u0435 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c -O0. \u0422\u0430\u043c \u0432\u0441\u0451 \u0435\u0449\u0451 \u043d\u0435\u0442 \u0436\u0435\u043b\u0435\u0437\u043d\u044b\u0445 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0439, \u043d\u043e \u0435\u0441\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u0434\u0430, \u0447\u0442\u043e \u044d\u0442\u043e \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<h2>\u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u043b\u0438 \u0432\u044b\u043d\u043e\u0441\u0438\u0442\u044c \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0438\u0437 \u0446\u0438\u043a\u043b\u043e\u0432?<\/h2>\n<p>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u044b \u043d\u0430 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0445 \u0441\u043f\u0435\u043a\u0443\u043b\u044f\u0442\u0438\u0432\u043d\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f\u0445. \u042d\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u0437\u0430\u0440\u0430\u043d\u0435\u0435, \u043f\u0440\u0438\u0442\u043e\u043c \u043d\u0435 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u0438\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u043e\u043e\u0431\u0449\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f. \u041f\u0440\u0438\u0432\u0435\u0434\u0443 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440.<\/p>\n<pre><code class=\"cpp\">bool cond(int idx);  int example_add(int x, int y) {   int sum = 0;   for (int i = 0; i &lt; 1000; i++)     if (cond(i))       sum += x + y;   return sum; }<\/code><\/pre>\n<p>\u041f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 cond() \u0432\u0435\u0440\u043d\u0451\u0442 true \u0445\u043e\u0442\u044f \u0431\u044b \u0440\u0430\u0437, \u0430 \u043b\u0443\u0447\u0448\u0435 &#8212; \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437, \u0442\u043e \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0432\u043e\u0442 \u0442\u0430\u043a\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f:<\/p>\n<pre><code class=\"cpp\">bool cond(int idx);  int example_add(int x, int y) {   int sum = 0;   int tmp = x + y;   for (int i = 0; i &lt; 1000; i++)     if (cond(i))       sum += tmp;   return sum; }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f &#171;\u0432\u044b\u043d\u043e\u0441 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0438\u0437 \u0446\u0438\u043a\u043b\u0430&#187;, \u0437\u0434\u0435\u0441\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f x + y \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043d\u043e\u043c\u0435\u0440\u0430 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442.\u043d. \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c. \u0422\u0430\u043a\u0438\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0438 \u0432 \u0446\u0438\u043a\u043b\u0435 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u041d\u0430\u043c \u0431\u044b \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0431\u044b\u043b \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435. \u041d\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0443\u0442\u044c-\u0447\u0443\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440.<\/p>\n<pre><code class=\"cpp\">bool cond(int idx);  int example_div(int x, int y) {   int sum = 0;   for (int i = 0; i &lt; 1000; i++)     if (cond(i))       sum += x \/ y;   return sum; }<\/code><\/pre>\n<p>\u041c\u043e\u0436\u0435\u043c \u043b\u0438 \u043c\u044b \u043f\u0440\u0435\u0434\u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u0441\u0434\u0435\u043b\u0430\u0432 \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435<\/p>\n<pre><code class=\"cpp\">bool cond(int idx);  int example_div(int x, int y) {   int sum = 0;   int tmp = x \/ y;   for (int i = 0; i &lt; 1000; i++)     if (cond(i))       sum += tmp;   return sum; }<\/code><\/pre>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0432\u0441\u0451 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435. \u041d\u043e \u043f\u043e\u0433\u043e\u0434\u0438\u0442\u0435-\u043a\u0430. \u0410 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 cond() \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430\u043c false, \u0430 y = 0? \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430 0, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u0435\u0434\u0451\u0442 \u043a \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e, \u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f &#8212; \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442 \u043d\u0430 0, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0432\u0438\u0441\u043d\u0443\u0442\u044c \u0438\u043b\u0438 \u043f\u043e\u043a\u0440\u0430\u0448\u0438\u0442\u044c\u0441\u044f. \u0412\u044b\u0445\u043e\u0434\u0438\u0442, \u0442\u0430\u043a\u043e\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u043e\u0442 \u0442\u0430\u043a \u0432 \u043b\u043e\u0431 \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f.<\/p>\n<p>\u041d\u043e \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0442\u0430\u043c \u0431\u044b\u043b\u043e \u0441\u043e \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c? \u0412\u0435\u0434\u044c \u0442\u0430\u043c-\u0442\u043e \u0432\u0441\u0451 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e? \u0412\u0435\u0434\u044c \u0442\u0430\u043a?<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/358\/067\/d47\/358067d475a706d9aad7fce0572fa011.jpg\" alt=\"\u041c\u044b \u0432\u0435\u0434\u044c \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u043d\u043e\u0441\u0438\u0442\u044c \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438\u0437 \u0446\u0438\u043a\u043b\u0430, \u0432\u0435\u0440\u043d\u043e?\" title=\"\u041c\u044b \u0432\u0435\u0434\u044c \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u043d\u043e\u0441\u0438\u0442\u044c \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438\u0437 \u0446\u0438\u043a\u043b\u0430, \u0432\u0435\u0440\u043d\u043e?\" width=\"770\" height=\"402\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/358\/067\/d47\/358067d475a706d9aad7fce0572fa011.jpg\" data-blurred=\"true\"\/><\/p>\n<div><figcaption>\u041c\u044b \u0432\u0435\u0434\u044c \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u043d\u043e\u0441\u0438\u0442\u044c \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438\u0437 \u0446\u0438\u043a\u043b\u0430, \u0432\u0435\u0440\u043d\u043e?<\/figcaption><\/div>\n<\/figure>\n<p>\u041d\u0443 \u0447\u0438\u0441\u0442\u043e \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e, \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0421++ \u0438 \u0434\u0435\u043c\u043e\u043d-\u043e\u043f\u0442\u0438\u043c\u0430\u0439\u0437\u0435\u0440\u0430 &#8212; \u043d\u0435\u0442. \u0412\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u0432 \u0421++ \u0437\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f &#8212; \u044d\u0442\u043e UB. \u0412 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 x + y \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f, \u0430 cond() \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 false, \u0438\u0441\u0445\u043e\u0434\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043d\u0435 \u0438\u043c\u0435\u043b\u0430 UB, \u0430 \u043d\u043e\u0432\u0430\u044f &#8212; \u0438\u043c\u0435\u0435\u0442. \u0417\u043b\u043e\u0431\u043d\u044b\u0439 \u0434\u0435\u043c\u043e\u043d-\u043e\u043f\u0442\u0438\u043c\u0430\u0439\u0437\u0435\u0440 \u043c\u043e\u0433 \u0431\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u044d\u0442\u0438\u043c \u0444\u0430\u043a\u0442\u043e\u043c \u0438 \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c rm -rf \/ \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u0434\u0435. \u041d\u0435\u0443\u0436\u0435\u043b\u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0435\u0432\u0430\u043b\u0438\u0434\u043d\u0430?<\/p>\n<h2>Poison \u0432 LLVM<\/h2>\n<p>\u041c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043f\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u043c \u0432\u044b\u0448\u0435, \u0432 \u0421++ \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435\u043b\u044c\u0437\u044f \u0441\u043f\u0435\u043a\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u041c\u0430\u043b\u0435\u0439\u0448\u0438\u0439 \u0447\u0438\u0445 &#8212; \u0438 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 UB \u0432 \u043c\u0435\u0441\u0442\u0435, \u0433\u0434\u0435 \u0435\u0433\u043e \u043d\u0435 \u0431\u044b\u043b\u043e, \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440, \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043b\u0443\u0447\u0448\u0438\u0445 \u043f\u043e\u0431\u0443\u0436\u0434\u0435\u043d\u0438\u0439, \u0432\u0430\u0441 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0445\u043e\u0440\u043e\u043d\u0438\u0442 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043e\u0439 \u0438 \u0436\u0451\u0441\u0442\u043a\u0438\u043c \u0434\u0438\u0441\u043a\u043e\u043c. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432\u0441\u0451 \u043d\u0435 \u0442\u0430\u043a \u043f\u043b\u043e\u0445\u043e. \u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 clang \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u0441\u0451-\u0442\u0430\u043a\u0438 <a href=\"https:\/\/godbolt.org\/z\/5jWehsf3f\" rel=\"noopener noreferrer nofollow\">\u0432\u044b\u043d\u043e\u0441\u0438\u0442<\/a>. \u041d\u043e \u043a\u0430\u043a \u043e\u043d \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442? \u0420\u0430\u0437\u0432\u0435 \u0435\u043c\u0443 \u043d\u0435 \u0441\u0442\u0440\u0430\u0448\u043d\u043e?<\/p>\n<p>\u041d\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0437\u0430\u0431\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0441\u0451-\u0442\u0430\u043a\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u043d\u0435 \u0432 \u0421++-\u043a\u043e\u0434\u0435, \u0430 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 IR. \u0418 \u043a\u0443\u0440\u043e\u0449\u0435\u043d\u0438\u0435 \u0434\u0438\u043a\u0438\u0445 \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f &#8212; \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043b\u0435\u0436\u0438\u0442 \u043d\u0430 \u043f\u043b\u0435\u0447\u0430\u0445 \u0442\u043e\u0433\u043e, \u043a\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u043a\u0430\u043a \u043e\u043d\u043e \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 IR. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0438\u0435\u0441\u044f \u043c\u043e\u0433\u0443\u0442 \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/blog.regehr.org\/archives\/1496\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u0438<\/a> \u0414\u0436\u043e\u043d\u0430 \u0420\u0435\u0439\u0433\u0440\u0430 \u0438\u0437 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442\u0430 \u0448\u0442\u0430\u0442\u0430 \u042e\u0442\u0430 \u0438 \u0434\u0440\u0443\u0433\u0438\u0445, \u044f \u0436\u0435 \u0432\u043a\u0440\u0430\u0442\u0446\u0435 \u043e\u043f\u0438\u0448\u0443, \u043a\u0430\u043a \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0441\u0435\u0439\u0447\u0430\u0441 \u0432 LLVM.<\/p>\n<p>\u0414\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u043d\u0435 \u0447\u0438\u0442\u0430\u043b \u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0435 \u0447\u0430\u0441\u0442\u0438, \u0441\u0435\u0439\u0447\u0430\u0441 \u0441\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c, \u0441\u0441\u044b\u043b\u043a\u0438 \u0435\u0441\u0442\u044c \u0432 \u0448\u0430\u043f\u043a\u0435. <\/p>\n<p>\u041d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 IR-\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 2 \u0442\u0438\u043f\u0430 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>\u041d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e\u0435 UB, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u043e\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438;<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 UB, \u0432\u044b\u0440\u0430\u0436\u0430\u0435\u043c\u043e\u0435 \u043e\u0442\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c (poison) \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c, \u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u043e\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 (\u0430 \u043c\u043e\u0436\u0435\u0442 \u0438 \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438).<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043c \u0440\u0430\u043d\u044c\u0448\u0435 \u0431\u044b\u043b\u043e (\u0438 \u0432\u0441\u0451 \u0435\u0449\u0451 \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f) \u0442\u0430\u043a\u0430\u044f \u0432\u0435\u0449\u044c, \u043a\u0430\u043a undef, \u043d\u043e \u043e\u043d\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u0430\u0431\u043e\u0439 \u0444\u043e\u0440\u043c\u043e\u0439 poison&#8217;\u0430, \u0438 \u043e \u043d\u0435\u0439 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043d\u0435 \u0431\u0443\u0434\u0435\u043c. \u041f\u043e\u0447\u0435\u043c\u0443 \u043e\u0442 \u043d\u0435\u0451 \u043e\u0442\u043a\u0430\u0437\u0430\u043b\u0438\u0441\u044c, \u043f\u0438\u0448\u0435\u0442 \u0442\u043e\u0442 \u0436\u0435 \u0414\u0436\u043e\u043d \u0420\u0435\u0439\u0433\u0440. Poison \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0438\u043a\u0430\u043a\u0438\u043c \u0447\u0438\u0441\u043b\u043e\u043c \u0438 \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438 \u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438:<\/p>\n<ul>\n<li>\n<p>\u041b\u044e\u0431\u0430\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f, \u043e\u043f\u0435\u0440\u0430\u043d\u0434\u043e\u043c \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f poison, \u043b\u0438\u0431\u043e \u0432\u0435\u0434\u0451\u0442 \u043a \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e, \u043b\u0438\u0431\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 poison<\/p>\n<ul>\n<li>\n<p>\u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f: \u0444\u0438\u043d\u043e\u0434\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f poison \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043c \u0438\u0437 \u0431\u043b\u043e\u043a\u0430, \u043e\u0442\u043a\u0443\u0434\u0430 \u043e\u043d \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442; select \u043d\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f poison, \u0435\u0441\u043b\u0438 \u043e\u043d \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435 \u0432\u044b\u0431\u0440\u0430\u043d, \u0438 \u0435\u0441\u0442\u044c \u0435\u0449\u0451 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f freeze-\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f. \u041e \u043d\u0435\u0439 \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043a\u0430\u043a-\u043d\u0438\u0431\u0443\u0434\u044c \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0440\u0430\u0437, \u0436\u0435\u043b\u0430\u044e\u0449\u0438\u0435 \u043c\u043e\u0433\u0443\u0442 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0432 <a href=\"https:\/\/llvm.org\/docs\/LangRef.html#freeze-instruction\" rel=\"noopener noreferrer nofollow\">LangRef<\/a>.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, poison \u043a\u0430\u043a \u0431\u044b \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0435\u0432\u044c\u044f\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439, &#171;\u043e\u0442\u0440\u0430\u0432\u043b\u044f\u044f&#187; \u0438\u0445, \u0430 \u0435\u0441\u043b\u0438 \u044f\u0434 \u0434\u043e\u0442\u0435\u0447\u0451\u0442 \u0434\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043e\u043f\u0430\u0441\u043d\u043e\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <strong>\u0438 \u043e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f<\/strong>, \u0442\u043e \u0441\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 UB.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0430\u0432\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c poison \u0432 \u043b\u044e\u0431\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u0430\u043a\u043e\u0435 \u0435\u043c\u0443 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0435, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0440\u0443\u0433\u043e\u0439 \u043e\u0447\u0435\u043d\u044c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440: \u0432 \u0421++ \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430<\/p>\n<pre><code class=\"cpp\">void foo(int x) {   if (x + 1 > x)     printf(\"true\");   else     printf(\"false\"); }<\/code><\/pre>\n<p>\u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0432 <\/p>\n<pre><code class=\"cpp\">void foo(int x) {   printf(\"true\"); }<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c true \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442\u0441\u044f \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 x = SINT_MAX, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0438\u0432\u043d\u044b\u0435 \u043b\u044e\u0434\u0438 \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043e\u0436\u0438\u0434\u0430\u0442\u044c, \u0447\u0442\u043e x + 1 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u0441\u0442 false. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"assembly\">...   %x.plus.1 = add nsw i32 %x, 1   %cmp = icmp sgt i32 %x.plus.1, %x   br i1 %cmp, label %if.true, label %if.false ...<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0441\u0442\u043e\u0438\u0442 \u0444\u043b\u0430\u0433 nsw (no sign wrap), \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0437\u043d\u0430\u043a\u043e\u0432\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u043e\u043d\u043e \u0432\u0441\u0451 \u0436\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442 (\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u0441 x = SINT_MAX), \u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u044d\u0442\u043e\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 poison. \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0436\u0435 \u0440\u0430\u0437\u043c\u044b\u0448\u043b\u044f\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<ul>\n<li>\n<p>\u0423 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u0440\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0438 %x.plus.1 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<ul>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u0432 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0442\u0430\u043a, \u0442\u043e %x + 1 > %x, \u0438 \u044f \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u043e\u0433\u0443 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c %cmp \u043d\u0430 true<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043c\u043e\u044e \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u044e \u043d\u0430\u0440\u0443\u0448\u0438\u043b\u0438, \u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c %x.plus.1 \u0441\u0442\u0430\u043d\u0435\u0442 poison. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 %cmp \u0435\u0441\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u043d\u0434 poison, \u0442\u043e \u0435\u0451 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0442\u0430\u043a\u0436\u0435 poison. \u041c\u043d\u0435 \u0432\u044b\u0433\u043e\u0434\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u044d\u0442\u043e\u0442 poison \u043d\u0430 true.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u0430\u043b\u0438\u0434\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c %cmp \u043d\u0430 true<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435, nsw \u0438 \u0438\u043c \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u0444\u043b\u0430\u0433\u0438 (\u0435\u0441\u0442\u044c \u0435\u0449\u0451 nuw \u0443 \u0438\u043d\u0442\u043e\u0432, \u0432\u0441\u044f\u043a\u0438\u0435 nnan, ninf \u0438 \u0442.\u043f. \u0443 \u0444\u043b\u043e\u0442\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u0432 (!range) \u043d\u0430 \u043b\u043e\u0430\u0434\u0430\u0445, \u0438 \u043c\u043d\u043e\u0433\u043e\u0435 \u0434\u0440\u0443\u0433\u043e\u0435) \u0433\u043e\u0432\u043e\u0440\u044f\u0442: \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439 (\u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u0438\u043d\u0439, \u043d\u0430\u043d\u043e\u0432, \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0441\u0442\u0435\u0439, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432\u043d\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430) \u0442\u0443\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u044b\u0442\u044c \u043d\u0435 \u043c\u043e\u0436\u0435\u0442. \u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0439\u0442\u0435 \u0442\u0430\u043a, \u0431\u0443\u0434\u0442\u043e \u0431\u044b \u0438\u0445 \u043d\u0435\u0442. \u0410 \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0432\u0441\u0451 \u0436\u0435 \u0431\u0443\u0434\u0443\u0442, \u0442\u043e \u0442\u0430\u043c \u0432\u0441\u0451 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u0441\u044f \u0432 poison, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0442\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c\u0443 UB, \u0430 \u043c\u043e\u0436\u0435\u0442 \u0438 \u043d\u0435 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438.<\/p>\n<h2>\u041e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 UB \u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u043d\u043e\u0441 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432<\/h2>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a poison \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 UB, \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 example_add \u0438 example_div \u043d\u0430 LLVM IR.<\/p>\n<pre><code class=\"assembly\">define noundef i32 @example_add(i32 noundef %x, i32 noundef %y) { entry:   br label %loop  loop:                                             ; preds = %backedge, %entry   %sum = phi i32 [ 0, %entry ], [ %sum.merged, %backedge ]   %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]   %loop.exit.cond = icmp slt i32 %iv, 1000   br i1 %loop.exit.cond, label %check_cond, label %exit  exit:                                             ; preds = %loop   ret i32 %sum  check_cond:                                       ; preds = %loop   %cond = call zeroext i1 @cond(i32 %iv)   br i1 %cond, label %update_sum, label %backedge  update_sum:                                       ; preds = %check_cond   %x.plus.y = add nsw i32 %x, %y   %sum.updated = add nsw i32 %sum, %x.plus.y   br label %backedge  backedge:                                         ; preds = %update_sum, %check_cond   %sum.merged = phi i32 [ %sum.updated, %update_sum ], [ %sum, %check_cond ]   %iv.next = add nsw i32 %iv, 1   br label %loop }  define noundef i32 @example_div(i32 noundef %x, i32 noundef %y) { entry:   br label %loop  loop:                                             ; preds = %backedge, %entry   %sum = phi i32 [ 0, %entry ], [ %sum.merged, %backedge ]   %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]   %loop.exit.cond = icmp slt i32 %iv, 1000   br i1 %loop.exit.cond, label %check_cond, label %exit  exit:                                             ; preds = %loop   ret i32 %sum  check_cond:                                       ; preds = %loop   %cond = call zeroext i1 @cond(i32 %iv)   br i1 %cond, label %update_sum, label %backedge  update_sum:                                       ; preds = %check_cond   %x.div.y = sdiv i32 %x, %y   %sum.updated = add nsw i32 %sum, %x.div.y   br label %backedge  backedge:                                         ; preds = %update_sum, %check_cond   %sum.merged = phi i32 [ %sum.updated, %update_sum ], [ %sum, %check_cond ]   %iv.next = add nsw i32 %iv, 1   br label %loop }  declare i1 @cond(i32)<\/code><\/pre>\n<p>\u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043d\u0435\u0442. \u0422\u0443\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 CFG \u0438 \u043f\u043b\u044e\u0441-\u043c\u0438\u043d\u0443\u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u0432 \u0431\u043b\u043e\u043a\u0435 update_sum (\u0432 \u043e\u0434\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 add nsw, \u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u043c &#8212; sdiv). \u041e\u0434\u043d\u0430\u043a\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434.<\/p>\n<p>\u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e sdiv \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u043d\u0443\u0442\u044c \u0435\u0451 \u0438\u0437 \u0431\u043b\u043e\u043a\u0430 update_sum \u0432 \u0431\u043b\u043e\u043a entry &#8212; \u043d\u0435\u043b\u044c\u0437\u044f, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 cond() \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 false, \u0432 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b UB \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f, \u0430 \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0430 \u043e\u043d\u043e \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u043b\u043e\u0441\u044c.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e add nsw \u043d\u0435 \u0432\u0435\u0434\u0451\u0442 \u043a \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c\u0443 UB. \u041e\u043d \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0451\u0442 poison, \u0447\u0442\u043e \u0441\u0430\u043c\u043e \u043f\u043e \u0441\u0435\u0431\u0435 \u043d\u0435 \u043e\u043f\u0430\u0441\u043d\u043e. \u041e\u0434\u043d\u0430\u043a\u043e poison \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043e\u0442\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438, \u0438 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u043e\u0442\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0439 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<ul>\n<li>\n<p>%x.plus.y &#8212; poison \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>%sum.updated &#8212; poison, \u0435\u0441\u043b\u0438 %x.plus.y &#8212; poison<\/p>\n<\/li>\n<li>\n<p>%sum.merged &#8212; poison, \u0435\u0441\u043b\u0438 %sum.updated &#8212; poison \u0438 \u043c\u044b \u043f\u0440\u0438\u0448\u043b\u0438 \u0442\u0443\u0434\u0430 \u0438\u0437 \u0431\u043b\u043e\u043a\u0430 %update_sum<\/p>\n<\/li>\n<li>\n<p>%sum &#8212; poison, \u0435\u0441\u043b\u0438 %sum.merged &#8212; poison, \u0438 \u043c\u044b \u043f\u0440\u0438\u0448\u043b\u0438 \u0442\u0443\u0434\u0430 \u0438\u0437 \u0431\u043b\u043e\u043a\u0430 %backedge<\/p>\n<\/li>\n<li>\n<p>ret i32 %sum &#8212; \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 UB, \u0435\u0441\u043b\u0438 %sum &#8212; poison (\u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u0430 \u043a\u0430\u043a noundef)<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c, \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0442\u0443\u0442 \u0441\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 UB, \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e\u0431\u044b \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e:<\/p>\n<ul>\n<li>\n<p>Poison \u0432\u043e\u0437\u043d\u0438\u043a \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f x + y<\/p>\n<\/li>\n<li>\n<p>\u041c\u044b \u043f\u0440\u043e\u0448\u043b\u0438 \u043f\u043e \u043f\u0443\u0442\u0438 check_cond <strong>\u2192<\/strong> update_sum <strong>\u2192 <\/strong>backedge<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 poison \u043c\u043e\u0436\u0435\u0442 \u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c, \u043d\u043e \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e UB \u043d\u0435 \u0431\u0443\u0434\u0435\u0442! \u0418\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u0438 \u0434\u0430\u0451\u0442 \u043f\u043e\u043b\u043d\u043e\u0435 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e add \u0441\u043f\u0435\u043a\u0443\u043b\u044f\u0442\u0438\u0432\u043d\u043e \u0432 \u0431\u043b\u043e\u043a\u0435 entry. \u042d\u0442\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f <a href=\"https:\/\/godbolt.org\/z\/9EfdcGTnW\" rel=\"noopener noreferrer nofollow\">LICM<\/a>.<\/p>\n<p>\u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435, \u0447\u0442\u043e \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 x + y \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f, \u043d\u043e cond() \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 false, \u0442\u043e \u043c\u044b \u043d\u0435 \u043f\u043e\u0439\u0434\u0451\u043c \u0432 \u0431\u043b\u043e\u043a update_sum, \u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043d\u0435 \u043e\u0442\u0440\u0430\u0432\u0438\u043c \u0432\u0441\u044e \u044d\u0442\u0443 \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u0432\u043f\u043b\u043e\u0442\u044c \u0434\u043e return&#8217;\u0430.<\/p>\n<h2>\u0412\u043c\u0435\u0441\u0442\u043e \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f<\/h2>\n<p>\u0422\u0435\u043c\u0430 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f &#8212; \u0431\u043e\u043b\u044c\u0448\u0430\u044f. \u041b\u044e\u0434\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u044e\u0442 \u0432\u0441\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043d\u0438\u043c \u0430\u0441\u043f\u0435\u043a\u0442\u044b &#8212; \u0432 \u043c\u0438\u0440\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e. \u041f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, \u043a\u0430\u043a \u043e\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c &#8212; \u0434\u0435\u0441\u044f\u0442\u043a\u0438. \u042f \u043f\u0440\u0438\u0432\u0451\u043b \u043b\u0438\u0448\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u044b\u0445 \u043f\u0440\u043e\u0441\u0442\u044b\u0445, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u0430\u043c\u0443\u044e \u0441\u0443\u0442\u044c \u044f\u0432\u043b\u0435\u043d\u0438\u044f. \u0412\u044b\u043f\u0438\u0448\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0442\u0435\u0437\u0438\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043b\u044c\u0448\u0435:<\/p>\n<ul>\n<li>\n<p>\u041d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 &#8212; \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u043b\u0438 \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0435\u0441\u0442\u044c UB &#8212; &#171;\u0437\u0430\u043a\u043e\u0440\u0440\u0430\u043f\u0447\u0435\u043d\u0430&#187; \u0432\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435, \u0438 UB \u0432 \u043d\u0435\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438 \u0432 \u0441\u0430\u043c\u044b\u0445 \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0441\u0442\u0430\u0445, \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0430\u043c, \u0433\u0434\u0435 \u044d\u0442\u043e \u0431\u044b \u0431\u044b\u043b\u043e \u043f\u0440\u0438 \u043d\u0430\u0438\u0432\u043d\u043e\u043c \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b;<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u043e\u043f\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0438 \u0432\u0438\u0434\u0430 &#171;\u0442\u0430\u043a\u0430\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442&#187;, \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u044d\u0442\u0438\u0445 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0439, \u0430 \u0435\u0441\u043b\u0438 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0432\u0441\u0451 \u0436\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 &#8212; \u044d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c UB;<\/p>\n<\/li>\n<li>\n<p>\u0412 LLVM \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0438 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 UB. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 poison, \u0438 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435 poison \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u0442 \u043a UB (\u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f).<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/740056\/\"> https:\/\/habr.com\/ru\/articles\/740056\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u042d\u0442\u043e \u0446\u0438\u043a\u043b \u0441\u0442\u0430\u0442\u0435\u0439 \u043e\u0431 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430\u0445 \u0432\u043e\u043e\u0431\u0449\u0435 \u0438 LLVM \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438. \u0421\u043c\u043e\u0442\u0440\u0438 \u0432\u0441\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430:<\/p>\n<ol>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/articles\/735152\/\" rel=\"noopener noreferrer nofollow\">SSA \u0444\u043e\u0440\u043c\u0430<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/articles\/737646\/\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/a><\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/p>\n<\/li>\n<\/ol>\n<p>\u0412\u043e\u043e\u0431\u0449\u0435-\u0442\u043e, \u0442\u0440\u0435\u0442\u044c\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u043b\u0430 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\u0445. \u041d\u043e \u043f\u043e\u043a\u0430 \u044f \u043f\u0440\u0438\u043a\u0438\u0434\u044b\u0432\u0430\u043b \u0435\u0451 \u043f\u043b\u0430\u043d, \u0441\u0442\u0430\u043b\u043e \u044f\u0441\u043d\u043e, \u0447\u0442\u043e \u0431\u0435\u0437 \u043e\u0441\u0432\u0435\u0449\u0435\u043d\u0438\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0430\u0441\u043f\u0435\u043a\u0442\u043e\u0432 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u043e\u0435 \u0438\u0437 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0445 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0439 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u044b\u0439 \u0448\u0430\u0433, \u043f\u0440\u0435\u0436\u0434\u0435, \u0447\u0435\u043c \u043e\u043a\u0443\u043d\u0430\u0442\u044c\u0441\u044f \u0432 \u043e\u043c\u0443\u0442 \u0441 \u0433\u043e\u043b\u043e\u0432\u043e\u0439.<\/p>\n<p>\u041d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u043c\u043d\u043e\u0433\u0438\u0435 \u0441\u043b\u044b\u0448\u0430\u043b\u0438, \u0447\u0442\u043e \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 (undefined behavior, UB) &#8212; \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u044b\u0439 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u0445 \u0431\u0430\u0433\u043e\u0432, \u0438\u043d\u043e\u0433\u0434\u0430 \u043e\u0447\u0435\u043d\u044c \u0437\u0430\u0431\u0430\u0432\u043d\u044b\u0445, \u0438\u043d\u043e\u0433\u0434\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e <a href=\"https:\/\/blog.tchatzigiannakis.com\/undefined-behavior-can-literally-erase-your-hard-disk\/\" rel=\"noopener noreferrer nofollow\">\u0436\u0443\u0442\u043a\u0438\u0445<\/a>. \u0422\u0435\u043c\u0430 \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u043e\u0434\u043d\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u043e\u0441\u0432\u0435\u0449\u0430\u043b\u0430\u0441\u044c \u0438 \u043d\u0430 \u0425\u0430\u0431\u0440\u0435, \u043d\u0430\u0432\u0441\u043a\u0438\u0434\u043a\u0443 <a href=\"https:\/\/habr.com\/ru\/articles\/136283\/\" rel=\"noopener noreferrer nofollow\">\u0440\u0430\u0437<\/a>, <a href=\"https:\/\/habr.com\/ru\/articles\/341048\/\" rel=\"noopener noreferrer nofollow\">\u0434\u0432\u0430<\/a>, <a href=\"https:\/\/habr.com\/ru\/companies\/pvs-studio\/articles\/276657\/\" rel=\"noopener noreferrer nofollow\">\u0442\u0440\u0438 <\/a>(\u0438 \u0434\u0430\u0436\u0435 \u0446\u0435\u043b\u044b\u0439 \u0442\u0435\u0433 \u0435\u0441\u0442\u044c). \u041e\u0434\u043d\u0430\u043a\u043e \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e \u0434\u0430\u043d\u043d\u043e\u0439 \u0442\u0435\u043c\u0435 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u044b \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u0441\u0442\u0440\u0435\u043b\u0438\u0442\u044c \u0441\u0435\u0431\u0435 \u043d\u043e\u0433\u0443, \u0433\u043e\u043b\u043e\u0432\u0443 \u0438\u043b\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0441\u0436\u0435\u0447\u044c \u0441\u0432\u043e\u0439 \u0436\u0451\u0441\u0442\u043a\u0438\u0439 \u0434\u0438\u0441\u043a, \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0432 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043a\u043e\u0434. \u042f \u0436\u0435 \u043d\u0430\u043c\u0435\u0440\u0435\u043d \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0430\u043a\u0446\u0435\u043d\u0442 \u043d\u0430 \u0442\u043e\u043c, \u0437\u0430\u0447\u0435\u043c \u0430\u0432\u0442\u043e\u0440\u044b \u044f\u0437\u044b\u043a\u043e\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b\u0438 \u0432\u0441\u0435\u0439 \u044d\u0442\u043e\u0439 \u043a\u0440\u0430\u0441\u043e\u0442\u044b, \u0438 \u043a\u0430\u043a \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u0435\u0451 \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0437 \u043d\u0435\u0451 \u043f\u0435\u0440\u0444\u043e\u043c\u0430\u043d\u0441. \u0412\u0441\u0451 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u044b\u043c\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0438\u0437 LLVM \u0438 \u043f\u0440\u0438\u0441\u044b\u043f\u0430\u043d\u043e \u0431\u0430\u0439\u043a\u0430\u043c\u0438 \u0438\u0437 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430, \u0442\u0430\u043a \u0447\u0442\u043e \u043d\u0430\u043b\u0438\u0432\u0430\u0439\u0442\u0435 \u0441\u0435\u0431\u0435 \u0447\u0430\u0439, \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0439\u0442\u0435\u0441\u044c \u043f\u043e\u0443\u0434\u043e\u0431\u043d\u0435\u0435, \u0438 \u043f\u043e\u0433\u043d\u0430\u043b\u0438.<\/p>\n<h2>\u041a\u043e\u0440\u043e\u0442\u043a\u043e \u043e \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0435<\/h2>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 undefined behavior, \u0442\u043e \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0434\u043b\u044f \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u043b\u0435\u043d\u0438\u044f. \u041d\u0430\u0447\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0441\u043e \u0441\u0442\u0430\u0442\u044c\u0438 \u0432 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Undefined_behavior\" rel=\"noopener noreferrer nofollow\">\u0412\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u0438<\/a>, \u0430 \u0434\u0430\u043b\u044c\u0448\u0435 \u0433\u0443\u0433\u043b\u0438\u0442\u044c \u043f\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u0430\u043c \u0438 \u043d\u0430\u0441\u043b\u0430\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u0434\u0435\u0441\u044f\u0442\u043a\u0430\u043c\u0438 \u0438\u0441\u0442\u043e\u0440\u0438\u0439 \u043d\u0430 \u0442\u0435\u043c\u0443 &#171;\u044f \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u044e, \u043a\u0430\u043a\u043e\u0433\u043e \u0447\u0451\u0440\u0442\u0430 \u043c\u043e\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0435 \u0442\u0430\u043a, \u043a\u0430\u043a \u043c\u043d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f&#187; \u0438\u043b\u0438 &#171;1001 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0442\u0441\u0442\u0440\u0435\u043b\u0438\u0442\u044c \u0441\u0435\u0431\u0435 \u043d\u043e\u0433\u0443 \u0434\u043b\u044f \u0447\u0430\u0439\u043d\u0438\u043a\u043e\u0432&#187;. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0437\u0430\u0431\u0430\u0432\u043d\u044b, \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0441 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u043e, \u0447\u0442\u043e \u0432 \u044f\u0437\u044b\u043a\u0430\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (\u0438 \u043e\u0441\u043e\u0431\u043e \u044d\u0442\u0438\u043c \u0441\u043b\u0430\u0432\u0435\u043d \u0421++ \u0438 \u0435\u043c\u0443 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435) \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u0444\u0440\u0430\u0437\u044b \u0442\u0438\u043f\u0430<\/p>\n<blockquote>\n<p>When signed integer arithmetic operation overflows (the result does not fit in the result type), the behavior is undefined<\/p>\n<\/blockquote>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u0432\u0441\u0451 \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e: \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c, \u0432\u0430\u043c \u043f\u043e\u0432\u0435\u0437\u0451\u0442, \u0438 \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e \u043c\u043e\u0434\u0443\u043b\u044e <em>2<sup>n<\/sup><\/em>, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u0432\u0435\u0437\u0451\u0442 \u0447\u0443\u0442\u044c \u043c\u0435\u043d\u044c\u0448\u0435, \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c 0 \u0438\u043b\u0438 SINT_MAX, \u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c, \u0432\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0443\u0434\u0430\u043b\u0438\u0442 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433, \u0430 \u0436\u0451\u0441\u0442\u043a\u0438\u0439 \u0434\u0438\u0441\u043a \u0441\u0433\u043e\u0440\u0438\u0442 \u0441\u0438\u043d\u0438\u043c \u043f\u043b\u0430\u043c\u0435\u043d\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0432\u044b \u0441\u043b\u043e\u0436\u0438\u043b\u0438 \u0434\u0432\u0430 \u0447\u0438\u0441\u043b\u0430.<\/p>\n<p>\u0412\u043e\u0442 \u043a\u0440\u0430\u0442\u043a\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u0441 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c:<\/p>\n<ul>\n<li>\n<p>\u041f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u043a\u043e\u0432\u043e\u0439 \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u043a\u0438<\/p>\n<\/li>\n<li>\n<p>\u0414\u0435\u043b\u0435\u043d\u0438\u0435 (\u0438\u043b\u0438 \u0432\u0437\u044f\u0442\u0438\u0435 \u043e\u0441\u0442\u0430\u0442\u043a\u0430) \u043d\u0430 0<\/p>\n<\/li>\n<li>\n<p>\u0420\u0430\u0437\u044b\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 (\u0442.\u0435. \u0447\u0442\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c) nullptr \u0438\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u043d\u0435\u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u0430)<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p>\u0411\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0431\u0435\u0437 \u0441\u0430\u0439\u0434-\u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u0413\u043e\u043d\u043a\u0430 \u043f\u0440\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0435\u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>\u0438 \u0442.\u043f.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0411\u043b\u0430\u0433\u0438\u043c\u0438 \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u0438\u044f\u043c\u0438<\/h3>\n<p>\u0412 \u043d\u0430\u0448\u0435\u0439 \u0441\u0440\u0435\u0434\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u043c &#171;demon optimizer&#187; &#8212; \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0439 \u0433\u0438\u043f\u043e\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0432\u043e\u0434, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043c\u043e\u0436\u0435\u0442 \u0441\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f UB, \u0438 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u0442\u0430\u0440\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u043d\u043e\u0441\u0438\u0442\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0439 \u0443\u0440\u043e\u043d (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c &#171;rm -rf \/&#187; \u0432\u0435\u0437\u0434\u0435, \u043a\u043e\u0433\u0434\u0430 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0445\u043e\u0442\u044c \u043a\u0430\u043a\u0430\u044f-\u0442\u043e \u0437\u043d\u0430\u043a\u043e\u0432\u0430\u044f \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u043a\u0430). \u041f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0441\u0442\u0430\u0432\u0438\u0442 \u0441\u0435\u0431\u0435 \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u0440\u0438 \u043c\u0430\u043b\u0435\u0439\u0448\u0435\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u0430\u0433\u0430\u0434\u0438\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0443. \u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432\u0441\u0451 \u0445\u0443\u0436\u0435: \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0433\u0430\u0434\u0438\u0442\u044c \u0435\u043c\u0443, \u0438\u0441\u043a\u0440\u0435\u043d\u043d\u0435 \u0441\u0442\u0430\u0440\u0430\u044f\u0441\u044c \u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043e\u0431\u0440\u043e.<\/p>\n<p>\u041d\u0435 \u0442\u0430\u043a \u0434\u0430\u0432\u043d\u043e \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430\u0445 \u0434\u0438\u0432\u0438\u043b\u0438\u0441\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438: \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 clang \u0443\u043c\u0443\u0434\u0440\u0438\u043b\u0441\u044f \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e never_called<\/p>\n<pre><code class=\"cpp\">#include &lt;iostream>  int main() {     int cnt = 0;     while (cnt++ != -1) {}     return 0; }  void never_called() {     std::cout &lt;&lt; \"You are screwed\" &lt;&lt; std::endl; } <\/code><\/pre>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u043f\u0440\u0438\u043d\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c &#171;rm -rf \/&#187;, \u0438 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f. \u041f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043d\u0435\u0442\u0440\u0443\u0434\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u0435\u0441\u043b\u0438 \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0432 <a href=\"https:\/\/godbolt.org\/z\/GM87qhnsz\" rel=\"noopener noreferrer nofollow\">godbolt<\/a>: <\/p>\n<pre><code class=\"assembly\">main:                                   # @main never_called():                      # @never_called()         push    rbx         mov     rbx, qword ptr [rip + std::cout@GOTPCREL]         lea     rsi, [rip + .L.str]         mov     edx, 15         mov     rdi, rbx         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::__ostream_insert&lt;char, std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;, char const*, long)@PLT         mov     rax, qword ptr [rbx]         mov     rax, qword ptr [rax - 24]         mov     rbx, qword ptr [rbx + rax + 240]         test    rbx, rbx         je      .LBB1_5         cmp     byte ptr [rbx + 56], 0         je      .LBB1_3         movzx   eax, byte ptr [rbx + 67]         jmp     .LBB1_4 .LBB1_3:         mov     rdi, rbx         call    std::ctype&lt;char>::_M_widen_init() const@PLT         mov     rax, qword ptr [rbx]         mov     rdi, rbx         mov     esi, 10         call    qword ptr [rax + 48] .LBB1_4:         movsx   esi, al         mov     rdi, qword ptr [rip + std::cout@GOTPCREL]         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >::put(char)@PLT         mov     rdi, rax         pop     rbx         jmp     std::basic_ostream&lt;char, std::char_traits&lt;char> >::flush()@PLT               # TAILCALL .LBB1_5:         call    std::__throw_bad_cast()@PLT .L.str:         .asciz  \"You are screwed\"<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u043f\u0440\u044f\u043c\u043e \u0437\u0430 \u043c\u0435\u0442\u043a\u043e\u0439 main \u0438\u0434\u0451\u0442 \u043c\u0435\u0442\u043a\u0430 \u043d\u0430\u0447\u0430\u043b\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 never_called, \u0438 \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0435\u0439 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u043f\u043e\u0439\u0434\u0451\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0435\u0433\u043e \u0434\u0430\u043b\u044c\u0448\u0435 \u0441\u043f\u043b\u043e\u0448\u043d\u044f\u043a\u043e\u043c. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0441\u0445\u0435\u043c\u0443 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u044d\u0442\u043e <a href=\"https:\/\/godbolt.org\/z\/o65ro3KMa\" rel=\"noopener noreferrer nofollow\">\u0441\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c<\/a>.<\/p>\n<ol>\n<li>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0443 \u0421++, \u0437\u043d\u0430\u043a\u043e\u0432\u043e\u0435 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 &#8212; \u044d\u0442\u043e UB. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e cnt, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0431\u044b\u043b\u043e \u0440\u0430\u0432\u043d\u043e \u043d\u0443\u043b\u044e \u0438 \u0448\u043b\u043e \u0432\u0432\u0435\u0440\u0445, \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c. \u041e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043e\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438, \u043d\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e UB, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u043d\u0430 \u044d\u0442\u043e \u043d\u0430\u043f\u043b\u0435\u0432\u0430\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 &#171;cnt != -1&#187; \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0432 &#171;true&#187;, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 cnt &#8212; \u043d\u0435\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435, \u0430 -1 &#8212; \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435, \u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u043e\u043d\u0438 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0440\u0430\u0432\u043d\u044b.<\/p>\n<\/li>\n<li>\n<p>\u0426\u0438\u043a\u043b while (true) {} &#8212; \u044d\u0442\u043e \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0431\u0435\u0437 \u0441\u0430\u0439\u0434-\u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432, \u0442\u043e \u0435\u0441\u0442\u044c UB. \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0441\u0447\u0438\u0442\u0430\u0435\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u0441\u044e\u0434\u0430 \u043f\u0440\u0438\u0448\u043b\u0438, \u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0451 \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440&#8230; \u041d\u0438\u0447\u0435\u0433\u043e. \u0412\u043e\u043e\u0431\u0449\u0435. \u041c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0446\u0438\u043a\u043b \u0438 \u0432\u0435\u0441\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 return&#8217;\u043e\u043c.<\/p>\n<\/li>\n<\/ol>\n<p>\u041e\u0431\u0430 \u0440\u0430\u0437\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0441\u0434\u0435\u043b\u0430\u043b \u043d\u0435\u0447\u0442\u043e \u0443\u043c\u043d\u043e\u0435 \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435. \u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u0447\u0438\u0441\u0435\u043b \u0438 \u0437\u0430\u043c\u0435\u043d\u0430 \u0435\u0433\u043e \u043d\u0430 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 &#8212; \u044d\u0442\u043e \u0431\u043b\u0430\u0433\u043e. \u0412\u0430\u043c \u043d\u0435 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u043d\u0430 \u044d\u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043d\u044b\u0439 \u0442\u0430\u043a\u0442. \u0427\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430, \u0442\u043e \u0442\u0443\u0442 \u043e \u0431\u043b\u0430\u0433\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043f\u043e\u0440\u0438\u0442\u044c, \u043d\u043e \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u043a\u0442\u043e-\u0442\u043e \u0431\u044b \u043f\u043e\u0441\u043b\u0435 while (true) {} \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0446\u0435\u043b\u0443\u044e \u0433\u043e\u0440\u0443 \u043a\u043e\u0434\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440. \u043f\u043e \u043e\u0448\u0438\u0431\u043a\u0435. \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u0431\u044b \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0435\u0451 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0442\u0430\u0449\u0438\u0442\u044c \u0434\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u043a\u043e\u043d\u0446\u0430, \u0442\u0440\u0430\u0442\u044f \u043d\u0430 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0441\u0432\u043e\u0451 \u0432\u0440\u0435\u043c\u044f, \u043f\u0440\u0438\u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f. \u0423\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u044d\u0442\u043e, \u0435\u0433\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 &#8212; \u044d\u0442\u043e \u0442\u043e\u0436\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435 \u0434\u043b\u044f \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u0441\u0430\u043c\u043e\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u0412\u044b\u0445\u043e\u0434\u0438\u0442, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0431\u0440\u043e, \u0430 \u0441\u0434\u0435\u043b\u0430\u043b \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u043e\u043f\u0430\u0441\u043d\u0443\u044e \u0435\u0440\u0443\u043d\u0434\u0443.<\/p>\n<h2>UB &#8212; \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/h2>\n<p>\u041c\u043d\u043e\u0433\u0438\u0435 \u0437\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c: \u043d\u0443 \u0445\u043e\u0440\u043e\u0448\u043e, \u0440\u0430\u0437 UB &#8212; \u044d\u0442\u043e, \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e, \u043e\u0447\u0435\u043d\u044c \u0441\u0442\u0440\u0430\u0448\u043d\u043e \u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0443\u0436\u0430\u0441\u043d\u044b\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c warning \u0432 \u0442\u0435\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u0445, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043a\u043e\u0434? \u041c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0446\u0438\u0439 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<p>\u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u044f\u0437\u044b\u043a\u0430\u0445 \u0432\u0440\u043e\u0434\u0435 \u0421++ \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043c\u043e\u0433\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 <strong>\u043f\u0440\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445<\/strong>. \u0414\u0435\u043b\u0435\u043d\u0438\u0435 \u0432\u0435\u0434\u0451\u0442 \u043a UB <strong>\u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438<\/strong> \u0437\u043d\u0430\u043c\u0435\u043d\u0430\u0442\u0435\u043b\u044c \u0440\u0430\u0432\u0435\u043d \u043d\u0443\u043b\u044e. \u0412\u0440\u044f\u0434 \u043b\u0438 \u043a\u0442\u043e-\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0442\u0430\u043c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 0 (\u0442\u0430\u043a\u043e\u0435 \u0431\u044b\u0432\u0430\u0435\u0442, \u043d\u043e \u044d\u0442\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u0443\u0447\u0435\u0431\u043d\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430, \u0430 \u043d\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438), \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e &lt;\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 1> \/ &lt;\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 2>, \u0438 \u0447\u0435\u043c\u0443 \u0440\u0430\u0432\u043d\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 2 &#8212; \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c \u043c\u043e\u0436\u0435\u0442 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0446\u0438\u043a\u043b while (true), \u043d\u043e \u0438 \u0446\u0438\u043a\u043b \u0441 \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u043c, \u043d\u0435 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c\u044b\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u043e\u0435, \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u0441\u0442\u0438\u043d\u043d\u043e. \u0422\u0430\u043a\u0436\u0435 \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u0435 x + y \u043c\u043e\u0436\u0435\u0442 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 \u043e\u0434\u043d\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 (\u0438 \u043f\u043e\u0440\u043e\u0434\u0438\u0442\u044c UB), \u0430 \u043c\u043e\u0436\u0435\u0442 \u0438 \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0438\u0442\u044c\u0441\u044f.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u0438 \u0438\u043c\u0435\u0442\u044c \u0442\u0430\u043a\u043e\u0439 warning, \u043e\u043d \u0431\u044b \u0432\u044b\u043b\u0435\u0442\u0430\u043b \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u0432\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u041e\u0447\u0435\u043d\u044c \u0440\u0435\u0434\u043a\u043e \u043a\u043e\u0433\u0434\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u043c\u043e\u0436\u043d\u043e \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0438 \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043f\u0440\u0435\u0434\u043c\u0435\u0442 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f\/\u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043d\u043e\u0439 \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0441\u0442\u0438\/\u043d\u0443\u043b\u0451\u0432\u043e\u0441\u0442\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u0421\u0442\u0440\u043e\u0433\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442, constexpr&#8217;\u043e\u0432 \u0438 \u0438\u0445 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0445, \u0434\u0430 \u0438 \u0442\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 (\u0438\u043d\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u043e\u043b\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0437\u0430\u043d\u0438\u043c\u0430\u043b\u0441\u044f \u044d\u0442\u0438\u043c \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435). \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0442\u043e, \u0431\u0443\u0434\u0435\u0442 \u043b\u0438 \u0432\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u043d\u0435\u0442, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0445\u043e\u0434\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0451\u043c \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"cpp\">int foo(int x) {   int sum = 0;   for (int i = 0; i &lt; 1000; i++)     if (cond(i))       sum += i \/ x;   return sum; }<\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0438 \u0434\u0432\u0443\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439:<\/p>\n<ul>\n<li>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u0441 x = 0<\/p>\n<\/li>\n<li>\n<p>cond(i) \u0432\u0435\u0440\u043d\u0451\u0442 true \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u0440\u0430\u0437<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 0, \u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0430\u0432\u043e \u0437\u0430\u043a\u0440\u0430\u0448\u0438\u0442\u044c\u0441\u044f, \u043f\u043e\u0432\u0438\u0441\u043d\u0443\u0442\u044c, \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u043d\u0438\u0431\u0443\u0434\u044c \u0435\u0440\u0443\u043d\u0434\u0443 \u0438 \u0442.\u0434. \u041e\u0434\u043d\u0430\u043a\u043e \u0441\u0430\u043c \u0444\u0430\u043a\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u0432 \u043d\u0435\u0439 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0435\u0449\u0451 \u043d\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 UB.<\/p>\n<h2>\u041d\u0435\u0438\u0437\u0431\u0435\u0436\u043d\u043e\u0435 UB \u043f\u0443\u0442\u0435\u0448\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/h2>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u0440\u0438 \u043a\u0430\u043a\u043e\u043c-\u0442\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442, \u0442\u043e \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, <strong>\u0433\u0434\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u0438 \u043a\u043e\u0433\u0434\u0430<\/strong> \u043e\u043d\u043e \u043f\u0440\u043e\u044f\u0432\u0438\u0442\u0441\u044f. \u041f\u0440\u0438\u0432\u0435\u0434\u0451\u043c \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"cpp\">void foo(int *ptr) {   printf(\"Before the loop\\n\");   for (int i = 0; i &lt; 1000; i++) {     printf(\"Before check\\n\");     if (i == 17)       *ptr = 1;     printf(\"After check\\n\");   }   printf(\"After the loop the loop\\n\"); }<\/code><\/pre>\n<p>\u0427\u0435\u043b\u043e\u0432\u0435\u043a\u0443 \u043d\u0430\u0438\u0432\u043d\u043e\u043c\u0443 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0441 ptr = nullptr \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c:<\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0442\u043e\u0447\u043d\u043e \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 &#171;Before the loop&#187;;<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0442\u043e\u0447\u043d\u043e 17 \u0440\u0430\u0437 \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u043f\u0430\u0440\u0443 &#171;Before check&#187;\/&#187;After check&#187;;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0442\u043e\u043c \u0434\u043b\u044f i = 17 \u0435\u0449\u0451 \u0440\u0430\u0437 \u0442\u043e\u0447\u043d\u043e \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442\u0441\u044f &#171;Before check&#187;, \u0430 \u0432\u043e\u0442 \u0434\u0430\u043b\u044c\u0448\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438 \u043a\u0440\u0430\u0448\/\u0437\u0430\u0432\u0438\u0441\u0430\u043d\u0438\u0435\/\u043b\u0438\u0431\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u0442\u0440\u0430\u043d\u043d\u043e\u0435.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u043e\u0435 \u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442, \u0435\u0441\u043b\u0438 \u0434\u0443\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0440\u043e\u0432\u043d\u043e \u0442\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438, \u0438 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0436\u0435. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u044b \u0442\u0430\u043a \u043d\u0435 \u0434\u0435\u043b\u0430\u044e\u0442. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u043f\u043e\u043b\u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0430\u0432\u043e \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0439:<\/p>\n<ul>\n<li>\n<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435 i == 17 \u0441\u0442\u0430\u043d\u0435\u0442 \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u043c (\u043f\u0440\u0438\u0447\u0451\u043c<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-348781","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/348781","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=348781"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/348781\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=348781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=348781"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=348781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}