History

Add -W[no-]error=OPTION specific abortions

Steffen Nurpmeso committed 5 years ago

Commit a7a13891 parent eadcee66 files · +79 −28Browse files

Unified · Split

6 files
  1. libtcc.c +55 −10
  2. tcc-doc.texi +5 −2
  3. tcc.h +9 −5
  4. tccasm.c +4 −4
  5. tccgen.c +5 −5
  6. tccpp.c +1 −2
libtcc.c+55−10
@@ -1230,8 +1230,9 @@ LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path) · 1229 unmodified lines
12301230 s->tcc_lib_path = tcc_strdup(path);
12311231 }
12321232
1233−#define WD_ALL 0x0001 /* warning is activated when using -Wall */
1234−#define FD_INVERT 0x0002 /* invert value before storing */
1233+#define WD_ALL (1u<<0) /* warning is activated when using -Wall */
1234+#define WD_ERROR (1u<<1) /* can be used with -W[no-]error=X */
1235+#define FD_INVERT (1u<<2) /* invert value before storing */
12351236
12361237 typedef struct FlagDef {
12371238 uint16_t offset;
@@ -1279,6 +1280,49 @@ ST_FUNC int set_flag(TCCState *s, const FlagDef *flags, const char *name) · 41 unmodified lines
12791280 return ret;
12801281 }
12811282
1283+ST_FUNC int set_W_flag(TCCState *s, const FlagDef *flags, const char *optarg)
1284+{
1285+ int value, ret;
1286+ const FlagDef *p;
1287+ const char *r, *sub;
1288+
1289+ value = 1;
1290+ r = optarg;
1291+ if (no_flag(&r))
1292+ value = 0;
1293+
1294+ if ((sub = strchr(r, '=')) != NULL) {
1295+ if (strncmp(r, "error", (uintptr_t)(sub - r)))
1296+ return -1;
1297+ r = ++sub;
1298+ if (value)
1299+ value = 1 | 2;
1300+ }
1301+
1302+ /* .offset for "all" is 0 */
1303+ for (ret = -1, p = flags; p->name; ++p) {
1304+ if (ret) {
1305+ if (strcmp(r, p->name))
1306+ continue;
1307+ if (sub != NULL && !(p->flags & WD_ERROR))
1308+ break;
1309+ } else {
1310+ if (0 == (p->flags & WD_ALL))
1311+ continue;
1312+ }
1313+ if (p->offset) {
1314+ *((unsigned char *)s + p->offset) = value;
1315+ if (ret) {
1316+ ret = 0;
1317+ break;
1318+ }
1319+ } else {
1320+ ret = 0;
1321+ }
1322+ }
1323+ return ret;
1324+}
1325+
12821326 static int strstart(const char *val, const char **str)
12831327 {
12841328 const char *p, *q;
@@ -1469,7 +1513,7 @@ static int tcc_set_linker(TCCState *s, const char *option) · 184 unmodified lines
14691513 tcc_error("unsupported linker option '%s'", option);
14701514 }
14711515
1472− if (ignoring && s->warn_unsupported)
1516+ if (ignoring && NEED_WARNING(s, unsupported))
14731517 tcc_warning("unsupported linker option '%s'", option);
14741518
14751519 option = skip_linker_arg(&p);
@@ -1616,12 +1660,13 @@ static const TCCOption tcc_options[] = { · 140 unmodified lines
16161660
16171661 static const FlagDef options_W[] = {
16181662 { 0, 0, "all" },
1619− { offsetof(TCCState, warn_unsupported), 0, "unsupported" },
1620− { offsetof(TCCState, warn_write_strings), WD_ALL, "write-strings" },
16211663 { offsetof(TCCState, warn_error), 0, "error" },
1622− { offsetof(TCCState, warn_gcc_compat), 0, "gcc-compat" },
1623− { offsetof(TCCState, warn_implicit_function_declaration), WD_ALL,
1624− "implicit-function-declaration" },
1664+ { offsetof(TCCState, warn_unsupported), WD_ERROR, "unsupported" },
1665+ { offsetof(TCCState, warn_gcc_compat), WD_ERROR, "gcc-compat" },
1666+ { offsetof(TCCState, warn_write_strings), WD_ERROR | WD_ALL,
1667+ "write-strings" },
1668+ { offsetof(TCCState, warn_implicit_function_declaration),
1669+ WD_ERROR | WD_ALL, "implicit-function-declaration" },
16251670 { 0, 0, NULL }
16261671 };
16271672
@@ -1920,7 +1965,7 @@ reparse: · 292 unmodified lines
19201965 break;
19211966 case TCC_OPTION_W:
19221967 s->warn_none = 0;
1923− if (optarg[0] && set_flag(s, options_W, optarg) < 0)
1968+ if (optarg[0] && set_W_flag(s, options_W, optarg) < 0)
19241969 goto unsupported_option;
19251970 break;
19261971 case TCC_OPTION_w:
@@ -2007,7 +2052,7 @@ reparse: · 80 unmodified lines
20072052 break;
20082053 default:
20092054 unsupported_option:
2010− if (s->warn_unsupported)
2055+ if (NEED_WARNING(s, unsupported))
20112056 tcc_warning("unsupported option '%s'", r);
20122057 break;
20132058 }
tcc-doc.texi+5−2
@@ -267,10 +267,13 @@ Make string constants be of type @code{const char *} instead of @code{char · 266 unmodified lines
267267 *}.
268268
269269 @item -Werror
270−Abort compilation if warnings are issued.
270+Abort compilation if a warning is issued.
271+Can be given an option to enable the specified warning
272+and turn it into an error, for example @option{-Werror=unsupported}.
273+(Enabling general abortion and disabling specifics is not supported.)
271274
272275 @item -Wall
273−Activate all warnings, except @option{-Werror}, @option{-Wunusupported} and
276+Activate all warnings, except @option{-Werror}, @option{-Wunsupported} and
274277 @option{-Wwrite-strings}.
275278
276279 @end table
tcc.h+9−5
@@ -767,13 +767,17 @@ struct TCCState { · 766 unmodified lines
767767 unsigned char dollars_in_identifiers; /* allows '$' char in identifiers */
768768 unsigned char ms_bitfields; /* if true, emulate MS algorithm for aligning bitfields */
769769
770− /* warning switches */
771− unsigned char warn_write_strings;
772− unsigned char warn_unsupported;
773− unsigned char warn_error;
770+ /* warning switches; but for first two, W[no-]error=X is supported */
771+ /* XXX TCC_IS_WARN_OR_ERR(X,Y) used to drive W[[no-]error]=X */
774772 unsigned char warn_none;
775− unsigned char warn_implicit_function_declaration;
773+ unsigned char warn_error;
774+ unsigned char warn_unsupported;
776775 unsigned char warn_gcc_compat;
776+ unsigned char warn_write_strings;
777+ unsigned char warn_implicit_function_declaration;
778+#define NEED_WARNING(SELF,SWITCH) \
779+ ((SELF)->warn_ ## SWITCH \
780+ ? (((SELF)->warn_ ## SWITCH & 2) ? (SELF)->warn_error = 1 : 1) : 0)
777781
778782 /* compile with debug symbol (and use them if error during execution) */
779783 unsigned char do_debug;
tccasm.c+4−4
@@ -775,7 +775,7 @@ static void asm_parse_directive(TCCState *s1, int global) · 774 unmodified lines
775775 else
776776 pstrcat(filename, sizeof(filename), get_tok_str(tok, NULL));
777777
778− if (s1->warn_unsupported)
778+ if (NEED_WARNING(s1, unsupported))
779779 tcc_warning("ignoring .file %s", filename);
780780
781781 next();
@@ -793,7 +793,7 @@ static void asm_parse_directive(TCCState *s1, int global) · 11 unmodified lines
793793 else
794794 pstrcat(ident, sizeof(ident), get_tok_str(tok, NULL));
795795
796− if (s1->warn_unsupported)
796+ if (NEED_WARNING(s1, unsupported))
797797 tcc_warning("ignoring .ident %s", ident);
798798
799799 next();
@@ -810,7 +810,7 @@ static void asm_parse_directive(TCCState *s1, int global) · 10 unmodified lines
810810 }
811811
812812 /* XXX .size name,label2-label1 */
813− if (s1->warn_unsupported)
813+ if (NEED_WARNING(s1, unsupported))
814814 tcc_warning("ignoring .size %s,*", get_tok_str(tok, NULL));
815815
816816 next();
@@ -840,7 +840,7 @@ static void asm_parse_directive(TCCState *s1, int global) · 23 unmodified lines
840840 if (!strcmp(newtype, "function") || !strcmp(newtype, "STT_FUNC")) {
841841 sym->type.t = (sym->type.t & ~VT_BTYPE) | VT_FUNC;
842842 }
843− else if (s1->warn_unsupported)
843+ else if (NEED_WARNING(s1, unsupported))
844844 tcc_warning("change type of '%s' from 0x%x to '%s' ignored",
845845 get_tok_str(sym->v, NULL), sym->type.t, newtype);
846846
tccgen.c+5−5
@@ -4506,7 +4506,7 @@ redo: · 4505 unmodified lines
45064506 ad->a.dllimport = 1;
45074507 break;
45084508 default:
4509− if (tcc_state->warn_unsupported)
4509+ if (NEED_WARNING(tcc_state, unsupported))
45104510 tcc_warning("'%s' attribute ignored", get_tok_str(t, NULL));
45114511 /* skip parameters */
45124512 if (tok == '(') {
@@ -5915,7 +5915,7 @@ ST_FUNC void unary(void) · 1402 unmodified lines
59155915 len = strlen(funcname) + 1;
59165916 /* generate char[len] type */
59175917 type.t = VT_BYTE;
5918− if (tcc_state->warn_write_strings)
5918+ if (NEED_WARNING(tcc_state, write_strings))
59195919 type.t |= VT_CONSTANT;
59205920 mk_pointer(&type);
59215921 type.t |= VT_ARRAY;
@@ -5942,7 +5942,7 @@ ST_FUNC void unary(void) · 20 unmodified lines
59425942 if (tcc_state->char_is_unsigned)
59435943 t = VT_BYTE | VT_UNSIGNED;
59445944 str_init:
5945− if (tcc_state->warn_write_strings)
5945+ if (NEED_WARNING(tcc_state, write_strings))
59465946 t |= VT_CONSTANT;
59475947 type.t = t;
59485948 mk_pointer(&type);
@@ -6378,9 +6378,9 @@ special_math_val: · 429 unmodified lines
63786378 tcc_error("'%s' undeclared", name);
63796379 /* for simple function calls, we tolerate undeclared
63806380 external reference to int() function */
6381− if (tcc_state->warn_implicit_function_declaration
6381+ if (NEED_WARNING(tcc_state, implicit_function_declaration)
63826382 #ifdef TCC_TARGET_PE
6383− /* people must be warned about using undeclared WINAPI functions
6383+ /* must warn about using undeclared WINAPI functions
63846384 (which usually start with uppercase letter) */
63856385 || (name[0] >= 'A' && name[0] <= 'Z')
63866386 #endif
tccpp.c+1−2
@@ -1770,9 +1770,8 @@ static void pragma_parse(TCCState *s1) · 1769 unmodified lines
17701770 tcc_free(p);
17711771 }
17721772
1773− } else if (s1->warn_unsupported) {
1773+ } else if (NEED_WARNING(s1, unsupported))
17741774 tcc_warning("#pragma %s is ignored", get_tok_str(tok, &tokc));
1775− }
17761775 return;
17771776
17781777 pragma_err:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t