diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2023-09-22 01:47:29 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-21 19:47:29 +0200 |
commit | a1b6fa9420db09f2660ad5919d2b96673f324f8f (patch) | |
tree | 3f73d80d96d65009ac228c382815eb57e7714345 | |
parent | c75cbdde7034f10979b61687733f253261ecffec (diff) | |
download | Nim-a1b6fa9420db09f2660ad5919d2b96673f324f8f.tar.gz |
fixes #22246; generate __builtin_unreachable hints for case defaults (#22737)
fixes #22246 resurrects #22350
-rw-r--r-- | compiler/ccgstmts.nim | 7 | ||||
-rw-r--r-- | compiler/extccomp.nim | 5 |
2 files changed, 8 insertions, 4 deletions
diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index de358e242..c212ca0cb 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -966,8 +966,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 be0bd36db..75d462b06 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: |