How about being build-system defined? As in, let me specify a &quot;target behavior profile&quot; as a switch to the compiler, which would be shorthand for a bunch of switches that define specific results for specific undefined behaviors: &quot;-foverflow=checked&quot; (add explicit checks) vs. &quot;-foverflow=wrap&quot; (do what most ISAs already do, but even on target ISAs that <i>don&#x27;t</i> do that) vs. &quot;-foverflow=clip&quot; (do something weird that no target ISA does, like making short 65535 + 1 = 65535.)<p>I would expect that a single-pass compiler like gcc would look at the toolchain&#x27;s target ISA, compare it to these switches, and then generate extra shim code to adapt any cases of target-arch-does-X into code-does-Y-on-X, while letting do-X-on-X just translate directly. Basically the same way floating-point code gets compiled: architectures that support it get it, architectures that don&#x27;t get a shim.<p>Meanwhile, a two-stage compiler with an intermediate representation, like clang, should generate IR with granular types specifying the chosen behavioral semantics on each operation. The second step in such a toolchain becomes much more formalized: rather than taking code that can contain undefined behavior as input, and then &quot;defining&quot; it during translation in some random heuristic manner, you just take code that already <i>specifies</i> the behavior it wants in full, and then attempt to generate target-arch code that does whatever it says in the most efficient manner possible <i>while not breaking any of the guarantees the IR asks for</i>. In other words, your code-generation stage becomes a static recompiler, like this one[1] for the NES ISA.<p>And you can always specify a switch at code-gen time that will error out the compilation if you&#x27;ve done something that has caused shims to be inserted. Or even a switch to throw away the behavioral semantics the IR asks for and substitute your own, like happens in most performance-focused emulator software.<p>[1] <a href="http:&#x2F;&#x2F;andrewkelley.me&#x2F;post&#x2F;jamulator.html" rel="nofollow">http:&#x2F;&#x2F;andrewkelley.me&#x2F;post&#x2F;jamulator.html</a>