added a switch -d:nimEmulateOverflowChecks for broken or old GCC versions (#13692)
This commit is contained in:
parent
b5c9881a30
commit
ba6e7c6365
4 changed files with 13 additions and 5 deletions
|
|
@ -3,6 +3,12 @@
|
||||||
|
|
||||||
## Changes affecting backwards compatibility
|
## Changes affecting backwards compatibility
|
||||||
|
|
||||||
|
- The Nim compiler now implements a faster way to detect overflows based
|
||||||
|
on GCC's `__builtin_sadd_overflow` family of functions. (Clang also
|
||||||
|
supports these). Some versions of GCC lack this feature and unfortunately
|
||||||
|
we cannot detect this case reliably. So if you get compilation errors like
|
||||||
|
"undefined reference to '__builtin_saddll_overflow'" compile your programs
|
||||||
|
with `-d:nimEmulateOverflowChecks`.
|
||||||
|
|
||||||
|
|
||||||
### Breaking changes in the standard library
|
### Breaking changes in the standard library
|
||||||
|
|
|
||||||
|
|
@ -1234,13 +1234,15 @@ proc genVarPrototype(m: BModule, n: PNode) =
|
||||||
"\t$1 = ($2*)hcrGetGlobal($3, \"$1\");$n", [sym.loc.r,
|
"\t$1 = ($2*)hcrGetGlobal($3, \"$1\");$n", [sym.loc.r,
|
||||||
getTypeDesc(m, sym.loc.t), getModuleDllPath(m, sym)])
|
getTypeDesc(m, sym.loc.t), getModuleDllPath(m, sym)])
|
||||||
|
|
||||||
proc addIntTypes(result: var Rope; conf: ConfigRef) {.inline.} =
|
proc addNimDefines(result: var Rope; conf: ConfigRef) {.inline.} =
|
||||||
result.addf("#define NIM_INTBITS $1\L", [
|
result.addf("#define NIM_INTBITS $1\L", [
|
||||||
platform.CPU[conf.target.targetCPU].intSize.rope])
|
platform.CPU[conf.target.targetCPU].intSize.rope])
|
||||||
if conf.cppCustomNamespace.len > 0:
|
if conf.cppCustomNamespace.len > 0:
|
||||||
result.add("#define USE_NIM_NAMESPACE ")
|
result.add("#define USE_NIM_NAMESPACE ")
|
||||||
result.add(conf.cppCustomNamespace)
|
result.add(conf.cppCustomNamespace)
|
||||||
result.add("\L")
|
result.add("\L")
|
||||||
|
if conf.isDefined("nimEmulateOverflowChecks"):
|
||||||
|
result.add("#define NIM_EmulateOverflowChecks\L")
|
||||||
|
|
||||||
proc getCopyright(conf: ConfigRef; cfile: Cfile): Rope =
|
proc getCopyright(conf: ConfigRef; cfile: Cfile): Rope =
|
||||||
if optCompileOnly in conf.globalOptions:
|
if optCompileOnly in conf.globalOptions:
|
||||||
|
|
@ -1263,7 +1265,7 @@ proc getCopyright(conf: ConfigRef; cfile: Cfile): Rope =
|
||||||
proc getFileHeader(conf: ConfigRef; cfile: Cfile): Rope =
|
proc getFileHeader(conf: ConfigRef; cfile: Cfile): Rope =
|
||||||
result = getCopyright(conf, cfile)
|
result = getCopyright(conf, cfile)
|
||||||
if conf.hcrOn: result.add("#define NIM_HOT_CODE_RELOADING\L")
|
if conf.hcrOn: result.add("#define NIM_HOT_CODE_RELOADING\L")
|
||||||
addIntTypes(result, conf)
|
addNimDefines(result, conf)
|
||||||
|
|
||||||
proc getSomeNameForModule(m: PSym): Rope =
|
proc getSomeNameForModule(m: PSym): Rope =
|
||||||
assert m.kind == skModule
|
assert m.kind == skModule
|
||||||
|
|
@ -1825,7 +1827,7 @@ proc writeHeader(m: BModule) =
|
||||||
|
|
||||||
var guard = "__$1__" % [m.filename.splitFile.name.rope]
|
var guard = "__$1__" % [m.filename.splitFile.name.rope]
|
||||||
result.addf("#ifndef $1$n#define $1$n", [guard])
|
result.addf("#ifndef $1$n#define $1$n", [guard])
|
||||||
addIntTypes(result, m.config)
|
addNimDefines(result, m.config)
|
||||||
generateHeaders(m)
|
generateHeaders(m)
|
||||||
|
|
||||||
generateThreadLocalStorage(m)
|
generateThreadLocalStorage(m)
|
||||||
|
|
|
||||||
|
|
@ -549,7 +549,7 @@ typedef int Nim_and_C_compiler_disagree_on_target_architecture[sizeof(NI) == siz
|
||||||
#define nimModInt(a, b, res) (((*res) = (a) % (b)), 0)
|
#define nimModInt(a, b, res) (((*res) = (a) % (b)), 0)
|
||||||
#define nimModInt64(a, b, res) (((*res) = (a) % (b)), 0)
|
#define nimModInt64(a, b, res) (((*res) = (a) % (b)), 0)
|
||||||
|
|
||||||
#if !defined(_MSC_VER)
|
#if !defined(_MSC_VER) && !defined(NIM_EmulateOverflowChecks)
|
||||||
/* these exist because we cannot have .compilerProcs that are importc'ed
|
/* these exist because we cannot have .compilerProcs that are importc'ed
|
||||||
by a different name */
|
by a different name */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ proc raiseDivByZero {.compilerproc, noinline.} =
|
||||||
|
|
||||||
{.pragma: nimbaseH, importc, nodecl, noSideEffect, compilerproc.}
|
{.pragma: nimbaseH, importc, nodecl, noSideEffect, compilerproc.}
|
||||||
|
|
||||||
when defined(gcc) or defined(clang):
|
when (defined(gcc) or defined(clang)) and not defined(nimEmulateOverflowChecks):
|
||||||
# take the #define from nimbase.h
|
# take the #define from nimbase.h
|
||||||
|
|
||||||
proc nimAddInt(a, b: int, res: ptr int): bool {.nimbaseH.}
|
proc nimAddInt(a, b: int, res: ptr int): bool {.nimbaseH.}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue