-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompiler-options.lua
executable file
·3604 lines (3238 loc) · 92.7 KB
/
compiler-options.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env lua
local table_insert = table.insert
local unpack = table.unpack or unpack
local function has_value(t)
return pairs(t)(t)
end
local function has_data(x)
return has_value(x._t) or (x._else and has_value(x._else))
end
local function ramify(x)
if x._if then
if not has_data(x) then
x = {}
end
else
for k,y in pairs(x) do
if y._if and not has_data(y) then
x[k] = nil
end
end
end
return x
end
local if_mt -- referenced by __unm
if_mt = {
__call = function(self, x)
assert(not self._t, '`_t` is not nil')
self._t = ramify(x)
return self
end,
__div = function(self, x)
local subelse = self._subelse or self
assert(subelse._if and not subelse._else, 'replace `x / y / z` with `x / { y / z }`')
x = x and ramify(x)
self._subelse = x
subelse._else = x
return self
end,
__unm = function(self)
return setmetatable({ _if={_not=self._if}, _t=self._t, _subelse=self._subelse }, if_mt)
end,
}
local if_mt_func = {
__call = function(self, ...)
return self._impl(...)
end,
__div = function(self, x)
return self._impl() / x
end,
__unm = function(self)
return -self._impl()
end,
}
local function If(condition)
return setmetatable({ _if=condition }, if_mt)
end
local function IfFunc(f)
return setmetatable({ _impl=f }, if_mt_func)
end
local function Logical(op, conditions)
local conds = {}
for _,x in ipairs(conditions) do
if x._impl then
x = x._impl()
elseif type(x) == 'function' then
x = x()
end
assert(x._if and not x._t)
assert(not x._if.opt)
if x._if[op] then
for _,cond in ipairs(x._if[op]) do
table_insert(conds, cond)
end
else
table_insert(conds, x._if)
end
end
return If({[op]=conds})
end
local function _conditional_name(cond)
return IfFunc(function(x)
local r = If(cond)
return x and r(x) or r
end)
end
local function vers(op_and_version)
local op, major, minor = op_and_version:match('^([<>!=]=?)(%d+)%.?(%d*)$')
assert(op)
return If({op=op, major=tonumber(major), minor=tonumber(minor) or 0})
end
local function _conditional_name_with_version(cond)
return IfFunc(function(x_or_op_and_version)
if type(x_or_op_and_version) == 'string' then
local ret = vers(x_or_op_and_version)
ret._if = {_and={cond, ret._if}}
return ret
else
local r = If(cond)
return x_or_op_and_version and r(x_or_op_and_version) or r
end
end)
end
local function Compiler(name)
return _conditional_name_with_version({compiler=name})
end
local function Platform(name)
return _conditional_name({platform=name})
end
local function Linker(name)
return _conditional_name({linker=name})
end
local function CompilerLike(compiler_like, compilers)
local tools = {}
for _,tool in ipairs(compilers) do
table_insert(tools, tool()._if.compiler)
end
return _conditional_name_with_version({compiler_like=compiler_like, compilers=tools})
end
local function Or(...) return Logical('_or', {...}) end
local function And(...) return Logical('_and', {...}) end
local function lvl(x) return If({lvl=x}) end
local function opt(x) return If({opt=x}) end
local has_opt_mt = {
__call = function(self, ...)
-- assert(#self.levels > 0)
return If({check_opt={optname=self.optname, levels=self.levels, exclude=self.exclude}})(...)
end,
with = function(self, ...)
assert(not self._used)
self._used = true
local levels = self.levels
local set = {}
local lvl
for _, cond in pairs({...}) do
lvl = assert(cond._if.lvl)
assert(not set[lvl])
table_insert(levels, lvl)
set[lvl] = true
end
assert(#levels ~= 0)
return self
end,
without = function(self, ...)
self.exclude = true
return self:with(...)
end,
}
has_opt_mt.__index = has_opt_mt
local function has_opt(optname)
return setmetatable({optname=optname, levels={}}, has_opt_mt)
end
-- local windows = Platform('windows')
-- local macos = Platform('macos')
local linux = Platform('linux')
local mingw = Platform('mingw')
local gcc = Compiler('gcc')
local clang = Compiler('clang')
local clang_cl = Compiler('clang-cl')
local msvc = Compiler('msvc')
local icc = Compiler('icc')
local icl = Compiler('icl')
-- local emcc = Compiler('emcc')
local clang_emcc = Compiler('clang-emcc') -- virtual compiler, refer to clang version
local clang_like = CompilerLike('clang-like', {clang, clang_cl, clang_emcc})
-- for clang-emcc to emcc
-- local switch_to_real_compiler = {switch_to_special=true}
-- local msvc_linker = Linker('msvc')
local lld_link = Linker('lld-link')
local ld64 = Linker('ld64') -- Apple ld64
local function link(x) return { link=x } end
local function flag(x) return { cxx=x } end
local function fl(x) return { cxx=x, link=x } end
local function act(datas) return { act={datas} } end
local function reset_opt(name) return { reset_opt=name } end
function noop() end
local function if_else(condition, f)
return condition { f(true) } / f()
end
local function match(t)
local x = t[1]
for i=2,#t do
x = x / t[i]
end
return x
end
local function MakeAST(is_C)
local c, cxx
if is_C then
c = flag
cxx = noop
else
c = noop
cxx = flag
end
-- opt'build' ? -pipe Avoid temporary files, speeding up builds
-- gcc and clang:
-- g++ -Q --help=optimizers,warnings,target,params,common,undocumented,joined,separate,language__ -O3
-- all warnings by version: https://github.com/pkolbus/compiler-warnings
-- clang:
-- https://clang.llvm.org/docs/DiagnosticsReference.html
-- https://releases.llvm.org/10.0.0/tools/clang/docs/DiagnosticsReference.html
-- https://github.com/llvm-mirror/clang/blob/master/include/clang/Driver/Options.td
-- https://github.com/llvm-mirror/clang/blob/master/include/clang/Basic/Diagnostic.td
-- clang-cl
-- https://clang.llvm.org/docs/UsersManual.html#id9
-- icc, icpc and icl:
-- icc / icpc (linux) -diag-enable warn -diag-dump
-- icl (windows) /Qdiag-enable:warn -Qdiag-dump
-- https://www.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/compiler-options/alphabetical-list-of-compiler-options.html
-- https://www.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/compiler-options/deprecated-and-removed-compiler-options.html
-- icx, icpx, dpcpp are clang compiler
-- icx -qnextgen-diag
-- emcc
-- List of all compiler & linker options: https://emscripten.org/docs/tools_reference/emcc.html
-- List of all -s options: https://github.com/emscripten-core/emscripten/blob/main/src/settings.js
local ndebug_decl = function(def, undef)
return {
lvl'off' { undef }
/ lvl'on' { def }
/ { --[[lvl'with_optimization_1_or_above']]
opt'optimization' {
-Or(lvl'0', lvl'g') {
def
}
}
}
}
end
return --[[printAST]] {
opt'ndebug' {
Or(msvc, icl) { ndebug_decl(flag'/DNDEBUG', flag'/UNDEBUG') }
/ ndebug_decl(flag'-DNDEBUG', flag'-UNDEBUG')
},
Or(gcc, clang_like) {
opt'warnings' {
match {
lvl'off' { flag'-w' },
match {
gcc {
flag'-Wall',
-- flag'-Weffc++',
flag'-Wextra',
flag'-Wcast-align',
flag'-Wcast-qual',
flag'-Wdisabled-optimization',
flag'-Wfloat-equal',
flag'-Wformat-security',
flag'-Wformat=2',
-- flag'-Winline',
flag'-Winvalid-pch',
flag'-Wmissing-include-dirs',
flag'-Wpacked',
flag'-Wredundant-decls',
flag'-Wundef',
flag'-Wunused-macros',
flag'-Wpointer-arith',
cxx'-Wmissing-declarations',
cxx'-Wnon-virtual-dtor',
cxx'-Wold-style-cast',
cxx'-Woverloaded-virtual',
c'-Wbad-function-cast',
c'-Winit-self', -- enabled by -Wall in C++
c'-Wjump-misses-init',
c'-Wnested-externs',
c'-Wold-style-definition',
c'-Wstrict-prototypes',
c'-Wwrite-strings',
vers'>=4.7' {
flag'-Wsuggest-attribute=noreturn',
cxx'-Wzero-as-null-pointer-constant',
flag'-Wlogical-op',
-- flag'-Wno-aggressive-loop-optimizations',
-- flag'-Wnormalized=nfc',
flag'-Wvector-operation-performance',
flag'-Wdouble-promotion',
flag'-Wtrampolines', -- C only with a nested function ?
vers'>=4.8' {
cxx'-Wuseless-cast',
vers'>=4.9' {
cxx'-Wconditionally-supported',
flag'-Wfloat-conversion',
vers'>=5.1' {
flag'-Wformat-signedness',
flag'-Warray-bounds=2', -- This option is only active when -ftree-vrp is active (default for -O2 and above). level=1 enabled by -Wall.
-- flag'-Wctor-dtor-privacy',
cxx'-Wstrict-null-sentinel',
cxx'-Wsuggest-override',
vers'>=6.1' {
flag'-Wduplicated-cond',
flag'-Wnull-dereference', -- This option is only active when -fdelete-null-pointer-checks is active, which is enabled by optimizations in most targets.
vers'>=7' {
cxx'-Waligned-new',
vers'>=7.1' {
flag'-Walloc-zero',
flag'-Walloca',
flag'-Wformat-overflow=2',
-- flag'-Wformat-truncation=1', -- enabled by -Wformat. Works best with -O2 and higher. =2 = calls to bounded functions whose return value is used
-- flag'-Wformat-y2k', -- strftime formats that may yield only a two-digit year.
flag'-Wduplicated-branches',
vers'>=8' {
cxx'-Wclass-memaccess',
Or(lvl'strict', lvl'very_strict') {
flag'-Wcast-align=strict'
},
}
}
}
}
}
}
}
},
},
{ --[[clang_like]]
flag'-Weverything',
flag'-Wno-documentation',
flag'-Wno-documentation-unknown-command',
flag'-Wno-newline-eof',
-- flag'-Wno-range-loop-analysis',
-- flag'-Wno-disabled-macro-expansion',
cxx'-Wno-c++98-compat',
cxx'-Wno-c++98-compat-pedantic',
flag'-Wno-padded',
flag'-Wno-global-constructors',
cxx'-Wno-weak-vtables',
cxx'-Wno-exit-time-destructors',
-- cxx'-Qunused-arguments',
-has_opt'switch_warnings':with(
lvl'off',
lvl'exhaustive_enum',
lvl'exhaustive_enum_and_mandatory_default'
) {
flag'-Wno-switch-enum',
},
-has_opt'covered_switch_default_warnings' {
flag'-Wno-covered-switch-default'
},
vers'>=3.9' {
cxx'-Wno-undefined-var-template',
vers'>=5' {
cxx'-Wno-inconsistent-missing-destructor-override',
vers'>=9' {
cxx'-Wno-ctad-maybe-unsupported',
vers'>=10' {
cxx'-Wno-c++20-compat',
vers'>=11' {
cxx'-Wno-suggest-destructor-override',
vers'>=16' {
-has_opt'unsafe_buffer_usage_warnings' {
flag'-Wno-unsafe-buffer-usage'
}
},
}
}
}
}
}
},
}
},
},
match {
gcc {
opt'switch_warnings' {
match {
lvl'on' { flag'-Wswitch' }, -- enabled by -Wall
lvl'exhaustive_enum' { flag'-Wswitch-enum' },
lvl'mandatory_default' { flag'-Wswitch-default' },
lvl'exhaustive_enum_and_mandatory_default' {
flag'-Wswitch-default',
flag'-Wswitch-enum',
},
{ --[[lvl'off']]
flag'-Wno-switch',
flag'-Wno-switch-enum',
flag'-Wno-switch-default',
}
}
}
},
{ --[[clang_like]]
opt'switch_warnings' {
-- -Wswitch-default is a noop with < 18.0
match {
lvl'on' {
flag'-Wswitch', -- enabled by default
flag'-Wno-switch-default',
},
lvl'mandatory_default' {
flag'-Wswitch', -- enabled by default
flag'-Wswitch-default',
},
lvl'exhaustive_enum' {
flag'-Wswitch', -- do like gcc where -Wswitch-enum covers cases of -Wswitch
flag'-Wswitch-enum',
flag'-Wno-switch-default',
},
lvl'exhaustive_enum_and_mandatory_default' {
flag'-Wswitch', -- do like gcc where -Wswitch-enum covers cases of -Wswitch
flag'-Wswitch-enum',
flag'-Wswitch-default',
},
{ --[[lvl'off']]
flag'-Wno-switch',
flag'-Wno-switch-enum',
flag'-Wno-switch-default',
}
}
},
opt'covered_switch_default_warnings' {
match {
lvl'off' { flag'-Wno-covered-switch-default' },
flag'-Wcovered-switch-default',
}
},
}
},
opt'unsafe_buffer_usage_warnings' {
clang_like'>=16' {
match {
lvl'off' { flag'-Wno-unsafe-buffer-usage' },
cxx'-Wunsafe-buffer-usage',
}
}
},
opt'diagnostics_show_template_tree' {
Or(gcc'>=8', clang_like) {
match {
lvl'on' { cxx'-fdiagnostics-show-template-tree' },
cxx'-fno-diagnostics-show-template-tree',
}
},
},
opt'elide_type' {
match {
lvl'on' { gcc'>=8' { cxx'-felide-type' } },
Or(gcc'>=8', clang_like'>=3.4') { cxx'-fno-elide-type', },
}
},
opt'exceptions' {
match {
lvl'on' {
flag'-fexceptions',
clang_emcc {
flag'-sDISABLE_EXCEPTION_CATCHING=0',
}
},
flag'-fno-exceptions',
}
},
opt'rtti' {
match {
lvl'on' { cxx'-frtti' },
cxx'-fno-rtti',
}
},
opt'var_init' {
Or(gcc'>=12', clang_like'>=8') {
clang_like'<=15' {
flag'-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang'
},
match {
lvl'pattern' {
flag'-ftrivial-auto-var-init=pattern'
},
lvl'zero' {
flag'-ftrivial-auto-var-init=zero'
},
--[[lvl'uninitialized']] {
flag'-ftrivial-auto-var-init=uninitialized',
},
},
},
},
opt'windows_abi_compatibility_warnings' {
Or(gcc'>=10', clang_like) {
match {
lvl'on' { cxx'-Wmismatched-tags' },
cxx'-Wno-mismatched-tags'
}
}
},
opt'warnings_as_error' {
match {
lvl'on' { flag'-Werror', },
lvl'basic' {
-- flag'-Werror=non-virtual-dtor',
flag'-Werror=return-type',
flag'-Werror=init-self',
match {
gcc {
flag'-Werror=div-by-zero',
vers'>=5.1' {
flag'-Werror=array-bounds',
flag'-Werror=logical-op',
flag'-Werror=logical-not-parentheses',
vers'>=7' {
cxx'-Werror=literal-suffix',
}
}
},
{ --[[clang_like]]
flag'-Werror=array-bounds',
flag'-Werror=division-by-zero',
vers'>=3.4' {
flag'-Werror=logical-not-parentheses',
vers'>=3.6' {
cxx'-Werror=delete-incomplete',
vers'>=6' {
cxx'-Werror=user-defined-literals',
vers'>=7' {
cxx'-Werror=dynamic-class-memaccess',
}
}
}
}
}
}
},
flag'-Wno-error',
}
},
opt'suggestions' {
-lvl'off' {
gcc {
flag'-Wsuggest-attribute=pure',
flag'-Wsuggest-attribute=const',
vers'>=5' {
cxx'-Wsuggest-final-types',
cxx'-Wsuggest-final-methods',
-- flag'-Wsuggest-attribute=format',
vers'>=5.1' {
cxx'-Wnoexcept',
},
}
}
},
},
-- ASAN_OPTIONS=strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1:detect_invalid_pointer_pairs=2
opt'sanitizers' {
match {
lvl'off' {
fl'-fno-sanitize=all'
},
clang_cl {
flag'-fsanitize=undefined',
flag'-fsanitize=address', -- memory, thread are mutually exclusive
flag'-fsanitize-address-use-after-scope',
},
Or(clang, clang_emcc) {
vers'>=3.1' {
fl'-fsanitize=undefined',
fl'-fsanitize=address', -- memory, thread are mutually exclusive
flag'-fsanitize-address-use-after-scope',
flag'-fno-omit-frame-pointer',
flag'-fno-optimize-sibling-calls',
clang {
vers'>=3.4' {
fl'-fsanitize=leak', -- requires the address sanitizer
},
vers'>=6' {
opt'stack_protector' {
-lvl'off' {
flag'-fsanitize-minimal-runtime',
}
}
},
},
}
},
{ --[[gcc]]
vers'>=4.8' {
fl'-fsanitize=address', -- memory, thread are mutually exclusive
flag'-fno-omit-frame-pointer',
flag'-fno-optimize-sibling-calls',
vers'>=4.9' {
fl'-fsanitize=undefined',
fl'-fsanitize=leak', -- requires the address sanitizer
}
}
}
}
},
opt'control_flow' {
match {
clang_emcc {
match {
lvl'off' {
link'-sASSERTIONS=0',
link'-sSAFE_HEAP=0',
},
{
-- Building with ASSERTIONS=1 causes STACK_OVERFLOW_CHECK=1
link'-sASSERTIONS=1',
link'-sDEMANGLE_SUPPORT=1',
-- ASan does not work with SAFE_HEAP
-has_opt'sanitizers':with(lvl'on') {
link'-sSAFE_HEAP=1',
},
}
}
},
lvl'off' {
match {
gcc'>=8' {
flag'-fcf-protection=none'
},
{ -- clang, clang_cl
fl'-fno-sanitize=cfi',
flag'-fcf-protection=none',
flag'-fno-sanitize-cfi-cross-dso',
}
}
},
Or(gcc'>=8', -gcc) {
match {
-- gcc: flag'-mcet',
-- clang_cl: flag'-fsanitize-cfi-cross-dso',
lvl'branch' { flag'-fcf-protection=branch' },
lvl'return' { flag'-fcf-protection=return' },
flag'-fcf-protection=full',
},
And(lvl'allow_bugs', clang) {
fl'-fsanitize=cfi', -- cfi-* only allowed with '-flto' and '-fvisibility=...'
flag'-fvisibility=hidden',
fl'-flto',
}
}
}
},
opt'color' {
Or(vers'>=4.9', -gcc --[[=clang_like]]) {
match {
lvl'auto' { flag'-fdiagnostics-color=auto' },
lvl'never' { flag'-fdiagnostics-color=never' },
--[[lvl'always']] { flag'-fdiagnostics-color=always' },
}
},
},
opt'reproducible_build_warnings' {
gcc'>=4.9' {
match {
lvl'on' { flag'-Wdate-time' },
flag'-Wno-date-time',
}
}
},
opt'diagnostics_format' {
match {
lvl'fixits' {
Or(gcc'>=7', And(-gcc, vers'>=5') --[[=clang_like'>=5']]) {
flag'-fdiagnostics-parseable-fixits'
}
},
lvl'patch' {
gcc'>=7' { flag'-fdiagnostics-generate-patch' }
},
{ --[[lvl'print_source_range_info']]
clang_like { flag'-fdiagnostics-print-source-range-info' }
}
}
},
opt'fix_compiler_error' {
match {
lvl'on' {
gcc {
vers'>=4.7' {
cxx'-Werror=narrowing',
vers'>=7.1' {
cxx'-Werror=literal-suffix', -- no warning name before 7.1
}
}
},
flag'-Werror=write-strings'
},
-gcc --[[=clang_like]] {
flag'-Wno-error=c++11-narrowing',
flag'-Wno-reserved-user-defined-literal',
}
}
},
opt'lto' {
match {
lvl'off' { fl'-fno-lto' },
gcc {
fl'-flto',
vers'>=5' {
opt'warnings' {
-- increases size of LTO object files, but enables diagnostics about ODR violations
-lvl'off' { fl'-flto-odr-type-merging' },
},
match {
lvl'fat' { flag'-ffat-lto-objects', },
lvl'thin' { link'-fuse-linker-plugin' },
}
}
},
{ --[[clang_like]]
clang_cl {
-- LTO require -fuse-ld=lld (link by default)
link'-fuse-ld=lld',
},
match {
And(Or(lvl'thin', lvl'on'), vers'>=6') {
fl'-flto=thin'
},
fl'-flto',
}
}
}
},
opt'shadow_warnings' {
match {
lvl'off' {
flag'-Wno-shadow',
clang_like'>=8' {
flag'-Wno-shadow-field'
}
},
lvl'on' { flag'-Wshadow' },
lvl'all' {
match {
gcc { flag'-Wshadow' },
flag'-Wshadow-all',
}
},
gcc'>=7.1' {
match {
lvl'local' {
flag'-Wshadow=local'
},
{ --[[lvl'compatible_local']]
flag'-Wshadow=compatible-local'
}
}
}
}
},
opt'float_sanitizers' {
Or(gcc'>=5', clang_like'>=5') {
match {
lvl'on' {
flag'-fsanitize=float-divide-by-zero',
flag'-fsanitize=float-cast-overflow',
},
{
flag'-fno-sanitize=float-divide-by-zero',
flag'-fno-sanitize=float-cast-overflow',
},
}
},
},
opt'integer_sanitizers' {
match {
clang_like'>=5' {
match {
lvl'on' { flag'-fsanitize=integer', },
flag'-fno-sanitize=integer',
}
},
gcc'>=4.9' {
lvl'on' {
flag'-ftrapv',
flag'-fsanitize=undefined',
},
}
}
},
},
opt'conversion_warnings' {
Or(gcc, clang_like, icc) {
match {
lvl'on' {
flag'-Wconversion',
flag'-Wsign-compare',
flag'-Wsign-conversion',
},
lvl'conversion'{
flag'-Wconversion',
},
lvl'sign'{
flag'-Wsign-compare',
flag'-Wsign-conversion',
},
{ --[[lvl'off']]
flag'-Wno-conversion',
flag'-Wno-sign-compare',
flag'-Wno-sign-conversion',
},
}
},
},
Or(gcc, clang, clang_emcc) {
opt'stl_debug' {
-lvl'off' {
lvl'assert_as_exception' {
cxx'-D_LIBCPP_DEBUG_USE_EXCEPTIONS'
},
match {
Or(lvl'allow_broken_abi', lvl'allow_broken_abi_and_bugs') {
clang {
-- debug allocator has a bug: https://bugs.llvm.org/show_bug.cgi?id=39203
Or(vers'>=8', lvl'allow_broken_abi_and_bugs') {
cxx'-D_LIBCPP_DEBUG=1',
},
},
cxx'-D_GLIBCXX_DEBUG',
},
cxx'-D_GLIBCXX_ASSERTIONS',
},
opt'pedantic' {
-lvl'off' {
cxx'-D_GLIBCXX_DEBUG_PEDANTIC'
},
},
}
},
opt'pedantic' {
-lvl'off' {
flag'-pedantic',
lvl'as_error' {
flag'-pedantic-errors',
},
},
},
},
clang_emcc {
opt'optimization' {
match {
lvl'0' { fl'-O0' },
lvl'g' { fl'-Og' },
lvl'1' { fl'-O1' },
lvl'2' { fl'-O2' },
lvl'3' { fl'-O3' },
lvl'fast' {
fl'-O3',
-- The LLVM wasm backend avoids traps by adding more code around each possible trap
-- (basically clamping the value if it would trap).
-- That code may not run in older VMs, though.
fl'-mnontrapping-fptoint',
},
lvl'size' { fl'-Os' },
{ --[[lvl'z']]
fl'-Oz'
-- -- This greatly reduces the size of the support JavaScript code
-- -- Note that this increases compile time significantly.
-- fl'--closure 1',
},
}
},
opt'debug' {
match {
lvl'off' { flag'-g0' },
flag'-g',
}
},
}
/
Or(gcc, clang) {
gcc'>=12' {
-- contrary to what the doc says, this flag is not set with -O0
cxx'-ffold-simple-inlines',
},
opt'coverage' {
lvl'on' {
flag'--coverage', -- -fprofile-arcs -ftest-coverage
link'--coverage', -- -lgcov
clang {
link'-lprofile_rt',
-- fl'-fprofile-instr-generate',
-- fl'-fcoverage-mapping',
},
},
},
opt'debug' {
match {
lvl'off' { flag'-g0' },
lvl'gdb' { flag'-ggdb' },
clang {
match {
lvl'line_tables_only' { flag'-gline-tables-only' },
lvl'lldb' { flag'-glldb' },
lvl'sce' { flag'-gsce' },
flag'-g',
}
},
flag'-g',
-- flag'-fasynchronous-unwind-tables', -- Increased reliability of backtraces
}
},
opt'optimization' {
match {
lvl'0' { flag'-O0' },
lvl'g' { flag'-Og' },
{