Skip to content

Commit 6bb6961

Browse files
committed
add --warning:BackendWarning:off to suppress backend warnings if ever needed, as alternative to --passc:-w (so that it remains compiler/OS platform independent)
1 parent fc8dc00 commit 6bb6961

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

compiler/commands.nim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,15 @@ proc expectNoArg(conf: ConfigRef; switch, arg: string, pass: TCmdLinePass, info:
173173
if arg != "":
174174
localError(conf, info, "invalid argument for command line option: '$1'" % addPrefix(switch))
175175

176+
proc handleSpecialNotes(conf: ConfigRef, pass: TCmdLinePass, note: TNoteKind) =
177+
## some notes require special handling so that cmdline flags overrides work
178+
## as expected.
179+
case note
180+
of warnBackendWarning:
181+
if pass in {passCmd2, passPP}:
182+
extccomp.addCompileOptionCmd(conf, warningsOff, isRemove = conf.hasWarn(note))
183+
else: discard
184+
176185
proc processSpecificNote*(arg: string, state: TSpecialWord, pass: TCmdLinePass,
177186
info: TLineInfo; orig: string; conf: ConfigRef) =
178187
var id = "" # arg = key:val or [key]:val; with val=on|off
@@ -214,6 +223,7 @@ proc processSpecificNote*(arg: string, state: TSpecialWord, pass: TCmdLinePass,
214223
excl(conf.notes, n)
215224
excl(conf.mainPackageNotes, n)
216225
excl(conf.foreignPackageNotes, n)
226+
handleSpecialNotes(conf, pass, n)
217227

218228
proc processCompile(conf: ConfigRef; filename: string) =
219229
var found = findFile(conf, filename)

compiler/extccomp.nim

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ template compiler(name, settings: untyped): untyped =
6161

6262
const
6363
gnuAsmListing = "-Wa,-acdl=$asmfile -g -fverbose-asm -masm=intel"
64+
warningsOff* = "-w" # if needed, can be compiler specific
6465

6566
# GNU C and C++ Compiler
6667
compiler gcc:
@@ -448,8 +449,12 @@ proc addCompileOption*(conf: ConfigRef; option: string) =
448449
proc addLinkOptionCmd*(conf: ConfigRef; option: string) =
449450
addOpt(conf.linkOptionsCmd, option)
450451

451-
proc addCompileOptionCmd*(conf: ConfigRef; option: string) =
452-
conf.compileOptionsCmd.add(option)
452+
proc addCompileOptionCmd*(conf: ConfigRef; option: string, isRemove = false) =
453+
if isRemove:
454+
if (var index = conf.compileOptionsCmd.find(option); index >= 0):
455+
conf.compileOptionsCmd.delete(index)
456+
else:
457+
conf.compileOptionsCmd.add(option)
453458

454459
proc initVars*(conf: ConfigRef) =
455460
# we need to define the symbol here, because ``CC`` may have never been set!

compiler/lineinfos.nim

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const
1717

1818
type
1919
TMsgKind* = enum
20+
# errors
2021
errUnknown, errInternal, errIllFormedAstX, errCannotOpenFile,
2122
errXExpected,
2223
errGridTableNotImplemented,
@@ -25,6 +26,7 @@ type
2526
errInvalidDirectiveX,
2627
errGenerated,
2728
errUser,
29+
# warnings
2830
warnCannotOpenFile,
2931
warnOctalEscape, warnXIsNeverRead, warnXmightNotBeenInit,
3032
warnDeprecated, warnConfigDeprecated,
@@ -37,7 +39,9 @@ type
3739
warnEachIdentIsTuple,
3840
warnProveInit, warnProveField, warnProveIndex, warnGcUnsafe, warnGcUnsafe2,
3941
warnUninit, warnGcMem, warnDestructor, warnLockLevel, warnResultShadowed,
40-
warnInconsistentSpacing, warnCaseTransition, warnCycleCreated, warnUser,
42+
warnInconsistentSpacing, warnCaseTransition, warnCycleCreated,
43+
warnBackendWarning, warnUser,
44+
# hints
4145
hintSuccess, hintSuccessX, hintCC,
4246
hintLineTooLong, hintXDeclaredButNotUsed,
4347
hintConvToBaseNotNeeded,
@@ -95,6 +99,7 @@ const
9599
warnInconsistentSpacing: "Number of spaces around '$#' is not consistent",
96100
warnCaseTransition: "Potential object case transition, instantiate new object instead",
97101
warnCycleCreated: "$1",
102+
warnBackendWarning: "$1",
98103
warnUser: "$1",
99104
hintSuccess: "operation successful: $#",
100105
# keep in sync with `pegSuccess` see testament.nim
@@ -141,7 +146,7 @@ const
141146
"UnsafeCode", "UnusedImport", "EachIdentIsTuple",
142147
"ProveInit", "ProveField", "ProveIndex", "GcUnsafe", "GcUnsafe2", "Uninit",
143148
"GcMem", "Destructor", "LockLevel", "ResultShadowed",
144-
"Spacing", "CaseTransition", "CycleCreated", "User"]
149+
"Spacing", "CaseTransition", "CycleCreated", "BackendWarning", "User"]
145150

146151
HintsToStr* = [
147152
"Success", "SuccessX", "CC", "LineTooLong",

0 commit comments

Comments
 (0)