diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2023-07-31 22:02:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-31 16:02:52 +0200 |
commit | b56df5c07f7dc9ac9d718ca47c10b0683a9b916f (patch) | |
tree | 6b2a71cee0689bd38e2359cfaf4d0251bf548980 | |
parent | 569ccc50ff9f4f48272a00c82556a495c0f721b9 (diff) | |
download | Nim-b56df5c07f7dc9ac9d718ca47c10b0683a9b916f.tar.gz |
fixes #22246; generate `__builtin_unreachable` hints for case defaults (#22350)
* fixes #22246; generate `__builtin_unreachable` hints * use elif * indentation * fixes holy enums in sim
-rw-r--r-- | compiler/ccgstmts.nim | 7 | ||||
-rw-r--r-- | compiler/extccomp.nim | 5 | ||||
-rw-r--r-- | testament/important_packages.nim | 2 |
3 files changed, 9 insertions, 5 deletions
diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index 319738981..448a437db 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -971,8 +971,11 @@ proc genOrdinalCase(p: BProc, n: PNode, d: var TLoc) = hasDefault = true exprBlock(p, branch.lastSon, d) lineF(p, cpsStmts, "break;$n", []) - if (hasAssume in CC[p.config.cCompiler].props) and not hasDefault: - lineF(p, cpsStmts, "default: __assume(0);$n", []) + if not hasDefault: + if hasBuiltinUnreachable in CC[p.config.cCompiler].props: + lineF(p, cpsStmts, "default: __builtin_unreachable();$n", []) + elif hasAssume in CC[p.config.cCompiler].props: + lineF(p, cpsStmts, "default: __assume(0);$n", []) lineF(p, cpsStmts, "}$n", []) if lend != "": fixLabel(p, lend) diff --git a/compiler/extccomp.nim b/compiler/extccomp.nim index 391f158f0..3605d1dd2 100644 --- a/compiler/extccomp.nim +++ b/compiler/extccomp.nim @@ -33,6 +33,7 @@ type hasGnuAsm, # CC's asm uses the absurd GNU assembler syntax hasDeclspec, # CC has __declspec(X) hasAttribute, # CC has __attribute__((X)) + hasBuiltinUnreachable # CC has __builtin_unreachable TInfoCCProps* = set[TInfoCCProp] TInfoCC* = tuple[ name: string, # the short name of the compiler @@ -95,7 +96,7 @@ compiler gcc: produceAsm: gnuAsmListing, cppXsupport: "-std=gnu++17 -funsigned-char", props: {hasSwitchRange, hasComputedGoto, hasCpp, hasGcGuard, hasGnuAsm, - hasAttribute}) + hasAttribute, hasBuiltinUnreachable}) # GNU C and C++ Compiler compiler nintendoSwitchGCC: @@ -122,7 +123,7 @@ compiler nintendoSwitchGCC: produceAsm: gnuAsmListing, cppXsupport: "-std=gnu++17 -funsigned-char", props: {hasSwitchRange, hasComputedGoto, hasCpp, hasGcGuard, hasGnuAsm, - hasAttribute}) + hasAttribute, hasBuiltinUnreachable}) # LLVM Frontend for GCC/G++ compiler llvmGcc: diff --git a/testament/important_packages.nim b/testament/important_packages.nim index 9016a0d3d..c632256ef 100644 --- a/testament/important_packages.nim +++ b/testament/important_packages.nim @@ -146,7 +146,7 @@ pkg "rosencrantz", "nim c -o:rsncntz -r rosencrantz.nim" pkg "sdl1", "nim c -r src/sdl.nim" pkg "sdl2_nim", "nim c -r sdl2/sdl.nim" pkg "sigv4", "nim c --gc:arc -r sigv4.nim", "https://github.com/disruptek/sigv4" -pkg "sim" +pkg "sim", url = "https://github.com/nim-lang/sim.nim" pkg "smtp", "nimble compileExample" pkg "snip", "nimble test", "https://github.com/genotrance/snip" pkg "ssostrings" |