diff options
author | def <dennis@felsin9.de> | 2015-05-04 23:59:53 +0200 |
---|---|---|
committer | def <dennis@felsin9.de> | 2015-05-05 00:02:09 +0200 |
commit | a9fe618756304a765006a54b3f8f8b1cdae0ffb9 (patch) | |
tree | fa4616d7b29ac6b3be49f1895bea4e2e4a46a81b | |
parent | 3bef848a2cf60008f23e72571d7c20c0eb9fd728 (diff) | |
download | Nim-a9fe618756304a765006a54b3f8f8b1cdae0ffb9.tar.gz |
Pass noReturn pragma to C code.
With GCC and Clang this generates __attribute__((noreturn)) in the function declaration. (both tested) With VCC __declspec(noreturn) is used.
-rw-r--r-- | compiler/cgen.nim | 5 | ||||
-rw-r--r-- | compiler/extccomp.nim | 8 |
2 files changed, 10 insertions, 3 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim index da9c6f653..4743e4576 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -676,6 +676,9 @@ proc genProcAux(m: BModule, prc: PSym) = closureSetup(p, prc) genStmts(p, prc.getBody) # modifies p.locals, p.init, etc. var generatedProc: Rope + if sfNoReturn in prc.flags: + if hasNoreturnDeclspec in extccomp.CC[extccomp.cCompiler].props: + header = "__declspec(noreturn) " & header if sfPure in prc.flags: if hasNakedDeclspec in extccomp.CC[extccomp.cCompiler].props: header = "__declspec(naked) " & header @@ -722,6 +725,8 @@ proc genProcPrototype(m: BModule, sym: PSym) = header = "extern \"C\" " & header if sfPure in sym.flags and hasNakedAttribute in CC[cCompiler].props: header.add(" __attribute__((naked))") + if sfNoReturn in sym.flags and hasNoreturnAttribute in CC[cCompiler].props: + header.add(" __attribute__((noreturn))") add(m.s[cfsProcHeaders], rfmt(nil, "$1;$n", header)) proc genProcNoForward(m: BModule, prc: PSym) = diff --git a/compiler/extccomp.nim b/compiler/extccomp.nim index 26f0318ee..1bf4eb757 100644 --- a/compiler/extccomp.nim +++ b/compiler/extccomp.nim @@ -27,7 +27,9 @@ type hasGcGuard, # CC supports GC_GUARD to keep stack roots hasGnuAsm, # CC's asm uses the absurd GNU assembler syntax hasNakedDeclspec, # CC has __declspec(naked) - hasNakedAttribute # CC has __attribute__((naked)) + hasNakedAttribute, # CC has __attribute__((naked)) + hasNoreturnAttribute, # CC has __attribute__((noreturn)) + hasNoreturnDeclspec # CC has __declspec(noreturn) TInfoCCProps* = set[TInfoCCProp] TInfoCC* = tuple[ name: string, # the short name of the compiler @@ -85,7 +87,7 @@ compiler gcc: structStmtFmt: "$1 $3 $2 ", # struct|union [packed] $name packedPragma: "__attribute__((__packed__))", props: {hasSwitchRange, hasComputedGoto, hasCpp, hasGcGuard, hasGnuAsm, - hasNakedAttribute}) + hasNakedAttribute, hasNoreturnAttribute}) # LLVM Frontend for GCC/G++ compiler llvmGcc: @@ -127,7 +129,7 @@ compiler vcc: asmStmtFrmt: "__asm{$n$1$n}$n", structStmtFmt: "$3$n$1 $2", packedPragma: "#pragma pack(1)", - props: {hasCpp, hasAssume, hasNakedDeclspec}) + props: {hasCpp, hasAssume, hasNakedDeclspec, hasNoreturnDeclspec}) # Intel C/C++ Compiler compiler icl: |