Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说跟老韩学Ubuntu Server 2204-gcc指令帮助手册第12小节,希望能够帮助你!!!。
GCC是每个从事Linux,以及嵌入式开发等必备的编译器,由于帮助手册较多,这里使用了分页的形式进行分享,如下为Ubuntu Server 22.04操作系统平台和GCC编译器的基本信息。
老韩Linux DevOps
GCC帮助手册的第12小节,3288行~5288行最后全部的帮助信息,如下。
3288 This warning is enabled by -Wall.
3289 -Wunused-label
3290 Warn whenever a label is declared but not used. This warning is enabled by -Wall.
3291 To suppress this warning use the "unused" attribute.
3292 -Wunused-local-typedefs (C, Objective-C, C++ and Objective-C++ only)
3293 Warn when a typedef locally defined in a function is not used. This warning is enabled by -Wall.
3294 -Wunused-parameter
3295 Warn whenever a function parameter is unused aside from its declaration.
3296 To suppress this warning use the "unused" attribute.
3297 -Wno-unused-result
3298 Do not warn if a caller of a function marked with attribute "warn_unused_result" does not use its return
3299 value. The default is -Wunused-result.
3300 -Wunused-variable
3301 Warn whenever a local or static variable is unused aside from its declaration. This option implies
3302 -Wunused-const-variable=1 for C, but not for C++. This warning is enabled by -Wall.
3303 To suppress this warning use the "unused" attribute.
3304 -Wunused-const-variable
3305 -Wunused-const-variable=n
3306 Warn whenever a constant static variable is unused aside from its declaration. -Wunused-const-variable=1
3307 is enabled by -Wunused-variable for C, but not for C++. In C this declares variable storage, but in C++
3308 this is not an error since const variables take the place of "#define"s.
3309 To suppress this warning use the "unused" attribute.
3310 -Wunused-const-variable=1
3311 This is the warning level that is enabled by -Wunused-variable for C. It warns only about unused
3312 static const variables defined in the main compilation unit, but not about static const variables
3313 declared in any header included.
3314 -Wunused-const-variable=2
3315 This warning level also warns for unused constant static variables in headers (excluding system
3316 headers). This is the warning level of -Wunused-const-variable and must be explicitly requested since
3317 in C++ this isn't an error and in C it might be harder to clean up all headers included.
3318 -Wunused-value
3319 Warn whenever a statement computes a result that is explicitly not used. To suppress this warning cast the
3320 unused expression to "void". This includes an expression-statement or the left-hand side of a comma
3321 expression that contains no side effects. For example, an expression such as "x[i,j]" causes a warning,
3322 while "x[(void)i,j]" does not.
3323 This warning is enabled by -Wall.
3324 -Wunused
3325 All the above -Wunused options combined.
3326 In order to get a warning about an unused function parameter, you must either specify -Wextra -Wunused
3327 (note that -Wall implies -Wunused), or separately specify -Wunused-parameter.
3328 -Wuninitialized
3329 Warn if an object with automatic or allocated storage duration is used without having been initialized. In
3330 C++, also warn if a non-static reference or non-static "const" member appears in a class without
3331 constructors.
3332 In addition, passing a pointer (or in C++, a reference) to an uninitialized object to a "const"-qualified
3333 argument of a built-in function known to read the object is also diagnosed by this warning.
3334 (-Wmaybe-uninitialized is issued for ordinary functions.)
3335 If you want to warn about code that uses the uninitialized value of the variable in its own initializer,
3336 use the -Winit-self option.
3337 These warnings occur for individual uninitialized elements of structure, union or array variables as well
3338 as for variables that are uninitialized as a whole. They do not occur for variables or elements declared
3339 "volatile". Because these warnings depend on optimization, the exact variables or elements for which there
3340 are warnings depend on the precise optimization options and version of GCC used.
3341 Note that there may be no warning about a variable that is used only to compute a value that itself is
3342 never used, because such computations may be deleted by data flow analysis before the warnings are printed.
3343 -Wno-invalid-memory-model
3344 This option controls warnings for invocations of __atomic Builtins, __sync Builtins, and the C11 atomic
3345 generic functions with a memory consistency argument that is either invalid for the operation or outside
3346 the range of values of the "memory_order" enumeration. For example, since the "__atomic_store" and
3347 "__atomic_store_n" built-ins are only defined for the relaxed, release, and sequentially consistent memory
3348 orders the following code is diagnosed:
3349 void store (int *i)
3350 {
3351 __atomic_store_n (i, 0, memory_order_consume);
3352 }
3353 -Winvalid-memory-model is enabled by default.
3354 -Wmaybe-uninitialized
3355 For an object with automatic or allocated storage duration, if there exists a path from the function entry
3356 to a use of the object that is initialized, but there exist some other paths for which the object is not
3357 initialized, the compiler emits a warning if it cannot prove the uninitialized paths are not executed at
3358 run time.
3359 In addition, passing a pointer (or in C++, a reference) to an uninitialized object to a "const"-qualified
3360 function argument is also diagnosed by this warning. (-Wuninitialized is issued for built-in functions
3361 known to read the object.) Annotating the function with attribute "access (none)" indicates that the
3362 argument isn't used to access the object and avoids the warning.
3363 These warnings are only possible in optimizing compilation, because otherwise GCC does not keep track of
3364 the state of variables.
3365 These warnings are made optional because GCC may not be able to determine when the code is correct in spite
3366 of appearing to have an error. Here is one example of how this can happen:
3367 {
3368 int x;
3369 switch (y)
3370 {
3371 case 1: x = 1;
3372 break;
3373 case 2: x = 4;
3374 break;
3375 case 3: x = 5;
3376 }
3377 foo (x);
3378 }
3379 If the value of "y" is always 1, 2 or 3, then "x" is always initialized, but GCC doesn't know this. To
3380 suppress the warning, you need to provide a default case with assert(0) or similar code.
3381 This option also warns when a non-volatile automatic variable might be changed by a call to "longjmp". The
3382 compiler sees only the calls to "setjmp". It cannot know where "longjmp" will be called; in fact, a signal
3383 handler could call it at any point in the code. As a result, you may get a warning even when there is in
3384 fact no problem because "longjmp" cannot in fact be called at the place that would cause a problem.
3385 Some spurious warnings can be avoided if you declare all the functions you use that never return as
3386 "noreturn".
3387 This warning is enabled by -Wall or -Wextra.
3388 -Wunknown-pragmas
3389 Warn when a "#pragma" directive is encountered that is not understood by GCC. If this command-line option
3390 is used, warnings are even issued for unknown pragmas in system header files. This is not the case if the
3391 warnings are only enabled by the -Wall command-line option.
3392 -Wno-pragmas
3393 Do not warn about misuses of pragmas, such as incorrect parameters, invalid syntax, or conflicts between
3394 pragmas. See also -Wunknown-pragmas.
3395 -Wno-prio-ctor-dtor
3396 Do not warn if a priority from 0 to 100 is used for constructor or destructor. The use of constructor and
3397 destructor attributes allow you to assign a priority to the constructor/destructor to control its order of
3398 execution before "main" is called or after it returns. The priority values must be greater than 100 as the
3399 compiler reserves priority values between 0--100 for the implementation.
3400 -Wstrict-aliasing
3401 This option is only active when -fstrict-aliasing is active. It warns about code that might break the
3402 strict aliasing rules that the compiler is using for optimization. The warning does not catch all cases,
3403 but does attempt to catch the more common pitfalls. It is included in -Wall. It is equivalent to
3404 -Wstrict-aliasing=3
3405 -Wstrict-aliasing=n
3406 This option is only active when -fstrict-aliasing is active. It warns about code that might break the
3407 strict aliasing rules that the compiler is using for optimization. Higher levels correspond to higher
3408 accuracy (fewer false positives). Higher levels also correspond to more effort, similar to the way -O
3409 works. -Wstrict-aliasing is equivalent to -Wstrict-aliasing=3.
3410 Level 1: Most aggressive, quick, least accurate. Possibly useful when higher levels do not warn but
3411 -fstrict-aliasing still breaks the code, as it has very few false negatives. However, it has many false
3412 positives. Warns for all pointer conversions between possibly incompatible types, even if never
3413 dereferenced. Runs in the front end only.
3414 Level 2: Aggressive, quick, not too precise. May still have many false positives (not as many as level 1
3415 though), and few false negatives (but possibly more than level 1). Unlike level 1, it only warns when an
3416 address is taken. Warns about incomplete types. Runs in the front end only.
3417 Level 3 (default for -Wstrict-aliasing): Should have very few false positives and few false negatives.
3418 Slightly slower than levels 1 or 2 when optimization is enabled. Takes care of the common pun+dereference
3419 pattern in the front end: "*(int*)&some_float". If optimization is enabled, it also runs in the back end,
3420 where it deals with multiple statement cases using flow-sensitive points-to information. Only warns when
3421 the converted pointer is dereferenced. Does not warn about incomplete types.
3422 -Wstrict-overflow
3423 -Wstrict-overflow=n
3424 This option is only active when signed overflow is undefined. It warns about cases where the compiler
3425 optimizes based on the assumption that signed overflow does not occur. Note that it does not warn about
3426 all cases where the code might overflow: it only warns about cases where the compiler implements some
3427 optimization. Thus this warning depends on the optimization level.
3428 An optimization that assumes that signed overflow does not occur is perfectly safe if the values of the
3429 variables involved are such that overflow never does, in fact, occur. Therefore this warning can easily
3430 give a false positive: a warning about code that is not actually a problem. To help focus on important
3431 issues, several warning levels are defined. No warnings are issued for the use of undefined signed
3432 overflow when estimating how many iterations a loop requires, in particular when determining whether a loop
3433 will be executed at all.
3434 -Wstrict-overflow=1
3435 Warn about cases that are both questionable and easy to avoid. For example the compiler simplifies "x
3436 + 1 > x" to 1. This level of -Wstrict-overflow is enabled by -Wall; higher levels are not, and must be
3437 explicitly requested.
3438 -Wstrict-overflow=2
3439 Also warn about other cases where a comparison is simplified to a constant. For example: "abs (x) >=
3440 0". This can only be simplified when signed integer overflow is undefined, because "abs (INT_MIN)"
3441 overflows to "INT_MIN", which is less than zero. -Wstrict-overflow (with no level) is the same as
3442 -Wstrict-overflow=2.
3443 -Wstrict-overflow=3
3444 Also warn about other cases where a comparison is simplified. For example: "x + 1 > 1" is simplified
3445 to "x > 0".
3446 -Wstrict-overflow=4
3447 Also warn about other simplifications not covered by the above cases. For example: "(x * 10) / 5" is
3448 simplified to "x * 2".
3449 -Wstrict-overflow=5
3450 Also warn about cases where the compiler reduces the magnitude of a constant involved in a comparison.
3451 For example: "x + 2 > y" is simplified to "x + 1 >= y". This is reported only at the highest warning
3452 level because this simplification applies to many comparisons, so this warning level gives a very large
3453 number of false positives.
3454 -Wstring-compare
3455 Warn for calls to "strcmp" and "strncmp" whose result is determined to be either zero or non-zero in tests
3456 for such equality owing to the length of one argument being greater than the size of the array the other
3457 argument is stored in (or the bound in the case of "strncmp"). Such calls could be mistakes. For example,
3458 the call to "strcmp" below is diagnosed because its result is necessarily non-zero irrespective of the
3459 contents of the array "a".
3460 extern char a[4];
3461 void f (char *d)
3462 {
3463 strcpy (d, "string");
3464 ...
3465 if (0 == strcmp (a, d)) // cannot be true
3466 puts ("a and d are the same");
3467 }
3468 -Wstring-compare is enabled by -Wextra.
3469 -Wno-stringop-overflow
3470 -Wstringop-overflow
3471 -Wstringop-overflow=type
3472 Warn for calls to string manipulation functions such as "memcpy" and "strcpy" that are determined to
3473 overflow the destination buffer. The optional argument is one greater than the type of Object Size
3474 Checking to perform to determine the size of the destination. The argument is meaningful only for
3475 functions that operate on character arrays but not for raw memory functions like "memcpy" which always make
3476 use of Object Size type-0. The option also warns for calls that specify a size in excess of the largest
3477 possible object or at most "SIZE_MAX / 2" bytes. The option produces the best results with optimization
3478 enabled but can detect a small subset of simple buffer overflows even without optimization in calls to the
3479 GCC built-in functions like "__builtin_memcpy" that correspond to the standard functions. In any case, the
3480 option warns about just a subset of buffer overflows detected by the corresponding overflow checking built-
3481 ins. For example, the option issues a warning for the "strcpy" call below because it copies at least 5
3482 characters (the string "blue" including the terminating NUL) into the buffer of size 4.
3483 enum Color { blue, purple, yellow };
3484 const char* f (enum Color clr)
3485 {
3486 static char buf [4];
3487 const char *str;
3488 switch (clr)
3489 {
3490 case blue: str = "blue"; break;
3491 case purple: str = "purple"; break;
3492 case yellow: str = "yellow"; break;
3493 }
3494 return strcpy (buf, str); // warning here
3495 }
3496 Option -Wstringop-overflow=2 is enabled by default.
3497 -Wstringop-overflow
3498 -Wstringop-overflow=1
3499 The -Wstringop-overflow=1 option uses type-zero Object Size Checking to determine the sizes of
3500 destination objects. At this setting the option does not warn for writes past the end of subobjects of
3501 larger objects accessed by pointers unless the size of the largest surrounding object is known. When
3502 the destination may be one of several objects it is assumed to be the largest one of them. On Linux
3503 systems, when optimization is enabled at this setting the option warns for the same code as when the
3504 "_FORTIFY_SOURCE" macro is defined to a non-zero value.
3505 -Wstringop-overflow=2
3506 The -Wstringop-overflow=2 option uses type-one Object Size Checking to determine the sizes of
3507 destination objects. At this setting the option warns about overflows when writing to members of the
3508 largest complete objects whose exact size is known. However, it does not warn for excessive writes to
3509 the same members of unknown objects referenced by pointers since they may point to arrays containing
3510 unknown numbers of elements. This is the default setting of the option.
3511 -Wstringop-overflow=3
3512 The -Wstringop-overflow=3 option uses type-two Object Size Checking to determine the sizes of
3513 destination objects. At this setting the option warns about overflowing the smallest object or data
3514 member. This is the most restrictive setting of the option that may result in warnings for safe code.
3515 -Wstringop-overflow=4
3516 The -Wstringop-overflow=4 option uses type-three Object Size Checking to determine the sizes of
3517 destination objects. At this setting the option warns about overflowing any data members, and when the
3518 destination is one of several objects it uses the size of the largest of them to decide whether to
3519 issue a warning. Similarly to -Wstringop-overflow=3 this setting of the option may result in warnings
3520 for benign code.
3521 -Wno-stringop-overread
3522 Warn for calls to string manipulation functions such as "memchr", or "strcpy" that are determined to read
3523 past the end of the source sequence.
3524 Option -Wstringop-overread is enabled by default.
3525 -Wno-stringop-truncation
3526 Do not warn for calls to bounded string manipulation functions such as "strncat", "strncpy", and "stpncpy"
3527 that may either truncate the copied string or leave the destination unchanged.
3528 In the following example, the call to "strncat" specifies a bound that is less than the length of the
3529 source string. As a result, the copy of the source will be truncated and so the call is diagnosed. To
3530 avoid the warning use "bufsize - strlen (buf) - 1)" as the bound.
3531 void append (char *buf, size_t bufsize)
3532 {
3533 strncat (buf, ".txt", 3);
3534 }
3535 As another example, the following call to "strncpy" results in copying to "d" just the characters preceding
3536 the terminating NUL, without appending the NUL to the end. Assuming the result of "strncpy" is necessarily
3537 a NUL-terminated string is a common mistake, and so the call is diagnosed. To avoid the warning when the
3538 result is not expected to be NUL-terminated, call "memcpy" instead.
3539 void copy (char *d, const char *s)
3540 {
3541 strncpy (d, s, strlen (s));
3542 }
3543 In the following example, the call to "strncpy" specifies the size of the destination buffer as the bound.
3544 If the length of the source string is equal to or greater than this size the result of the copy will not be
3545 NUL-terminated. Therefore, the call is also diagnosed. To avoid the warning, specify "sizeof buf - 1" as
3546 the bound and set the last element of the buffer to "NUL".
3547 void copy (const char *s)
3548 {
3549 char buf[80];
3550 strncpy (buf, s, sizeof buf);
3551 ...
3552 }
3553 In situations where a character array is intended to store a sequence of bytes with no terminating "NUL"
3554 such an array may be annotated with attribute "nonstring" to avoid this warning. Such arrays, however, are
3555 not suitable arguments to functions that expect "NUL"-terminated strings. To help detect accidental
3556 misuses of such arrays GCC issues warnings unless it can prove that the use is safe.
3557 -Wsuggest-attribute=[pure|const|noreturn|format|cold|malloc]
3558 Warn for cases where adding an attribute may be beneficial. The attributes currently supported are listed
3559 below.
3560 -Wsuggest-attribute=pure
3561 -Wsuggest-attribute=const
3562 -Wsuggest-attribute=noreturn
3563 -Wmissing-noreturn
3564 -Wsuggest-attribute=malloc
3565 Warn about functions that might be candidates for attributes "pure", "const" or "noreturn" or "malloc".
3566 The compiler only warns for functions visible in other compilation units or (in the case of "pure" and
3567 "const") if it cannot prove that the function returns normally. A function returns normally if it
3568 doesn't contain an infinite loop or return abnormally by throwing, calling "abort" or trapping. This
3569 analysis requires option -fipa-pure-const, which is enabled by default at -O and higher. Higher
3570 optimization levels improve the accuracy of the analysis.
3571 -Wsuggest-attribute=format
3572 -Wmissing-format-attribute
3573 Warn about function pointers that might be candidates for "format" attributes. Note these are only
3574 possible candidates, not absolute ones. GCC guesses that function pointers with "format" attributes
3575 that are used in assignment, initialization, parameter passing or return statements should have a
3576 corresponding "format" attribute in the resulting type. I.e. the left-hand side of the assignment or
3577 initialization, the type of the parameter variable, or the return type of the containing function
3578 respectively should also have a "format" attribute to avoid the warning.
3579 GCC also warns about function definitions that might be candidates for "format" attributes. Again,
3580 these are only possible candidates. GCC guesses that "format" attributes might be appropriate for any
3581 function that calls a function like "vprintf" or "vscanf", but this might not always be the case, and
3582 some functions for which "format" attributes are appropriate may not be detected.
3583 -Wsuggest-attribute=cold
3584 Warn about functions that might be candidates for "cold" attribute. This is based on static detection
3585 and generally only warns about functions which always leads to a call to another "cold" function such
3586 as wrappers of C++ "throw" or fatal error reporting functions leading to "abort".
3587 -Walloc-zero
3588 Warn about calls to allocation functions decorated with attribute "alloc_size" that specify zero bytes,
3589 including those to the built-in forms of the functions "aligned_alloc", "alloca", "calloc", "malloc", and
3590 "realloc". Because the behavior of these functions when called with a zero size differs among
3591 implementations (and in the case of "realloc" has been deprecated) relying on it may result in subtle
3592 portability bugs and should be avoided.
3593 -Walloc-size-larger-than=byte-size
3594 Warn about calls to functions decorated with attribute "alloc_size" that attempt to allocate objects larger
3595 than the specified number of bytes, or where the result of the size computation in an integer type with
3596 infinite precision would exceed the value of PTRDIFF_MAX on the target.
3597 -Walloc-size-larger-than=PTRDIFF_MAX is enabled by default. Warnings controlled by the option can be
3598 disabled either by specifying byte-size of SIZE_MAX or more or by -Wno-alloc-size-larger-than.
3599 -Wno-alloc-size-larger-than
3600 Disable -Walloc-size-larger-than= warnings. The option is equivalent to -Walloc-size-larger-than=SIZE_MAX
3601 or larger.
3602 -Walloca
3603 This option warns on all uses of "alloca" in the source.
3604 -Walloca-larger-than=byte-size
3605 This option warns on calls to "alloca" with an integer argument whose value is either zero, or that is not
3606 bounded by a controlling predicate that limits its value to at most byte-size. It also warns for calls to
3607 "alloca" where the bound value is unknown. Arguments of non-integer types are considered unbounded even if
3608 they appear to be constrained to the expected range.
3609 For example, a bounded case of "alloca" could be:
3610 void func (size_t n)
3611 {
3612 void *p;
3613 if (n <= 1000)
3614 p = alloca (n);
3615 else
3616 p = malloc (n);
3617 f (p);
3618 }
3619 In the above example, passing "-Walloca-larger-than=1000" would not issue a warning because the call to
3620 "alloca" is known to be at most 1000 bytes. However, if "-Walloca-larger-than=500" were passed, the
3621 compiler would emit a warning.
3622 Unbounded uses, on the other hand, are uses of "alloca" with no controlling predicate constraining its
3623 integer argument. For example:
3624 void func ()
3625 {
3626 void *p = alloca (n);
3627 f (p);
3628 }
3629 If "-Walloca-larger-than=500" were passed, the above would trigger a warning, but this time because of the
3630 lack of bounds checking.
3631 Note, that even seemingly correct code involving signed integers could cause a warning:
3632 void func (signed int n)
3633 {
3634 if (n < 500)
3635 {
3636 p = alloca (n);
3637 f (p);
3638 }
3639 }
3640 In the above example, n could be negative, causing a larger than expected argument to be implicitly cast
3641 into the "alloca" call.
3642 This option also warns when "alloca" is used in a loop.
3643 -Walloca-larger-than=PTRDIFF_MAX is enabled by default but is usually only effective when -ftree-vrp is
3644 active (default for -O2 and above).
3645 See also -Wvla-larger-than=byte-size.
3646 -Wno-alloca-larger-than
3647 Disable -Walloca-larger-than= warnings. The option is equivalent to -Walloca-larger-than=SIZE_MAX or
3648 larger.
3649 -Warith-conversion
3650 Do warn about implicit conversions from arithmetic operations even when conversion of the operands to the
3651 same type cannot change their values. This affects warnings from -Wconversion, -Wfloat-conversion, and
3652 -Wsign-conversion.
3653 void f (char c, int i)
3654 {
3655 c = c + i; // warns with B<-Wconversion>
3656 c = c + 1; // only warns with B<-Warith-conversion>
3657 }
3658 -Warray-bounds
3659 -Warray-bounds=n
3660 This option is only active when -ftree-vrp is active (default for -O2 and above). It warns about subscripts
3661 to arrays that are always out of bounds. This warning is enabled by -Wall.
3662 -Warray-bounds=1
3663 This is the warning level of -Warray-bounds and is enabled by -Wall; higher levels are not, and must be
3664 explicitly requested.
3665 -Warray-bounds=2
3666 This warning level also warns about out of bounds access for arrays at the end of a struct and for
3667 arrays accessed through pointers. This warning level may give a larger number of false positives and is
3668 deactivated by default.
3669 -Warray-parameter
3670 -Warray-parameter=n
3671 Warn about redeclarations of functions involving arguments of array or pointer types of inconsistent kinds
3672 or forms, and enable the detection of out-of-bounds accesses to such parameters by warnings such as
3673 -Warray-bounds.
3674 If the first function declaration uses the array form the bound specified in the array is assumed to be the
3675 minimum number of elements expected to be provided in calls to the function and the maximum number of
3676 elements accessed by it. Failing to provide arguments of sufficient size or accessing more than the
3677 maximum number of elements may be diagnosed by warnings such as -Warray-bounds. At level 1 the warning
3678 diagnoses inconsistencies involving array parameters declared using the "T[static N]" form.
3679 For example, the warning triggers for the following redeclarations because the first one allows an array of
3680 any size to be passed to "f" while the second one with the keyword "static" specifies that the array
3681 argument must have at least four elements.
3682 void f (int[static 4]);
3683 void f (int[]); // warning (inconsistent array form)
3684 void g (void)
3685 {
3686 int *p = (int *)malloc (4);
3687 f (p); // warning (array too small)
3688 ...
3689 }
3690 At level 2 the warning also triggers for redeclarations involving any other inconsistency in array or
3691 pointer argument forms denoting array sizes. Pointers and arrays of unspecified bound are considered
3692 equivalent and do not trigger a warning.
3693 void g (int*);
3694 void g (int[]); // no warning
3695 void g (int[8]); // warning (inconsistent array bound)
3696 -Warray-parameter=2 is included in -Wall. The -Wvla-parameter option triggers warnings for similar
3697 inconsistencies involving Variable Length Array arguments.
3698 -Wattribute-alias=n
3699 -Wno-attribute-alias
3700 Warn about declarations using the "alias" and similar attributes whose target is incompatible with the type
3701 of the alias.
3702 -Wattribute-alias=1
3703 The default warning level of the -Wattribute-alias option diagnoses incompatibilities between the type
3704 of the alias declaration and that of its target. Such incompatibilities are typically indicative of
3705 bugs.
3706 -Wattribute-alias=2
3707 At this level -Wattribute-alias also diagnoses cases where the attributes of the alias declaration are
3708 more restrictive than the attributes applied to its target. These mismatches can potentially result in
3709 incorrect code generation. In other cases they may be benign and could be resolved simply by adding
3710 the missing attribute to the target. For comparison, see the -Wmissing-attributes option, which
3711 controls diagnostics when the alias declaration is less restrictive than the target, rather than more
3712 restrictive.
3713 Attributes considered include "alloc_align", "alloc_size", "cold", "const", "hot", "leaf", "malloc",
3714 "nonnull", "noreturn", "nothrow", "pure", "returns_nonnull", and "returns_twice".
3715 -Wattribute-alias is equivalent to -Wattribute-alias=1. This is the default. You can disable these
3716 warnings with either -Wno-attribute-alias or -Wattribute-alias=0.
3717 -Wbool-compare
3718 Warn about boolean expression compared with an integer value different from "true"/"false". For instance,
3719 the following comparison is always false:
3720 int n = 5;
3721 ...
3722 if ((n > 1) == 2) { ... }
3723 This warning is enabled by -Wall.
3724 -Wbool-operation
3725 Warn about suspicious operations on expressions of a boolean type. For instance, bitwise negation of a
3726 boolean is very likely a bug in the program. For C, this warning also warns about incrementing or
3727 decrementing a boolean, which rarely makes sense. (In C++, decrementing a boolean is always invalid.
3728 Incrementing a boolean is invalid in C++17, and deprecated otherwise.)
3729 This warning is enabled by -Wall.
3730 -Wduplicated-branches
3731 Warn when an if-else has identical branches. This warning detects cases like
3732 if (p != NULL)
3733 return 0;
3734 else
3735 return 0;
3736 It doesn't warn when both branches contain just a null statement. This warning also warn for conditional
3737 operators:
3738 int i = x ? *p : *p;
3739 -Wduplicated-cond
3740 Warn about duplicated conditions in an if-else-if chain. For instance, warn for the following code:
3741 if (p->q != NULL) { ... }
3742 else if (p->q != NULL) { ... }
3743 -Wframe-address
3744 Warn when the __builtin_frame_address or __builtin_return_address is called with an argument greater than
3745 0. Such calls may return indeterminate values or crash the program. The warning is included in -Wall.
3746 -Wno-discarded-qualifiers (C and Objective-C only)
3747 Do not warn if type qualifiers on pointers are being discarded. Typically, the compiler warns if a "const
3748 char *" variable is passed to a function that takes a "char *" parameter. This option can be used to
3749 suppress such a warning.
3750 -Wno-discarded-array-qualifiers (C and Objective-C only)
3751 Do not warn if type qualifiers on arrays which are pointer targets are being discarded. Typically, the
3752 compiler warns if a "const int (*)[]" variable is passed to a function that takes a "int (*)[]" parameter.
3753 This option can be used to suppress such a warning.
3754 -Wno-incompatible-pointer-types (C and Objective-C only)
3755 Do not warn when there is a conversion between pointers that have incompatible types. This warning is for
3756 cases not covered by -Wno-pointer-sign, which warns for pointer argument passing or assignment with
3757 different signedness.
3758 -Wno-int-conversion (C and Objective-C only)
3759 Do not warn about incompatible integer to pointer and pointer to integer conversions. This warning is
3760 about implicit conversions; for explicit conversions the warnings -Wno-int-to-pointer-cast and
3761 -Wno-pointer-to-int-cast may be used.
3762 -Wzero-length-bounds
3763 Warn about accesses to elements of zero-length array members that might overlap other members of the same
3764 object. Declaring interior zero-length arrays is discouraged because accesses to them are undefined. See
3765 For example, the first two stores in function "bad" are diagnosed because the array elements overlap the
3766 subsequent members "b" and "c". The third store is diagnosed by -Warray-bounds because it is beyond the
3767 bounds of the enclosing object.
3768 struct X { int a[0]; int b, c; };
3769 struct X x;
3770 void bad (void)
3771 {
3772 x.a[0] = 0; // -Wzero-length-bounds
3773 x.a[1] = 1; // -Wzero-length-bounds
3774 x.a[2] = 2; // -Warray-bounds
3775 }
3776 Option -Wzero-length-bounds is enabled by -Warray-bounds.
3777 -Wno-div-by-zero
3778 Do not warn about compile-time integer division by zero. Floating-point division by zero is not warned
3779 about, as it can be a legitimate way of obtaining infinities and NaNs.
3780 -Wsystem-headers
3781 Print warning messages for constructs found in system header files. Warnings from system headers are
3782 normally suppressed, on the assumption that they usually do not indicate real problems and would only make
3783 the compiler output harder to read. Using this command-line option tells GCC to emit warnings from system
3784 headers as if they occurred in user code. However, note that using -Wall in conjunction with this option
3785 does not warn about unknown pragmas in system headers---for that, -Wunknown-pragmas must also be used.
3786 -Wtautological-compare
3787 Warn if a self-comparison always evaluates to true or false. This warning detects various mistakes such
3788 as:
3789 int i = 1;
3790 ...
3791 if (i > i) { ... }
3792 This warning also warns about bitwise comparisons that always evaluate to true or false, for instance:
3793 if ((a & 16) == 10) { ... }
3794 will always be false.
3795 This warning is enabled by -Wall.
3796 -Wtrampolines
3797 Warn about trampolines generated for pointers to nested functions. A trampoline is a small piece of data
3798 or code that is created at run time on the stack when the address of a nested function is taken, and is
3799 used to call the nested function indirectly. For some targets, it is made up of data only and thus
3800 requires no special treatment. But, for most targets, it is made up of code and thus requires the stack to
3801 be made executable in order for the program to work properly.
3802 -Wfloat-equal
3803 Warn if floating-point values are used in equality comparisons.
3804 The idea behind this is that sometimes it is convenient (for the programmer) to consider floating-point
3805 values as approximations to infinitely precise real numbers. If you are doing this, then you need to
3806 compute (by analyzing the code, or in some other way) the maximum or likely maximum error that the
3807 computation introduces, and allow for it when performing comparisons (and when producing output, but that's
3808 a different problem). In particular, instead of testing for equality, you should check to see whether the
3809 two values have ranges that overlap; and this is done with the relational operators, so equality
3810 comparisons are probably mistaken.
3811 -Wtraditional (C and Objective-C only)
3812 Warn about certain constructs that behave differently in traditional and ISO C. Also warn about ISO C
3813 constructs that have no traditional C equivalent, and/or problematic constructs that should be avoided.
3814 * Macro parameters that appear within string literals in the macro body. In traditional C macro
3815 replacement takes place within string literals, but in ISO C it does not.
3816 * In traditional C, some preprocessor directives did not exist. Traditional preprocessors only
3817 considered a line to be a directive if the # appeared in column 1 on the line. Therefore -Wtraditional
3818 warns about directives that traditional C understands but ignores because the # does not appear as the
3819 first character on the line. It also suggests you hide directives like "#pragma" not understood by
3820 traditional C by indenting them. Some traditional implementations do not recognize "#elif", so this
3821 option suggests avoiding it altogether.
3822 * A function-like macro that appears without arguments.
3823 * The unary plus operator.
3824 * The U integer constant suffix, or the F or L floating-point constant suffixes. (Traditional C does
3825 support the L suffix on integer constants.) Note, these suffixes appear in macros defined in the
3826 system headers of most modern systems, e.g. the _MIN/_MAX macros in "<limits.h>". Use of these macros
3827 in user code might normally lead to spurious warnings, however GCC's integrated preprocessor has enough
3828 context to avoid warning in these cases.
3829 * A function declared external in one block and then used after the end of the block.
3830 * A "switch" statement has an operand of type "long".
3831 * A non-"static" function declaration follows a "static" one. This construct is not accepted by some
3832 traditional C compilers.
3833 * The ISO type of an integer constant has a different width or signedness from its traditional type.
3834 This warning is only issued if the base of the constant is ten. I.e. hexadecimal or octal values,
3835 which typically represent bit patterns, are not warned about.
3836 * Usage of ISO string concatenation is detected.
3837 * Initialization of automatic aggregates.
3838 * Identifier conflicts with labels. Traditional C lacks a separate namespace for labels.
3839 * Initialization of unions. If the initializer is zero, the warning is omitted. This is done under the
3840 assumption that the zero initializer in user code appears conditioned on e.g. "__STDC__" to avoid
3841 missing initializer warnings and relies on default initialization to zero in the traditional C case.
3842 * Conversions by prototypes between fixed/floating-point values and vice versa. The absence of these
3843 prototypes when compiling with traditional C causes serious problems. This is a subset of the possible
3844 conversion warnings; for the full set use -Wtraditional-conversion.
3845 * Use of ISO C style function definitions. This warning intentionally is not issued for prototype
3846 declarations or variadic functions because these ISO C features appear in your code when using
3847 libiberty's traditional C compatibility macros, "PARAMS" and "VPARAMS". This warning is also bypassed
3848 for nested functions because that feature is already a GCC extension and thus not relevant to
3849 traditional C compatibility.
3850 -Wtraditional-conversion (C and Objective-C only)
3851 Warn if a prototype causes a type conversion that is different from what would happen to the same argument
3852 in the absence of a prototype. This includes conversions of fixed point to floating and vice versa, and
3853 conversions changing the width or signedness of a fixed-point argument except when the same as the default
3854 promotion.
3855 -Wdeclaration-after-statement (C and Objective-C only)
3856 Warn when a declaration is found after a statement in a block. This construct, known from C++, was
3857 introduced with ISO C99 and is by default allowed in GCC. It is not supported by ISO C90.
3858 -Wshadow
3859 Warn whenever a local variable or type declaration shadows another variable, parameter, type, class member
3860 (in C++), or instance variable (in Objective-C) or whenever a built-in function is shadowed. Note that in
3861 C++, the compiler warns if a local variable shadows an explicit typedef, but not if it shadows a
3862 struct/class/enum. If this warning is enabled, it includes also all instances of local shadowing. This
3863 means that -Wno-shadow=local and -Wno-shadow=compatible-local are ignored when -Wshadow is used. Same as
3864 -Wshadow=global.
3865 -Wno-shadow-ivar (Objective-C only)
3866 Do not warn whenever a local variable shadows an instance variable in an Objective-C method.
3867 -Wshadow=global
3868 Warn for any shadowing. Same as -Wshadow.
3869 -Wshadow=local
3870 Warn when a local variable shadows another local variable or parameter.
3871 -Wshadow=compatible-local
3872 Warn when a local variable shadows another local variable or parameter whose type is compatible with that
3873 of the shadowing variable. In C++, type compatibility here means the type of the shadowing variable can be
3874 converted to that of the shadowed variable. The creation of this flag (in addition to -Wshadow=local) is
3875 based on the idea that when a local variable shadows another one of incompatible type, it is most likely
3876 intentional, not a bug or typo, as shown in the following example:
3877 for (SomeIterator i = SomeObj.begin(); i != SomeObj.end(); ++i)
3878 {
3879 for (int i = 0; i < N; ++i)
3880 {
3881 ...
3882 }
3883 ...
3884 }
3885 Since the two variable "i" in the example above have incompatible types, enabling only
3886 -Wshadow=compatible-local does not emit a warning. Because their types are incompatible, if a programmer
3887 accidentally uses one in place of the other, type checking is expected to catch that and emit an error or
3888 warning. Use of this flag instead of -Wshadow=local can possibly reduce the number of warnings triggered
3889 by intentional shadowing. Note that this also means that shadowing "const char *i" by "char *i" does not
3890 emit a warning.
3891 This warning is also enabled by -Wshadow=local.
3892 -Wlarger-than=byte-size
3893 Warn whenever an object is defined whose size exceeds byte-size. -Wlarger-than=PTRDIFF_MAX is enabled by
3894 default. Warnings controlled by the option can be disabled either by specifying byte-size of SIZE_MAX or
3895 more or by -Wno-larger-than.
3896 Also warn for calls to bounded functions such as "memchr" or "strnlen" that specify a bound greater than
3897 the largest possible object, which is PTRDIFF_MAX bytes by default. These warnings can only be disabled by
3898 -Wno-larger-than.
3899 -Wno-larger-than
3900 Disable -Wlarger-than= warnings. The option is equivalent to -Wlarger-than=SIZE_MAX or larger.
3901 -Wframe-larger-than=byte-size
3902 Warn if the size of a function frame exceeds byte-size. The computation done to determine the stack frame
3903 size is approximate and not conservative. The actual requirements may be somewhat greater than byte-size
3904 even if you do not get a warning. In addition, any space allocated via "alloca", variable-length arrays,
3905 or related constructs is not included by the compiler when determining whether or not to issue a warning.
3906 -Wframe-larger-than=PTRDIFF_MAX is enabled by default. Warnings controlled by the option can be disabled
3907 either by specifying byte-size of SIZE_MAX or more or by -Wno-frame-larger-than.
3908 -Wno-frame-larger-than
3909 Disable -Wframe-larger-than= warnings. The option is equivalent to -Wframe-larger-than=SIZE_MAX or larger.
3910 -Wno-free-nonheap-object
3911 Warn when attempting to deallocate an object that was either not allocated on the heap, or by using a
3912 pointer that was not returned from a prior call to the corresponding allocation function. For example,
3913 because the call to "stpcpy" returns a pointer to the terminating nul character and not to the begginning
3914 of the object, the call to "free" below is diagnosed.
3915 void f (char *p)
3916 {
3917 p = stpcpy (p, "abc");
3918 // ...
3919 free (p); // warning
3920 }
3921 -Wfree-nonheap-object is enabled by default.
3922 -Wstack-usage=byte-size
3923 Warn if the stack usage of a function might exceed byte-size. The computation done to determine the stack
3924 usage is conservative. Any space allocated via "alloca", variable-length arrays, or related constructs is
3925 included by the compiler when determining whether or not to issue a warning.
3926 The message is in keeping with the output of -fstack-usage.
3927 * If the stack usage is fully static but exceeds the specified amount, it's:
3928 warning: stack usage is 1120 bytes
3929 * If the stack usage is (partly) dynamic but bounded, it's:
3930 warning: stack usage might be 1648 bytes
3931 * If the stack usage is (partly) dynamic and not bounded, it's:
3932 warning: stack usage might be unbounded
3933 -Wstack-usage=PTRDIFF_MAX is enabled by default. Warnings controlled by the option can be disabled either
3934 by specifying byte-size of SIZE_MAX or more or by -Wno-stack-usage.
3935 -Wno-stack-usage
3936 Disable -Wstack-usage= warnings. The option is equivalent to -Wstack-usage=SIZE_MAX or larger.
3937 -Wunsafe-loop-optimizations
3938 Warn if the loop cannot be optimized because the compiler cannot assume anything on the bounds of the loop
3939 indices. With -funsafe-loop-optimizations warn if the compiler makes such assumptions.
3940 -Wno-pedantic-ms-format (MinGW targets only)
3941 When used in combination with -Wformat and -pedantic without GNU extensions, this option disables the
3942 warnings about non-ISO "printf" / "scanf" format width specifiers "I32", "I64", and "I" used on Windows
3943 targets, which depend on the MS runtime.
3944 -Wpointer-arith
3945 Warn about anything that depends on the "size of" a function type or of "void". GNU C assigns these types
3946 a size of 1, for convenience in calculations with "void *" pointers and pointers to functions. In C++,
3947 warn also when an arithmetic operation involves "NULL". This warning is also enabled by -Wpedantic.
3948 -Wno-pointer-compare
3949 Do not warn if a pointer is compared with a zero character constant. This usually means that the pointer
3950 was meant to be dereferenced. For example:
3951 const char *p = foo ();
3952 if (p == '\0')
3953 return 42;
3954 Note that the code above is invalid in C++11.
3955 This warning is enabled by default.
3956 -Wtsan
3957 Warn about unsupported features in ThreadSanitizer.
3958 ThreadSanitizer does not support "std::atomic_thread_fence" and can report false positives.
3959 This warning is enabled by default.
3960 -Wtype-limits
3961 Warn if a comparison is always true or always false due to the limited range of the data type, but do not
3962 warn for constant expressions. For example, warn if an unsigned variable is compared against zero with "<"
3963 or ">=". This warning is also enabled by -Wextra.
3964 -Wabsolute-value (C and Objective-C only)
3965 Warn for calls to standard functions that compute the absolute value of an argument when a more appropriate
3966 standard function is available. For example, calling "abs(3.14)" triggers the warning because the
3967 appropriate function to call to compute the absolute value of a double argument is "fabs". The option also
3968 triggers warnings when the argument in a call to such a function has an unsigned type. This warning can be
3969 suppressed with an explicit type cast and it is also enabled by -Wextra.
3970 -Wcomment
3971 -Wcomments
3972 Warn whenever a comment-start sequence /* appears in a /* comment, or whenever a backslash-newline appears
3973 in a // comment. This warning is enabled by -Wall.
3974 -Wtrigraphs
3975 Warn if any trigraphs are encountered that might change the meaning of the program. Trigraphs within
3976 comments are not warned about, except those that would form escaped newlines.
3977 This option is implied by -Wall. If -Wall is not given, this option is still enabled unless trigraphs are
3978 enabled. To get trigraph conversion without warnings, but get the other -Wall warnings, use -trigraphs
3979 -Wall -Wno-trigraphs.
3980 -Wundef
3981 Warn if an undefined identifier is evaluated in an "#if" directive. Such identifiers are replaced with
3982 zero.
3983 -Wexpansion-to-defined
3984 Warn whenever defined is encountered in the expansion of a macro (including the case where the macro is
3985 expanded by an #if directive). Such usage is not portable. This warning is also enabled by -Wpedantic and
3986 -Wextra.
3987 -Wunused-macros
3988 Warn about macros defined in the main file that are unused. A macro is used if it is expanded or tested
3989 for existence at least once. The preprocessor also warns if the macro has not been used at the time it is
3990 redefined or undefined.
3991 Built-in macros, macros defined on the command line, and macros defined in include files are not warned
3992 about.
3993 Note: If a macro is actually used, but only used in skipped conditional blocks, then the preprocessor
3994 reports it as unused. To avoid the warning in such a case, you might improve the scope of the macro's
3995 definition by, for example, moving it into the first skipped block. Alternatively, you could provide a
3996 dummy use with something like:
3997 #if defined the_macro_causing_the_warning
3998 #endif
3999 -Wno-endif-labels
4000 Do not warn whenever an "#else" or an "#endif" are followed by text. This sometimes happens in older
4001 programs with code of the form
4002 #if FOO
4003 ...
4004 #else FOO
4005 ...
4006 #endif FOO
4007 The second and third "FOO" should be in comments. This warning is on by default.
4008 -Wbad-function-cast (C and Objective-C only)
4009 Warn when a function call is cast to a non-matching type. For example, warn if a call to a function
4010 returning an integer type is cast to a pointer type.
4011 -Wc90-c99-compat (C and Objective-C only)
4012 Warn about features not present in ISO C90, but present in ISO C99. For instance, warn about use of
4013 variable length arrays, "long long" type, "bool" type, compound literals, designated initializers, and so
4014 on. This option is independent of the standards mode. Warnings are disabled in the expression that
4015 follows "__extension__".
4016 -Wc99-c11-compat (C and Objective-C only)
4017 Warn about features not present in ISO C99, but present in ISO C11. For instance, warn about use of
4018 anonymous structures and unions, "_Atomic" type qualifier, "_Thread_local" storage-class specifier,
4019 "_Alignas" specifier, "Alignof" operator, "_Generic" keyword, and so on. This option is independent of the
4020 standards mode. Warnings are disabled in the expression that follows "__extension__".
4021 -Wc11-c2x-compat (C and Objective-C only)
4022 Warn about features not present in ISO C11, but present in ISO C2X. For instance, warn about omitting the
4023 string in "_Static_assert", use of [[]] syntax for attributes, use of decimal floating-point types, and so
4024 on. This option is independent of the standards mode. Warnings are disabled in the expression that
4025 follows "__extension__".
4026 -Wc++-compat (C and Objective-C only)
4027 Warn about ISO C constructs that are outside of the common subset of ISO C and ISO C++, e.g. request for
4028 implicit conversion from "void *" to a pointer to non-"void" type.
4029 -Wc++11-compat (C++ and Objective-C++ only)
4030 Warn about C++ constructs whose meaning differs between ISO C++ 1998 and ISO C++ 2011, e.g., identifiers in
4031 ISO C++ 1998 that are keywords in ISO C++ 2011. This warning turns on -Wnarrowing and is enabled by -Wall.
4032 -Wc++14-compat (C++ and Objective-C++ only)
4033 Warn about C++ constructs whose meaning differs between ISO C++ 2011 and ISO C++ 2014. This warning is
4034 enabled by -Wall.
4035 -Wc++17-compat (C++ and Objective-C++ only)
4036 Warn about C++ constructs whose meaning differs between ISO C++ 2014 and ISO C++ 2017. This warning is
4037 enabled by -Wall.
4038 -Wc++20-compat (C++ and Objective-C++ only)
4039 Warn about C++ constructs whose meaning differs between ISO C++ 2017 and ISO C++ 2020. This warning is
4040 enabled by -Wall.
4041 -Wcast-qual
4042 Warn whenever a pointer is cast so as to remove a type qualifier from the target type. For example, warn
4043 if a "const char *" is cast to an ordinary "char *".
4044 Also warn when making a cast that introduces a type qualifier in an unsafe way. For example, casting "char
4045 **" to "const char **" is unsafe, as in this example:
4046 /* p is char ** value. */
4047 const char **q = (const char **) p;
4048 /* Assignment of readonly string to const char * is OK. */
4049 *q = "string";
4050 /* Now char** pointer points to read-only memory. */
4051 **p = 'b';
4052 -Wcast-align
4053 Warn whenever a pointer is cast such that the required alignment of the target is increased. For example,
4054 warn if a "char *" is cast to an "int *" on machines where integers can only be accessed at two- or four-
4055 byte boundaries.
4056 -Wcast-align=strict
4057 Warn whenever a pointer is cast such that the required alignment of the target is increased. For example,
4058 warn if a "char *" is cast to an "int *" regardless of the target machine.
4059 -Wcast-function-type
4060 Warn when a function pointer is cast to an incompatible function pointer. In a cast involving function
4061 types with a variable argument list only the types of initial arguments that are provided are considered.
4062 Any parameter of pointer-type matches any other pointer-type. Any benign differences in integral types are
4063 ignored, like "int" vs. "long" on ILP32 targets. Likewise type qualifiers are ignored. The function type
4064 "void (*) (void)" is special and matches everything, which can be used to suppress this warning. In a cast
4065 involving pointer to member types this warning warns whenever the type cast is changing the pointer to
4066 member type. This warning is enabled by -Wextra.
4067 -Wwrite-strings
4068 When compiling C, give string constants the type "const char[length]" so that copying the address of one
4069 into a non-"const" "char *" pointer produces a warning. These warnings help you find at compile time code
4070 that can try to write into a string constant, but only if you have been very careful about using "const" in
4071 declarations and prototypes. Otherwise, it is just a nuisance. This is why we did not make -Wall request
4072 these warnings.
4073 When compiling C++, warn about the deprecated conversion from string literals to "char *". This warning is
4074 enabled by default for C++ programs.
4075 -Wclobbered
4076 Warn for variables that might be changed by "longjmp" or "vfork". This warning is also enabled by -Wextra.
4077 -Wconversion
4078 Warn for implicit conversions that may alter a value. This includes conversions between real and integer,
4079 like "abs (x)" when "x" is "double"; conversions between signed and unsigned, like "unsigned ui = -1"; and
4080 conversions to smaller types, like "sqrtf (M_PI)". Do not warn for explicit casts like "abs ((int) x)" and
4081 "ui = (unsigned) -1", or if the value is not changed by the conversion like in "abs (2.0)". Warnings about
4082 conversions between signed and unsigned integers can be disabled by using -Wno-sign-conversion.
4083 For C++, also warn for confusing overload resolution for user-defined conversions; and conversions that
4084 never use a type conversion operator: conversions to "void", the same type, a base class or a reference to
4085 them. Warnings about conversions between signed and unsigned integers are disabled by default in C++ unless
4086 -Wsign-conversion is explicitly enabled.
4087 Warnings about conversion from arithmetic on a small type back to that type are only given with
4088 -Warith-conversion.
4089 -Wdangling-else
4090 Warn about constructions where there may be confusion to which "if" statement an "else" branch belongs.
4091 Here is an example of such a case:
4092 {
4093 if (a)
4094 if (b)
4095 foo ();
4096 else
4097 bar ();
4098 }
4099 In C/C++, every "else" branch belongs to the innermost possible "if" statement, which in this example is
4100 "if (b)". This is often not what the programmer expected, as illustrated in the above example by
4101 indentation the programmer chose. When there is the potential for this confusion, GCC issues a warning
4102 when this flag is specified. To eliminate the warning, add explicit braces around the innermost "if"
4103 statement so there is no way the "else" can belong to the enclosing "if". The resulting code looks like
4104 this:
4105 {
4106 if (a)
4107 {
4108 if (b)
4109 foo ();
4110 else
4111 bar ();
4112 }
4113 }
4114 This warning is enabled by -Wparentheses.
4115 -Wdate-time
4116 Warn when macros "__TIME__", "__DATE__" or "__TIMESTAMP__" are encountered as they might prevent bit-wise-
4117 identical reproducible compilations.
4118 -Wempty-body
4119 Warn if an empty body occurs in an "if", "else" or "do while" statement. This warning is also enabled by
4120 -Wextra.
4121 -Wno-endif-labels
4122 Do not warn about stray tokens after "#else" and "#endif".
4123 -Wenum-compare
4124 Warn about a comparison between values of different enumerated types. In C++ enumerated type mismatches in
4125 conditional expressions are also diagnosed and the warning is enabled by default. In C this warning is
4126 enabled by -Wall.
4127 -Wenum-conversion
4128 Warn when a value of enumerated type is implicitly converted to a different enumerated type. This warning
4129 is enabled by -Wextra in C.
4130 -Wjump-misses-init (C, Objective-C only)
4131 Warn if a "goto" statement or a "switch" statement jumps forward across the initialization of a variable,
4132 or jumps backward to a label after the variable has been initialized. This only warns about variables that
4133 are initialized when they are declared. This warning is only supported for C and Objective-C; in C++ this
4134 sort of branch is an error in any case.
4135 -Wjump-misses-init is included in -Wc++-compat. It can be disabled with the -Wno-jump-misses-init option.
4136 -Wsign-compare
4137 Warn when a comparison between signed and unsigned values could produce an incorrect result when the signed
4138 value is converted to unsigned. In C++, this warning is also enabled by -Wall. In C, it is also enabled
4139 by -Wextra.
4140 -Wsign-conversion
4141 Warn for implicit conversions that may change the sign of an integer value, like assigning a signed integer
4142 expression to an unsigned integer variable. An explicit cast silences the warning. In C, this option is
4143 enabled also by -Wconversion.
4144 -Wfloat-conversion
4145 Warn for implicit conversions that reduce the precision of a real value. This includes conversions from
4146 real to integer, and from higher precision real to lower precision real values. This option is also
4147 enabled by -Wconversion.
4148 -Wno-scalar-storage-order
4149 Do not warn on suspicious constructs involving reverse scalar storage order.
4150 -Wsizeof-array-div
4151 Warn about divisions of two sizeof operators when the first one is applied to an array and the divisor does
4152 not equal the size of the array element. In such a case, the computation will not yield the number of
4153 elements in the array, which is likely what the user intended. This warning warns e.g. about
4154 int fn ()
4155 {
4156 int arr[10];
4157 return sizeof (arr) / sizeof (short);
4158 }
4159 This warning is enabled by -Wall.
4160 -Wsizeof-pointer-div
4161 Warn for suspicious divisions of two sizeof expressions that divide the pointer size by the element size,
4162 which is the usual way to compute the array size but won't work out correctly with pointers. This warning
4163 warns e.g. about "sizeof (ptr) / sizeof (ptr[0])" if "ptr" is not an array, but a pointer. This warning is
4164 enabled by -Wall.
4165 -Wsizeof-pointer-memaccess
4166 Warn for suspicious length parameters to certain string and memory built-in functions if the argument uses
4167 "sizeof". This warning triggers for example for "memset (ptr, 0, sizeof (ptr));" if "ptr" is not an array,
4168 but a pointer, and suggests a possible fix, or about "memcpy (&foo, ptr, sizeof (&foo));".
4169 -Wsizeof-pointer-memaccess also warns about calls to bounded string copy functions like "strncat" or
4170 "strncpy" that specify as the bound a "sizeof" expression of the source array. For example, in the
4171 following function the call to "strncat" specifies the size of the source string as the bound. That is
4172 almost certainly a mistake and so the call is diagnosed.
4173 void make_file (const char *name)
4174 {
4175 char path[PATH_MAX];
4176 strncpy (path, name, sizeof path - 1);
4177 strncat (path, ".text", sizeof ".text");
4178 ...
4179 }
4180 The -Wsizeof-pointer-memaccess option is enabled by -Wall.
4181 -Wno-sizeof-array-argument
4182 Do not warn when the "sizeof" operator is applied to a parameter that is declared as an array in a function
4183 definition. This warning is enabled by default for C and C++ programs.
4184 -Wmemset-elt-size
4185 Warn for suspicious calls to the "memset" built-in function, if the first argument references an array, and
4186 the third argument is a number equal to the number of elements, but not equal to the size of the array in
4187 memory. This indicates that the user has omitted a multiplication by the element size. This warning is
4188 enabled by -Wall.
4189 -Wmemset-transposed-args
4190 Warn for suspicious calls to the "memset" built-in function where the second argument is not zero and the
4191 third argument is zero. For example, the call "memset (buf, sizeof buf, 0)" is diagnosed because "memset
4192 (buf, 0, sizeof buf)" was meant instead. The diagnostic is only emitted if the third argument is a literal
4193 zero. Otherwise, if it is an expression that is folded to zero, or a cast of zero to some type, it is far
4194 less likely that the arguments have been mistakenly transposed and no warning is emitted. This warning is
4195 enabled by -Wall.
4196 -Waddress
4197 Warn about suspicious uses of memory addresses. These include using the address of a function in a
4198 conditional expression, such as "void func(void); if (func)", and comparisons against the memory address of
4199 a string literal, such as "if (x == "abc")". Such uses typically indicate a programmer error: the address
4200 of a function always evaluates to true, so their use in a conditional usually indicate that the programmer
4201 forgot the parentheses in a function call; and comparisons against string literals result in unspecified
4202 behavior and are not portable in C, so they usually indicate that the programmer intended to use "strcmp".
4203 This warning is enabled by -Wall.
4204 -Wno-address-of-packed-member
4205 Do not warn when the address of packed member of struct or union is taken, which usually results in an
4206 unaligned pointer value. This is enabled by default.
4207 -Wlogical-op
4208 Warn about suspicious uses of logical operators in expressions. This includes using logical operators in
4209 contexts where a bit-wise operator is likely to be expected. Also warns when the operands of a logical
4210 operator are the same:
4211 extern int a;
4212 if (a < 0 && a < 0) { ... }
4213 -Wlogical-not-parentheses
4214 Warn about logical not used on the left hand side operand of a comparison. This option does not warn if
4215 the right operand is considered to be a boolean expression. Its purpose is to detect suspicious code like
4216 the following:
4217 int a;
4218 ...
4219 if (!a > 1) { ... }
4220 It is possible to suppress the warning by wrapping the LHS into parentheses:
4221 if ((!a) > 1) { ... }
4222 This warning is enabled by -Wall.
4223 -Waggregate-return
4224 Warn if any functions that return structures or unions are defined or called. (In languages where you can
4225 return an array, this also elicits a warning.)
4226 -Wno-aggressive-loop-optimizations
4227 Warn if in a loop with constant number of iterations the compiler detects undefined behavior in some
4228 statement during one or more of the iterations.
4229 -Wno-attributes
4230 Do not warn if an unexpected "__attribute__" is used, such as unrecognized attributes, function attributes
4231 applied to variables, etc. This does not stop errors for incorrect use of supported attributes.
4232 -Wno-builtin-declaration-mismatch
4233 Warn if a built-in function is declared with an incompatible signature or as a non-function, or when a
4234 built-in function declared with a type that does not include a prototype is called with arguments whose
4235 promoted types do not match those expected by the function. When -Wextra is specified, also warn when a
4236 built-in function that takes arguments is declared without a prototype. The -Wbuiltin-declaration-mismatch
4237 warning is enabled by default. To avoid the warning include the appropriate header to bring the prototypes
4238 of built-in functions into scope.
4239 For example, the call to "memset" below is diagnosed by the warning because the function expects a value of
4240 type "size_t" as its argument but the type of 32 is "int". With -Wextra, the declaration of the function
4241 is diagnosed as well.
4242 extern void* memset ();
4243 void f (void *d)
4244 {
4245 memset (d, '\0', 32);
4246 }
4247 -Wno-builtin-macro-redefined
4248 Do not warn if certain built-in macros are redefined. This suppresses warnings for redefinition of
4249 "__TIMESTAMP__", "__TIME__", "__DATE__", "__FILE__", and "__BASE_FILE__".
4250 -Wstrict-prototypes (C and Objective-C only)
4251 Warn if a function is declared or defined without specifying the argument types. (An old-style function
4252 definition is permitted without a warning if preceded by a declaration that specifies the argument types.)
4253 -Wold-style-declaration (C and Objective-C only)
4254 Warn for obsolescent usages, according to the C Standard, in a declaration. For example, warn if storage-
4255 class specifiers like "static" are not the first things in a declaration. This warning is also enabled by
4256 -Wextra.
4257 -Wold-style-definition (C and Objective-C only)
4258 Warn if an old-style function definition is used. A warning is given even if there is a previous
4259 prototype. A definition using () is not considered an old-style definition in C2X mode, because it is
4260 equivalent to (void) in that case, but is considered an old-style definition for older standards.
4261 -Wmissing-parameter-type (C and Objective-C only)
4262 A function parameter is declared without a type specifier in K&R-style functions:
4263 void foo(bar) { }
4264 This warning is also enabled by -Wextra.
4265 -Wmissing-prototypes (C and Objective-C only)
4266 Warn if a global function is defined without a previous prototype declaration. This warning is issued even
4267 if the definition itself provides a prototype. Use this option to detect global functions that do not have
4268 a matching prototype declaration in a header file. This option is not valid for C++ because all function
4269 declarations provide prototypes and a non-matching declaration declares an overload rather than conflict
4270 with an earlier declaration. Use -Wmissing-declarations to detect missing declarations in C++.
4271 -Wmissing-declarations
4272 Warn if a global function is defined without a previous declaration. Do so even if the definition itself
4273 provides a prototype. Use this option to detect global functions that are not declared in header files.
4274 In C, no warnings are issued for functions with previous non-prototype declarations; use
4275 -Wmissing-prototypes to detect missing prototypes. In C++, no warnings are issued for function templates,
4276 or for inline functions, or for functions in anonymous namespaces.
4277 -Wmissing-field-initializers
4278 Warn if a structure's initializer has some fields missing. For example, the following code causes such a
4279 warning, because "x.h" is implicitly zero:
4280 struct s { int f, g, h; };
4281 struct s x = { 3, 4 };
4282 This option does not warn about designated initializers, so the following modification does not trigger a
4283 warning:
4284 struct s { int f, g, h; };
4285 struct s x = { .f = 3, .g = 4 };
4286 In C this option does not warn about the universal zero initializer { 0 }:
4287 struct s { int f, g, h; };
4288 struct s x = { 0 };
4289 Likewise, in C++ this option does not warn about the empty { } initializer, for example:
4290 struct s { int f, g, h; };
4291 s x = { };
4292 This warning is included in -Wextra. To get other -Wextra warnings without this one, use -Wextra
4293 -Wno-missing-field-initializers.
4294 -Wno-multichar
4295 Do not warn if a multicharacter constant ('FOOF') is used. Usually they indicate a typo in the user's
4296 code, as they have implementation-defined values, and should not be used in portable code.
4297 -Wnormalized=[none|id|nfc|nfkc]
4298 In ISO C and ISO C++, two identifiers are different if they are different sequences of characters.
4299 However, sometimes when characters outside the basic ASCII character set are used, you can have two
4300 different character sequences that look the same. To avoid confusion, the ISO 10646 standard sets out some
4301 normalization rules which when applied ensure that two sequences that look the same are turned into the
4302 same sequence. GCC can warn you if you are using identifiers that have not been normalized; this option
4303 controls that warning.
4304 There are four levels of warning supported by GCC. The default is -Wnormalized=nfc, which warns about any
4305 identifier that is not in the ISO 10646 "C" normalized form, NFC. NFC is the recommended form for most
4306 uses. It is equivalent to -Wnormalized.
4307 Unfortunately, there are some characters allowed in identifiers by ISO C and ISO C++ that, when turned into
4308 NFC, are not allowed in identifiers. That is, there's no way to use these symbols in portable ISO C or C++
4309 and have all your identifiers in NFC. -Wnormalized=id suppresses the warning for these characters. It is
4310 hoped that future versions of the standards involved will correct this, which is why this option is not the
4311 default.
4312 You can switch the warning off for all characters by writing -Wnormalized=none or -Wno-normalized. You
4313 should only do this if you are using some other normalization scheme (like "D"), because otherwise you can
4314 easily create bugs that are literally impossible to see.
4315 Some characters in ISO 10646 have distinct meanings but look identical in some fonts or display
4316 methodologies, especially once formatting has been applied. For instance "\u207F", "SUPERSCRIPT LATIN
4317 SMALL LETTER N", displays just like a regular "n" that has been placed in a superscript. ISO 10646 defines
4318 the NFKC normalization scheme to convert all these into a standard form as well, and GCC warns if your code
4319 is not in NFKC if you use -Wnormalized=nfkc. This warning is comparable to warning about every identifier
4320 that contains the letter O because it might be confused with the digit 0, and so is not the default, but
4321 may be useful as a local coding convention if the programming environment cannot be fixed to display these
4322 characters distinctly.
4323 -Wno-attribute-warning
4324 Do not warn about usage of functions declared with "warning" attribute. By default, this warning is
4325 enabled. -Wno-attribute-warning can be used to disable the warning or -Wno-error=attribute-warning can be
4326 used to disable the error when compiled with -Werror flag.
4327 -Wno-deprecated
4328 Do not warn about usage of deprecated features.
4329 -Wno-deprecated-declarations
4330 Do not warn about uses of functions, variables, and types marked as deprecated by using the "deprecated"
4331 attribute.
4332 -Wno-overflow
4333 Do not warn about compile-time overflow in constant expressions.
4334 -Wno-odr
4335 Warn about One Definition Rule violations during link-time optimization. Enabled by default.
4336 -Wopenmp-simd
4337 Warn if the vectorizer cost model overrides the OpenMP simd directive set by user. The
4338 -fsimd-cost-model=unlimited option can be used to relax the cost model.
4339 -Woverride-init (C and Objective-C only)
4340 Warn if an initialized field without side effects is overridden when using designated initializers.
4341 This warning is included in -Wextra. To get other -Wextra warnings without this one, use -Wextra
4342 -Wno-override-init.
4343 -Wno-override-init-side-effects (C and Objective-C only)
4344 Do not warn if an initialized field with side effects is overridden when using designated initializers.
4345 This warning is enabled by default.
4346 -Wpacked
4347 Warn if a structure is given the packed attribute, but the packed attribute has no effect on the layout or
4348 size of the structure. Such structures may be mis-aligned for little benefit. For instance, in this code,
4349 the variable "f.x" in "struct bar" is misaligned even though "struct bar" does not itself have the packed
4350 attribute:
4351 struct foo {
4352 int x;
4353 char a, b, c, d;
4354 } __attribute__((packed));
4355 struct bar {
4356 char z;
4357 struct foo f;
4358 };
4359 -Wnopacked-bitfield-compat
4360 The 4.1, 4.2 and 4.3 series of GCC ignore the "packed" attribute on bit-fields of type "char". This was
4361 fixed in GCC 4.4 but the change can lead to differences in the structure layout. GCC informs you when the
4362 offset of such a field has changed in GCC 4.4. For example there is no longer a 4-bit padding between
4363 field "a" and "b" in this structure:
4364 struct foo
4365 {
4366 char a:4;
4367 char b:8;
4368 } __attribute__ ((packed));
4369 This warning is enabled by default. Use -Wno-packed-bitfield-compat to disable this warning.
4370 -Wpacked-not-aligned (C, C++, Objective-C and Objective-C++ only)
4371 Warn if a structure field with explicitly specified alignment in a packed struct or union is misaligned.
4372 For example, a warning will be issued on "struct S", like, "warning: alignment 1 of 'struct S' is less than
4373 8", in this code:
4374 struct __attribute__ ((aligned (8))) S8 { char a[8]; };
4375 struct __attribute__ ((packed)) S {
4376 struct S8 s8;
4377 };
4378 This warning is enabled by -Wall.
4379 -Wpadded
4380 Warn if padding is included in a structure, either to align an element of the structure or to align the
4381 whole structure. Sometimes when this happens it is possible to rearrange the fields of the structure to
4382 reduce the padding and so make the structure smaller.
4383 -Wredundant-decls
4384 Warn if anything is declared more than once in the same scope, even in cases where multiple declaration is
4385 valid and changes nothing.
4386 -Wrestrict
4387 Warn when an object referenced by a "restrict"-qualified parameter (or, in C++, a "__restrict"-qualified
4388 parameter) is aliased by another argument, or when copies between such objects overlap. For example, the
4389 call to the "strcpy" function below attempts to truncate the string by replacing its initial characters
4390 with the last four. However, because the call writes the terminating NUL into "a[4]", the copies overlap
4391 and the call is diagnosed.
4392 void foo (void)
4393 {
4394 char a[] = "abcd1234";
4395 strcpy (a, a + 4);
4396 ...
4397 }
4398 The -Wrestrict option detects some instances of simple overlap even without optimization but works best at
4399 -O2 and above. It is included in -Wall.
4400 -Wnested-externs (C and Objective-C only)
4401 Warn if an "extern" declaration is encountered within a function.
4402 -Winline
4403 Warn if a function that is declared as inline cannot be inlined. Even with this option, the compiler does
4404 not warn about failures to inline functions declared in system headers.
4405 The compiler uses a variety of heuristics to determine whether or not to inline a function. For example,
4406 the compiler takes into account the size of the function being inlined and the amount of inlining that has
4407 already been done in the current function. Therefore, seemingly insignificant changes in the source
4408 program can cause the warnings produced by -Winline to appear or disappear.
4409 -Wint-in-bool-context
4410 Warn for suspicious use of integer values where boolean values are expected, such as conditional
4411 expressions (?:) using non-boolean integer constants in boolean context, like "if (a <= b ? 2 : 3)". Or
4412 left shifting of signed integers in boolean context, like "for (a = 0; 1 << a; a++);". Likewise for all
4413 kinds of multiplications regardless of the data type. This warning is enabled by -Wall.
4414 -Wno-int-to-pointer-cast
4415 Suppress warnings from casts to pointer type of an integer of a different size. In C++, casting to a
4416 pointer type of smaller size is an error. Wint-to-pointer-cast is enabled by default.
4417 -Wno-pointer-to-int-cast (C and Objective-C only)
4418 Suppress warnings from casts from a pointer to an integer type of a different size.
4419 -Winvalid-pch
4420 Warn if a precompiled header is found in the search path but cannot be used.
4421 -Wlong-long
4422 Warn if "long long" type is used. This is enabled by either -Wpedantic or -Wtraditional in ISO C90 and
4423 C++98 modes. To inhibit the warning messages, use -Wno-long-long.
4424 -Wvariadic-macros
4425 Warn if variadic macros are used in ISO C90 mode, or if the GNU alternate syntax is used in ISO C99 mode.
4426 This is enabled by either -Wpedantic or -Wtraditional. To inhibit the warning messages, use
4427 -Wno-variadic-macros.
4428 -Wno-varargs
4429 Do not warn upon questionable usage of the macros used to handle variable arguments like "va_start". These
4430 warnings are enabled by default.
4431 -Wvector-operation-performance
4432 Warn if vector operation is not implemented via SIMD capabilities of the architecture. Mainly useful for
4433 the performance tuning. Vector operation can be implemented "piecewise", which means that the scalar
4434 operation is performed on every vector element; "in parallel", which means that the vector operation is
4435 implemented using scalars of wider type, which normally is more performance efficient; and "as a single
4436 scalar", which means that vector fits into a scalar type.
4437 -Wvla
4438 Warn if a variable-length array is used in the code. -Wno-vla prevents the -Wpedantic warning of the
4439 variable-length array.
4440 -Wvla-larger-than=byte-size
4441 If this option is used, the compiler warns for declarations of variable-length arrays whose size is either
4442 unbounded, or bounded by an argument that allows the array size to exceed byte-size bytes. This is similar
4443 to how -Walloca-larger-than=byte-size works, but with variable-length arrays.
4444 Note that GCC may optimize small variable-length arrays of a known value into plain arrays, so this warning
4445 may not get triggered for such arrays.
4446 -Wvla-larger-than=PTRDIFF_MAX is enabled by default but is typically only effective when -ftree-vrp is
4447 active (default for -O2 and above).
4448 See also -Walloca-larger-than=byte-size.
4449 -Wno-vla-larger-than
4450 Disable -Wvla-larger-than= warnings. The option is equivalent to -Wvla-larger-than=SIZE_MAX or larger.
4451 -Wvla-parameter
4452 Warn about redeclarations of functions involving arguments of Variable Length Array types of inconsistent
4453 kinds or forms, and enable the detection of out-of-bounds accesses to such parameters by warnings such as
4454 -Warray-bounds.
4455 If the first function declaration uses the VLA form the bound specified in the array is assumed to be the
4456 minimum number of elements expected to be provided in calls to the function and the maximum number of
4457 elements accessed by it. Failing to provide arguments of sufficient size or accessing more than the
4458 maximum number of elements may be diagnosed.
4459 For example, the warning triggers for the following redeclarations because the first one allows an array of
4460 any size to be passed to "f" while the second one specifies that the array argument must have at least "n"
4461 elements. In addition, calling "f" with the assotiated VLA bound parameter in excess of the actual VLA
4462 bound triggers a warning as well.
4463 void f (int n, int[n]);
4464 void f (int, int[]); // warning: argument 2 previously declared as a VLA
4465 void g (int n)
4466 {
4467 if (n > 4)
4468 return;
4469 int a[n];
4470 f (sizeof a, a); // warning: access to a by f may be out of bounds
4471 ...
4472 }
4473 -Wvla-parameter is included in -Wall. The -Warray-parameter option triggers warnings for similar problems
4474 involving ordinary array arguments.
4475 -Wvolatile-register-var
4476 Warn if a register variable is declared volatile. The volatile modifier does not inhibit all optimizations
4477 that may eliminate reads and/or writes to register variables. This warning is enabled by -Wall.
4478 -Wdisabled-optimization
4479 Warn if a requested optimization pass is disabled. This warning does not generally indicate that there is
4480 anything wrong with your code; it merely indicates that GCC's optimizers are unable to handle the code
4481 effectively. Often, the problem is that your code is too big or too complex; GCC refuses to optimize
4482 programs when the optimization itself is likely to take inordinate amounts of time.
4483 -Wpointer-sign (C and Objective-C only)
4484 Warn for pointer argument passing or assignment with different signedness. This option is only supported
4485 for C and Objective-C. It is implied by -Wall and by -Wpedantic, which can be disabled with
4486 -Wno-pointer-sign.
4487 -Wstack-protector
4488 This option is only active when -fstack-protector is active. It warns about functions that are not
4489 protected against stack smashing.
4490 -Woverlength-strings
4491 Warn about string constants that are longer than the "minimum maximum" length specified in the C standard.
4492 Modern compilers generally allow string constants that are much longer than the standard's minimum limit,
4493 but very portable programs should avoid using longer strings.
4494 The limit applies after string constant concatenation, and does not count the trailing NUL. In C90, the
4495 limit was 509 characters; in C99, it was raised to 4095. C++98 does not specify a normative minimum
4496 maximum, so we do not diagnose overlength strings in C++.
4497 This option is implied by -Wpedantic, and can be disabled with -Wno-overlength-strings.
4498 -Wunsuffixed-float-constants (C and Objective-C only)
4499 Issue a warning for any floating constant that does not have a suffix. When used together with
4500 -Wsystem-headers it warns about such constants in system header files. This can be useful when preparing
4501 code to use with the "FLOAT_CONST_DECIMAL64" pragma from the decimal floating-point extension to C99.
4502 -Wno-lto-type-mismatch
4503 During the link-time optimization, do not warn about type mismatches in global declarations from different
4504 compilation units. Requires -flto to be enabled. Enabled by default.
4505 -Wno-designated-init (C and Objective-C only)
4506 Suppress warnings when a positional initializer is used to initialize a structure that has been marked with
4507 the "designated_init" attribute.
4508 Options That Control Static Analysis
4509 -fanalyzer
4510 This option enables an static analysis of program flow which looks for "interesting" interprocedural paths
4511 through the code, and issues warnings for problems found on them.
4512 This analysis is much more expensive than other GCC warnings.
4513 Enabling this option effectively enables the following warnings:
4514 -Wanalyzer-double-fclose -Wanalyzer-double-free -Wanalyzer-exposure-through-output-file
4515 -Wanalyzer-file-leak -Wanalyzer-free-of-non-heap -Wanalyzer-malloc-leak -Wanalyzer-mismatching-deallocation
4516 -Wanalyzer-possible-null-argument -Wanalyzer-possible-null-dereference -Wanalyzer-null-argument
4517 -Wanalyzer-null-dereference -Wanalyzer-shift-count-negative -Wanalyzer-shift-count-overflow
4518 -Wanalyzer-stale-setjmp-buffer -Wanalyzer-tainted-array-index -Wanalyzer-unsafe-call-within-signal-handler
4519 -Wanalyzer-use-after-free -Wanalyzer-use-of-pointer-in-stale-stack-frame -Wanalyzer-write-to-const
4520 -Wanalyzer-write-to-string-literal
4521 This option is only available if GCC was configured with analyzer support enabled.
4522 -Wanalyzer-too-complex
4523 If -fanalyzer is enabled, the analyzer uses various heuristics to attempt to explore the control flow and
4524 data flow in the program, but these can be defeated by sufficiently complicated code.
4525 By default, the analysis silently stops if the code is too complicated for the analyzer to fully explore
4526 and it reaches an internal limit. The -Wanalyzer-too-complex option warns if this occurs.
4527 -Wno-analyzer-double-fclose
4528 This warning requires -fanalyzer, which enables it; use -Wno-analyzer-double-fclose to disable it.
4529 This diagnostic warns for paths through the code in which a "FILE *" can have "fclose" called on it more
4530 than once.
4531 -Wno-analyzer-double-free
4532 This warning requires -fanalyzer, which enables it; use -Wno-analyzer-double-free to disable it.
4533 This diagnostic warns for paths through the code in which a pointer can have a deallocator called on it
4534 more than once, either "free", or a deallocator referenced by attribute "malloc".
4535 -Wno-analyzer-exposure-through-output-file
4536 This warning requires -fanalyzer, which enables it; use -Wno-analyzer-exposure-through-output-file to
4537 disable it.
4538 This diagnostic warns for paths through the code in which a security-sensitive value is written to an
4539 output file (such as writing a password to a log file).
4540 -Wno-analyzer-file-leak
4541 This warning requires -fanalyzer, which enables it; use -Wno-analyzer-file-leak to disable it.
4542 This diagnostic warns for paths through the code in which a "<stdio.h>" "FILE *" stream object is leaked.
4543 -Wno-analyzer-free-of-non-heap
4544 This warning requires -fanalyzer, which enables it; use -Wno-analyzer-free-of-non-heap to disable it.
4545 This diagnostic warns for paths through the code in which "free" is called on a non-heap pointer (e.g. an
4546 on-stack buffer, or a global).
4547 -Wno-analyzer-malloc-leak
4548 This warning requires -fanalyzer, which enables it; use -Wno-analyzer-malloc-leak to disable it.
4549 This diagnostic warns for paths through the code in which a pointer allocated via an allocator is leaked:
4550 either "malloc", or a function marked with attribute "malloc".
4551 -Wno-analyzer-mismatching-deallocation
4552 This warning requires -fanalyzer, which enables it; use -Wno-analyzer-mismatching-deallocation to disable
4553 it.
4554 This diagnostic warns for paths through the code in which the wrong deallocation function is called on a
4555 pointer value, based on which function was used to allocate the pointer value. The diagnostic will warn
4556 about mismatches between "free", scalar "delete" and vector "delete[]", and those marked as
4557 allocator/deallocator pairs using attribute "malloc".
4558 -Wno-analyzer-possible-null-argument
4559 This warning requires -fanalyzer, which enables it; use -Wno-analyzer-possible-null-argument to disable it.
4560 This diagnostic warns for paths through the code in which a possibly-NULL value is passed to a function
4561 argument marked with "__attribute__((nonnull))" as requiring a non-NULL value.
4562 -Wno-analyzer-possible-null-dereference
4563 This warning requires -fanalyzer, which enables it; use -Wno-analyzer-possible-null-dereference to disable
4564 it.
4565 This diagnostic warns for paths through the code in which a possibly-NULL value is dereferenced.
4566 -Wno-analyzer-null-argument
4567 This warning requires -fanalyzer, which enables it; use -Wno-analyzer-null-argument to disable it.
4568 This diagnostic warns for paths through the code in which a value known to be NULL is passed to a function
4569 argument marked with "__attribute__((nonnull))" as requiring a non-NULL value.
4570 -Wno-analyzer-null-dereference
4571 This warning requires -fanalyzer, which enables it; use -Wno-analyzer-null-dereference to disable it.
4572 This diagnostic warns for paths through the code in which a value known to be NULL is dereferenced.
4573 -Wno-analyzer-shift-count-negative
4574 This warning requires -fanalyzer, which enables it; use -Wno-analyzer-shift-count-negative to disable it.
4575 This diagnostic warns for paths through the code in which a shift is attempted with a negative count. It
4576 is analogous to the -Wshift-count-negative diagnostic implemented in the C/C++ front ends, but is
4577 implemented based on analyzing interprocedural paths, rather than merely parsing the syntax tree. However,
4578 the analyzer does not prioritize detection of such paths, so false negatives are more likely relative to
4579 other warnings.
4580 -Wno-analyzer-shift-count-overflow
4581 This warning requires -fanalyzer, which enables it; use -Wno-analyzer-shift-count-overflow to disable it.
4582 This diagnostic warns for paths through the code in which a shift is attempted with a count greater than or
4583 equal to the precision of the operand's type. It is analogous to the -Wshift-count-overflow diagnostic
4584 implemented in the C/C++ front ends, but is implemented based on analyzing interprocedural paths, rather
4585 than merely parsing the syntax tree. However, the analyzer does not prioritize detection of such paths, so
4586 false negatives are more likely relative to other warnings.
4587 -Wno-analyzer-stale-setjmp-buffer
4588 This warning requires -fanalyzer, which enables it; use -Wno-analyzer-stale-setjmp-buffer to disable it.
4589 This diagnostic warns for paths through the code in which "longjmp" is called to rewind to a "jmp_buf"
4590 relating to a "setjmp" call in a function that has returned.
4591 When "setjmp" is called on a "jmp_buf" to record a rewind location, it records the stack frame. The stack
4592 frame becomes invalid when the function containing the "setjmp" call returns. Attempting to rewind to it
4593 via "longjmp" would reference a stack frame that no longer exists, and likely lead to a crash (or worse).
4594 -Wno-analyzer-tainted-array-index
4595 This warning requires both -fanalyzer and -fanalyzer-checker=taint to enable it; use
4596 -Wno-analyzer-tainted-array-index to disable it.
4597 This diagnostic warns for paths through the code in which a value that could be under an attacker's control
4598 is used as the index of an array access without being sanitized.
4599 -Wno-analyzer-unsafe-call-within-signal-handler
4600 This warning requires -fanalyzer, which enables it; use -Wno-analyzer-unsafe-call-within-signal-handler to
4601 disable it.
4602 This diagnostic warns for paths through the code in which a function known to be async-signal-unsafe (such
4603 as "fprintf") is called from a signal handler.
4604 -Wno-analyzer-use-after-free
4605 This warning requires -fanalyzer, which enables it; use -Wno-analyzer-use-after-free to disable it.
4606 This diagnostic warns for paths through the code in which a pointer is used after a deallocator is called
4607 on it: either "free", or a deallocator referenced by attribute "malloc".
4608 -Wno-analyzer-use-of-pointer-in-stale-stack-frame
4609 This warning requires -fanalyzer, which enables it; use -Wno-analyzer-use-of-pointer-in-stale-stack-frame
4610 to disable it.
4611 This diagnostic warns for paths through the code in which a pointer is dereferenced that points to a
4612 variable in a stale stack frame.
4613 -Wno-analyzer-write-to-const
4614 This warning requires -fanalyzer, which enables it; use -Wno-analyzer-write-to-const to disable it.
4615 This diagnostic warns for paths through the code in which the analyzer detects an attempt to write through
4616 a pointer to a "const" object. However, the analyzer does not prioritize detection of such paths, so false
4617 negatives are more likely relative to other warnings.
4618 -Wno-analyzer-write-to-string-literal
4619 This warning requires -fanalyzer, which enables it; use -Wno-analyzer-write-to-string-literal to disable
4620 it.
4621 This diagnostic warns for paths through the code in which the analyzer detects an attempt to write through
4622 a pointer to a string literal. However, the analyzer does not prioritize detection of such paths, so false
4623 negatives are more likely relative to other warnings.
4624 Pertinent parameters for controlling the exploration are: --param analyzer-bb-explosion-factor=value, --param
4625 analyzer-max-enodes-per-program-point=value, --param analyzer-max-recursion-depth=value, and --param
4626 analyzer-min-snodes-for-call-summary=value.
4627 The following options control the analyzer.
4628 -fanalyzer-call-summaries
4629 Simplify interprocedural analysis by computing the effect of certain calls, rather than exploring all paths
4630 through the function from callsite to each possible return.
4631 If enabled, call summaries are only used for functions with more than one call site, and that are
4632 sufficiently complicated (as per --param analyzer-min-snodes-for-call-summary=value).
4633 -fanalyzer-checker=name
4634 Restrict the analyzer to run just the named checker, and enable it.
4635 Some checkers are disabled by default (even with -fanalyzer), such as the "taint" checker that implements
4636 -Wanalyzer-tainted-array-index, and this option is required to enable them.
4637 -fno-analyzer-feasibility
4638 This option is intended for analyzer developers.
4639 By default the analyzer verifies that there is a feasible control flow path for each diagnostic it emits:
4640 that the conditions that hold are not mutually exclusive. Diagnostics for which no feasible path can be
4641 found are rejected. This filtering can be suppressed with -fno-analyzer-feasibility, for debugging issues
4642 in this code.
4643 -fanalyzer-fine-grained
4644 This option is intended for analyzer developers.
4645 Internally the analyzer builds an "exploded graph" that combines control flow graphs with data flow
4646 information.
4647 By default, an edge in this graph can contain the effects of a run of multiple statements within a basic
4648 block. With -fanalyzer-fine-grained, each statement gets its own edge.
4649 -fanalyzer-show-duplicate-count
4650 This option is intended for analyzer developers: if multiple diagnostics have been detected as being
4651 duplicates of each other, it emits a note when reporting the best diagnostic, giving the number of
4652 additional diagnostics that were suppressed by the deduplication logic.
4653 -fno-analyzer-state-merge
4654 This option is intended for analyzer developers.
4655 By default the analyzer attempts to simplify analysis by merging sufficiently similar states at each
4656 program point as it builds its "exploded graph". With -fno-analyzer-state-merge this merging can be
4657 suppressed, for debugging state-handling issues.
4658 -fno-analyzer-state-purge
4659 This option is intended for analyzer developers.
4660 By default the analyzer attempts to simplify analysis by purging aspects of state at a program point that
4661 appear to no longer be relevant e.g. the values of locals that aren't accessed later in the function and
4662 which aren't relevant to leak analysis.
4663 With -fno-analyzer-state-purge this purging of state can be suppressed, for debugging state-handling
4664 issues.
4665 -fanalyzer-transitivity
4666 This option enables transitivity of constraints within the analyzer.
4667 -fanalyzer-verbose-edges
4668 This option is intended for analyzer developers. It enables more verbose, lower-level detail in the
4669 descriptions of control flow within diagnostic paths.
4670 -fanalyzer-verbose-state-changes
4671 This option is intended for analyzer developers. It enables more verbose, lower-level detail in the
4672 descriptions of events relating to state machines within diagnostic paths.
4673 -fanalyzer-verbosity=level
4674 This option controls the complexity of the control flow paths that are emitted for analyzer diagnostics.
4675 The level can be one of:
4676 0 At this level, interprocedural call and return events are displayed, along with the most pertinent
4677 state-change events relating to a diagnostic. For example, for a double-"free" diagnostic, both calls
4678 to "free" will be shown.
4679 1 As per the previous level, but also show events for the entry to each function.
4680 2 As per the previous level, but also show events relating to control flow that are significant to
4681 triggering the issue (e.g. "true path taken" at a conditional).
4682 This level is the default.
4683 3 As per the previous level, but show all control flow events, not just significant ones.
4684 4 This level is intended for analyzer developers; it adds various other events intended for debugging the
4685 analyzer.
4686 -fdump-analyzer
4687 Dump internal details about what the analyzer is doing to file.analyzer.txt. This option is overridden by
4688 -fdump-analyzer-stderr.
4689 -fdump-analyzer-stderr
4690 Dump internal details about what the analyzer is doing to stderr. This option overrides -fdump-analyzer.
4691 -fdump-analyzer-callgraph
4692 Dump a representation of the call graph suitable for viewing with GraphViz to file.callgraph.dot.
4693 -fdump-analyzer-exploded-graph
4694 Dump a representation of the "exploded graph" suitable for viewing with GraphViz to file.eg.dot. Nodes are
4695 color-coded based on state-machine states to emphasize state changes.
4696 -fdump-analyzer-exploded-nodes
4697 Emit diagnostics showing where nodes in the "exploded graph" are in relation to the program source.
4698 -fdump-analyzer-exploded-nodes-2
4699 Dump a textual representation of the "exploded graph" to file.eg.txt.
4700 -fdump-analyzer-exploded-nodes-3
4701 Dump a textual representation of the "exploded graph" to one dump file per node, to file.eg-id.txt. This
4702 is typically a large number of dump files.
4703 -fdump-analyzer-feasibility
4704 Dump internal details about the analyzer's search for feasible paths. The details are written in a form
4705 suitable for viewing with GraphViz to filenames of the form file.*.fg.dot and file.*.tg.dot.
4706 -fdump-analyzer-json
4707 Dump a compressed JSON representation of analyzer internals to file.analyzer.json.gz. The precise format
4708 is subject to change.
4709 -fdump-analyzer-state-purge
4710 As per -fdump-analyzer-supergraph, dump a representation of the "supergraph" suitable for viewing with
4711 GraphViz, but annotate the graph with information on what state will be purged at each node. The graph is
4712 written to file.state-purge.dot.
4713 -fdump-analyzer-supergraph
4714 Dump representations of the "supergraph" suitable for viewing with GraphViz to file.supergraph.dot and to
4715 file.supergraph-eg.dot. These show all of the control flow graphs in the program, with interprocedural
4716 edges for calls and returns. The second dump contains annotations showing nodes in the "exploded graph"
4717 and diagnostics associated with them.
4718 Options for Debugging Your Program
4719 To tell GCC to emit extra information for use by a debugger, in almost all cases you need only to add -g to
4720 your other options.
4721 GCC allows you to use -g with -O. The shortcuts taken by optimized code may occasionally be surprising: some
4722 variables you declared may not exist at all; flow of control may briefly move where you did not expect it; some
4723 statements may not be executed because they compute constant results or their values are already at hand; some
4724 statements may execute in different places because they have been moved out of loops. Nevertheless it is
4725 possible to debug optimized output. This makes it reasonable to use the optimizer for programs that might have
4726 bugs.
4727 If you are not using some other optimization option, consider using -Og with -g. With no -O option at all,
4728 some compiler passes that collect information useful for debugging do not run at all, so that -Og may result in
4729 a better debugging experience.
4730 -g Produce debugging information in the operating system's native format (stabs, COFF, XCOFF, or DWARF). GDB
4731 can work with this debugging information.
4732 On most systems that use stabs format, -g enables use of extra debugging information that only GDB can use;
4733 this extra information makes debugging work better in GDB but probably makes other debuggers crash or
4734 refuse to read the program. If you want to control for certain whether to generate the extra information,
4735 use -gstabs+, -gstabs, -gxcoff+, -gxcoff, or -gvms (see below).
4736 -ggdb
4737 Produce debugging information for use by GDB. This means to use the most expressive format available
4738 (DWARF, stabs, or the native format if neither of those are supported), including GDB extensions if at all
4739 possible.
4740 -gdwarf
4741 -gdwarf-version
4742 Produce debugging information in DWARF format (if that is supported). The value of version may be either
4743 2, 3, 4 or 5; the default version for most targets is 5 (with the exception of VxWorks, TPF and Darwin/Mac
4744 OS X, which default to version 2, and AIX, which defaults to version 4).
4745 Note that with DWARF Version 2, some ports require and always use some non-conflicting DWARF 3 extensions
4746 in the unwind tables.
4747 Version 4 may require GDB 7.0 and -fvar-tracking-assignments for maximum benefit. Version 5 requires GDB
4748 8.0 or higher.
4749 GCC no longer supports DWARF Version 1, which is substantially different than Version 2 and later. For
4750 historical reasons, some other DWARF-related options such as -fno-dwarf2-cfi-asm) retain a reference to
4751 DWARF Version 2 in their names, but apply to all currently-supported versions of DWARF.
4752 -gstabs
4753 Produce debugging information in stabs format (if that is supported), without GDB extensions. This is the
4754 format used by DBX on most BSD systems. On MIPS, Alpha and System V Release 4 systems this option produces
4755 stabs debugging output that is not understood by DBX. On System V Release 4 systems this option requires
4756 the GNU assembler.
4757 -gstabs+
4758 Produce debugging information in stabs format (if that is supported), using GNU extensions understood only
4759 by the GNU debugger (GDB). The use of these extensions is likely to make other debuggers crash or refuse
4760 to read the program.
4761 -gxcoff
4762 Produce debugging information in XCOFF format (if that is supported). This is the format used by the DBX
4763 debugger on IBM RS/6000 systems.
4764 -gxcoff+
4765 Produce debugging information in XCOFF format (if that is supported), using GNU extensions understood only
4766 by the GNU debugger (GDB). The use of these extensions is likely to make other debuggers crash or refuse
4767 to read the program, and may cause assemblers other than the GNU assembler (GAS) to fail with an error.
4768 -gvms
4769 Produce debugging information in Alpha/VMS debug format (if that is supported). This is the format used by
4770 DEBUG on Alpha/VMS systems.
4771 -glevel
4772 -ggdblevel
4773 -gstabslevel
4774 -gxcofflevel
4775 -gvmslevel
4776 Request debugging information and also use level to specify how much information. The default level is 2.
4777 Level 0 produces no debug information at all. Thus, -g0 negates -g.
4778 Level 1 produces minimal information, enough for making backtraces in parts of the program that you don't
4779 plan to debug. This includes descriptions of functions and external variables, and line number tables, but
4780 no information about local variables.
4781 Level 3 includes extra information, such as all the macro definitions present in the program. Some
4782 debuggers support macro expansion when you use -g3.
4783 If you use multiple -g options, with or without level numbers, the last such option is the one that is
4784 effective.
4785 -gdwarf does not accept a concatenated debug level, to avoid confusion with -gdwarf-level. Instead use an
4786 additional -glevel option to change the debug level for DWARF.
4787 -fno-eliminate-unused-debug-symbols
4788 By default, no debug information is produced for symbols that are not actually used. Use this option if you
4789 want debug information for all symbols.
4790 -femit-class-debug-always
4791 Instead of emitting debugging information for a C++ class in only one object file, emit it in all object
4792 files using the class. This option should be used only with debuggers that are unable to handle the way
4793 GCC normally emits debugging information for classes because using this option increases the size of
4794 debugging information by as much as a factor of two.
4795 -fno-merge-debug-strings
4796 Direct the linker to not merge together strings in the debugging information that are identical in
4797 different object files. Merging is not supported by all assemblers or linkers. Merging decreases the size
4798 of the debug information in the output file at the cost of increasing link processing time. Merging is
4799 enabled by default.
4800 -fdebug-prefix-map=old=new
4801 When compiling files residing in directory old, record debugging information describing them as if the
4802 files resided in directory new instead. This can be used to replace a build-time path with an install-time
4803 path in the debug info. It can also be used to change an absolute path to a relative path by using . for
4804 new. This can give more reproducible builds, which are location independent, but may require an extra
4805 command to tell GDB where to find the source files. See also -ffile-prefix-map.
4806 -fvar-tracking
4807 Run variable tracking pass. It computes where variables are stored at each position in code. Better
4808 debugging information is then generated (if the debugging information format supports this information).
4809 It is enabled by default when compiling with optimization (-Os, -O, -O2, ...), debugging information (-g)
4810 and the debug info format supports it.
4811 -fvar-tracking-assignments
4812 Annotate assignments to user variables early in the compilation and attempt to carry the annotations over
4813 throughout the compilation all the way to the end, in an attempt to improve debug information while
4814 optimizing. Use of -gdwarf-4 is recommended along with it.
4815 It can be enabled even if var-tracking is disabled, in which case annotations are created and maintained,
4816 but discarded at the end. By default, this flag is enabled together with -fvar-tracking, except when
4817 selective scheduling is enabled.
4818 -gsplit-dwarf
4819 If DWARF debugging information is enabled, separate as much debugging information as possible into a
4820 separate output file with the extension .dwo. This option allows the build system to avoid linking files
4821 with debug information. To be useful, this option requires a debugger capable of reading .dwo files.
4822 -gdwarf32
4823 -gdwarf64
4824 If DWARF debugging information is enabled, the -gdwarf32 selects the 32-bit DWARF format and the -gdwarf64
4825 selects the 64-bit DWARF format. The default is target specific, on most targets it is -gdwarf32 though.
4826 The 32-bit DWARF format is smaller, but can't support more than 2GiB of debug information in any of the
4827 DWARF debug information sections. The 64-bit DWARF format allows larger debug information and might not be
4828 well supported by all consumers yet.
4829 -gdescribe-dies
4830 Add description attributes to some DWARF DIEs that have no name attribute, such as artificial variables,
4831 external references and call site parameter DIEs.
4832 -gpubnames
4833 Generate DWARF ".debug_pubnames" and ".debug_pubtypes" sections.
4834 -ggnu-pubnames
4835 Generate ".debug_pubnames" and ".debug_pubtypes" sections in a format suitable for conversion into a GDB
4836 index. This option is only useful with a linker that can produce GDB index version 7.
4837 -fdebug-types-section
4838 When using DWARF Version 4 or higher, type DIEs can be put into their own ".debug_types" section instead of
4839 making them part of the ".debug_info" section. It is more efficient to put them in a separate comdat
4840 section since the linker can then remove duplicates. But not all DWARF consumers support ".debug_types"
4841 sections yet and on some objects ".debug_types" produces larger instead of smaller debugging information.
4842 -grecord-gcc-switches
4843 -gno-record-gcc-switches
4844 This switch causes the command-line options used to invoke the compiler that may affect code generation to
4845 be appended to the DW_AT_producer attribute in DWARF debugging information. The options are concatenated
4846 with spaces separating them from each other and from the compiler version. It is enabled by default. See
4847 also -frecord-gcc-switches for another way of storing compiler options into the object file.
4848 -gstrict-dwarf
4849 Disallow using extensions of later DWARF standard version than selected with -gdwarf-version. On most
4850 targets using non-conflicting DWARF extensions from later standard versions is allowed.
4851 -gno-strict-dwarf
4852 Allow using extensions of later DWARF standard version than selected with -gdwarf-version.
4853 -gas-loc-support
4854 Inform the compiler that the assembler supports ".loc" directives. It may then use them for the assembler
4855 to generate DWARF2+ line number tables.
4856 This is generally desirable, because assembler-generated line-number tables are a lot more compact than
4857 those the compiler can generate itself.
4858 This option will be enabled by default if, at GCC configure time, the assembler was found to support such
4859 directives.
4860 -gno-as-loc-support
4861 Force GCC to generate DWARF2+ line number tables internally, if DWARF2+ line number tables are to be
4862 generated.
4863 -gas-locview-support
4864 Inform the compiler that the assembler supports "view" assignment and reset assertion checking in ".loc"
4865 directives.
4866 This option will be enabled by default if, at GCC configure time, the assembler was found to support them.
4867 -gno-as-locview-support
4868 Force GCC to assign view numbers internally, if -gvariable-location-views are explicitly requested.
4869 -gcolumn-info
4870 -gno-column-info
4871 Emit location column information into DWARF debugging information, rather than just file and line. This
4872 option is enabled by default.
4873 -gstatement-frontiers
4874 -gno-statement-frontiers
4875 This option causes GCC to create markers in the internal representation at the beginning of statements, and
4876 to keep them roughly in place throughout compilation, using them to guide the output of "is_stmt" markers
4877 in the line number table. This is enabled by default when compiling with optimization (-Os, -O, -O2, ...),
4878 and outputting DWARF 2 debug information at the normal level.
4879 -gvariable-location-views
4880 -gvariable-location-views=incompat5
4881 -gno-variable-location-views
4882 Augment variable location lists with progressive view numbers implied from the line number table. This
4883 enables debug information consumers to inspect state at certain points of the program, even if no
4884 instructions associated with the corresponding source locations are present at that point. If the
4885 assembler lacks support for view numbers in line number tables, this will cause the compiler to emit the
4886 line number table, which generally makes them somewhat less compact. The augmented line number tables and
4887 location lists are fully backward-compatible, so they can be consumed by debug information consumers that
4888 are not aware of these augmentations, but they won't derive any benefit from them either.
4889 This is enabled by default when outputting DWARF 2 debug information at the normal level, as long as there
4890 is assembler support, -fvar-tracking-assignments is enabled and -gstrict-dwarf is not. When assembler
4891 support is not available, this may still be enabled, but it will force GCC to output internal line number
4892 tables, and if -ginternal-reset-location-views is not enabled, that will most certainly lead to silently
4893 mismatching location views.
4894 There is a proposed representation for view numbers that is not backward compatible with the location list
4895 format introduced in DWARF 5, that can be enabled with -gvariable-location-views=incompat5. This option
4896 may be removed in the future, is only provided as a reference implementation of the proposed
4897 representation. Debug information consumers are not expected to support this extended format, and they
4898 would be rendered unable to decode location lists using it.
4899 -ginternal-reset-location-views
4900 -gno-internal-reset-location-views
4901 Attempt to determine location views that can be omitted from location view lists. This requires the
4902 compiler to have very accurate insn length estimates, which isn't always the case, and it may cause
4903 incorrect view lists to be generated silently when using an assembler that does not support location view
4904 lists. The GNU assembler will flag any such error as a "view number mismatch". This is only enabled on
4905 ports that define a reliable estimation function.
4906 -ginline-points
4907 -gno-inline-points
4908 Generate extended debug information for inlined functions. Location view tracking markers are inserted at
4909 inlined entry points, so that address and view numbers can be computed and output in debug information.
4910 This can be enabled independently of location views, in which case the view numbers won't be output, but it
4911 can only be enabled along with statement frontiers, and it is only enabled by default if location views are
4912 enabled.
4913 -gz[=type]
4914 Produce compressed debug sections in DWARF format, if that is supported. If type is not given, the default
4915 type depends on the capabilities of the assembler and linker used. type may be one of none (don't compress
4916 debug sections), zlib (use zlib compression in ELF gABI format), or zlib-gnu (use zlib compression in
4917 traditional GNU format). If the linker doesn't support writing compressed debug sections, the option is
4918 rejected. Otherwise, if the assembler does not support them, -gz is silently ignored when producing object
4919 files.
4920 -femit-struct-debug-baseonly
4921 Emit debug information for struct-like types only when the base name of the compilation source file matches
4922 the base name of file in which the struct is defined.
4923 This option substantially reduces the size of debugging information, but at significant potential loss in
4924 type information to the debugger. See -femit-struct-debug-reduced for a less aggressive option. See
4925 -femit-struct-debug-detailed for more detailed control.
4926 This option works only with DWARF debug output.
4927 -femit-struct-debug-reduced
4928 Emit debug information for struct-like types only when the base name of the compilation source file matches
4929 the base name of file in which the type is defined, unless the struct is a template or defined in a system
4930 header.
4931 This option significantly reduces the size of debugging information, with some potential loss in type
4932 information to the debugger. See -femit-struct-debug-baseonly for a more aggressive option. See
4933 -femit-struct-debug-detailed for more detailed control.
4934 This option works only with DWARF debug output.
4935 -femit-struct-debug-detailed[=spec-list]
4936 Specify the struct-like types for which the compiler generates debug information. The intent is to reduce
4937 duplicate struct debug information between different object files within the same program.
4938 This option is a detailed version of -femit-struct-debug-reduced and -femit-struct-debug-baseonly, which
4939 serves for most needs.
4940 A specification has the syntax[dir:|ind:][ord:|gen:](any|sys|base|none)
4941 The optional first word limits the specification to structs that are used directly (dir:) or used
4942 indirectly (ind:). A struct type is used directly when it is the type of a variable, member. Indirect
4943 uses arise through pointers to structs. That is, when use of an incomplete struct is valid, the use is
4944 indirect. An example is struct one direct; struct two * indirect;.
4945 The optional second word limits the specification to ordinary structs (ord:) or generic structs (gen:).
4946 Generic structs are a bit complicated to explain. For C++, these are non-explicit specializations of
4947 template classes, or non-template classes within the above. Other programming languages have generics, but
4948 -femit-struct-debug-detailed does not yet implement them.
4949 The third word specifies the source files for those structs for which the compiler should emit debug
4950 information. The values none and any have the normal meaning. The value base means that the base of name
4951 of the file in which the type declaration appears must match the base of the name of the main compilation
4952 file. In practice, this means that when compiling foo.c, debug information is generated for types declared
4953 in that file and foo.h, but not other header files. The value sys means those types satisfying base or
4954 declared in system or compiler headers.
4955 You may need to experiment to determine the best settings for your application.
4956 The default is -femit-struct-debug-detailed=all.
4957 This option works only with DWARF debug output.
4958 -fno-dwarf2-cfi-asm
4959 Emit DWARF unwind info as compiler generated ".eh_frame" section instead of using GAS ".cfi_*" directives.
4960 -fno-eliminate-unused-debug-types
4961 Normally, when producing DWARF output, GCC avoids producing debug symbol output for types that are nowhere
4962 used in the source file being compiled. Sometimes it is useful to have GCC emit debugging information for
4963 all types declared in a compilation unit, regardless of whether or not they are actually used in that
4964 compilation unit, for example if, in the debugger, you want to cast a value to a type that is not actually
4965 used in your program (but is declared). More often, however, this results in a significant amount of
4966 wasted space.
4967 Options That Control Optimization
4968 These options control various sorts of optimizations.
4969 Without any optimization option, the compiler's goal is to reduce the cost of compilation and to make debugging
4970 produce the expected results. Statements are independent: if you stop the program with a breakpoint between
4971 statements, you can then assign a new value to any variable or change the program counter to any other
4972 statement in the function and get exactly the results you expect from the source code.
4973 Turning on optimization flags makes the compiler attempt to improve the performance and/or code size at the
4974 expense of compilation time and possibly the ability to debug the program.
4975 The compiler performs optimization based on the knowledge it has of the program. Compiling multiple files at
4976 once to a single output file mode allows the compiler to use information gained from all of the files when
4977 compiling each of them.
4978 Not all optimizations are controlled directly by a flag. Only optimizations that have a flag are listed in
4979 this section.
4980 Most optimizations are completely disabled at -O0 or if an -O level is not set on the command line, even if
4981 individual optimization flags are specified. Similarly, -Og suppresses many optimization passes.
4982 Depending on the target and how GCC was configured, a slightly different set of optimizations may be enabled at
4983 each -O level than those listed here. You can invoke GCC with -Q --help=optimizers to find out the exact set
4984 of optimizations that are enabled at each level.
4985 -O
4986 -O1 Optimize. Optimizing compilation takes somewhat more time, and a lot more memory for a large function.
4987 With -O, the compiler tries to reduce code size and execution time, without performing any optimizations
4988 that take a great deal of compilation time.
4989 -O turns on the following optimization flags:
4990 -fauto-inc-dec -fbranch-count-reg -fcombine-stack-adjustments -fcompare-elim -fcprop-registers -fdce
4991 -fdefer-pop -fdelayed-branch -fdse -fforward-propagate -fguess-branch-probability -fif-conversion
4992 -fif-conversion2 -finline-functions-called-once -fipa-modref -fipa-profile -fipa-pure-const -fipa-reference
4993 -fipa-reference-addressable -fmerge-constants -fmove-loop-invariants -fomit-frame-pointer -freorder-blocks
4994 -fshrink-wrap -fshrink-wrap-separate -fsplit-wide-types -fssa-backprop -fssa-phiopt -ftree-bit-ccp
4995 -ftree-ccp -ftree-ch -ftree-coalesce-vars -ftree-copy-prop -ftree-dce -ftree-dominator-opts -ftree-dse
4996 -ftree-forwprop -ftree-fre -ftree-phiprop -ftree-pta -ftree-scev-cprop -ftree-sink -ftree-slsr -ftree-sra
4997 -ftree-ter -funit-at-a-time
4998 -O2 Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed
4999 tradeoff. As compared to -O, this option increases both compilation time and the performance of the
5000 generated code.
5001 -O2 turns on all optimization flags specified by -O. It also turns on the following optimization flags:
5002 -falign-functions -falign-jumps -falign-labels -falign-loops -fcaller-saves -fcode-hoisting
5003 -fcrossjumping -fcse-follow-jumps -fcse-skip-blocks -fdelete-null-pointer-checks -fdevirtualize
5004 -fdevirtualize-speculatively -fexpensive-optimizations -ffinite-loops -fgcse -fgcse-lm
5005 -fhoist-adjacent-loads -finline-functions -finline-small-functions -findirect-inlining -fipa-bit-cp
5006 -fipa-cp -fipa-icf -fipa-ra -fipa-sra -fipa-vrp -fisolate-erroneous-paths-dereference -flra-remat
5007 -foptimize-sibling-calls -foptimize-strlen -fpartial-inlining -fpeephole2 -freorder-blocks-algorithm=stc
5008 -freorder-blocks-and-partition -freorder-functions -frerun-cse-after-loop -fschedule-insns
5009 -fschedule-insns2 -fsched-interblock -fsched-spec -fstore-merging -fstrict-aliasing -fthread-jumps
5010 -ftree-builtin-call-dce -ftree-pre -ftree-switch-conversion -ftree-tail-merge -ftree-vrp
5011 Please note the warning under -fgcse about invoking -O2 on programs that use computed gotos.
5012 NOTE: In Ubuntu 8.10 and later versions, -D_FORTIFY_SOURCE=2 is set by default, and is activated when -O is
5013 set to 2 or higher. This enables additional compile-time and run-time checks for several libc functions.
5014 To disable, specify either -U_FORTIFY_SOURCE or -D_FORTIFY_SOURCE=0.
5015 -O3 Optimize yet more. -O3 turns on all optimizations specified by -O2 and also turns on the following
5016 optimization flags:
5017 -fgcse-after-reload -fipa-cp-clone -floop-interchange -floop-unroll-and-jam -fpeel-loops
5018 -fpredictive-commoning -fsplit-loops -fsplit-paths -ftree-loop-distribution -ftree-loop-vectorize
5019 -ftree-partial-pre -ftree-slp-vectorize -funswitch-loops -fvect-cost-model -fvect-cost-model=dynamic
5020 -fversion-loops-for-strides
5021 -O0 Reduce compilation time and make debugging produce the expected results. This is the default.
5022 -Os Optimize for size. -Os enables all -O2 optimizations except those that often increase code size:
5023 -falign-functions -falign-jumps -falign-labels -falign-loops -fprefetch-loop-arrays
5024 -freorder-blocks-algorithm=stc
5025 It also enables -finline-functions, causes the compiler to tune for code size rather than execution speed,
5026 and performs further optimizations designed to reduce code size.
5027 -Ofast
5028 Disregard strict standards compliance. -Ofast enables all -O3 optimizations. It also enables
5029 optimizations that are not valid for all standard-compliant programs. It turns on -ffast-math,
5030 -fallow-store-data-races and the Fortran-specific -fstack-arrays, unless -fmax-stack-var-size is specified,
5031 and -fno-protect-parens.
5032 -Og Optimize debugging experience. -Og should be the optimization level of choice for the standard edit-
5033 compile-debug cycle, offering a reasonable level of optimization while maintaining fast compilation and a
5034 good debugging experience. It is a better choice than -O0 for producing debuggable code because some
5035 compiler passes that collect debug information are disabled at -O0.
5036 Like -O0, -Og completely disables a number of optimization passes so that individual options controlling
5037 them have no effect. Otherwise -Og enables all -O1 optimization flags except for those that may interfere
5038 with debugging:
5039 -fbranch-count-reg -fdelayed-branch -fdse -fif-conversion -fif-conversion2
5040 -finline-functions-called-once -fmove-loop-invariants -fssa-phiopt -ftree-bit-ccp -ftree-dse -ftree-pta
5041 -ftree-sra
5042 If you use multiple -O options, with or without level numbers, the last such option is the one that is
5043 effective.
5044 Options of the form -fflag specify machine-independent flags. Most flags have both positive and negative
5045 forms; the negative form of -ffoo is -fno-foo. In the table below, only one of the forms is listed---the one
5046 you typically use. You can figure out the other form by either removing no- or adding it.
5047 The following options control specific optimizations. They are either activated by -O options or are related
5048 to ones that are. You can use the following flags in the rare cases when "fine-tuning" of optimizations to be
5049 performed is desired.
5050 -fno-defer-pop
5051 For machines that must pop arguments after a function call, always pop the arguments as soon as each
5052 function returns. At levels -O1 and higher, -fdefer-pop is the default; this allows the compiler to let
5053 arguments accumulate on the stack for several function calls and pop them all at once.
5054 -fforward-propagate
5055 Perform a forward propagation pass on RTL. The pass tries to combine two instructions and checks if the
5056 result can be simplified. If loop unrolling is active, two passes are performed and the second is
5057 scheduled after loop unrolling.
5058 This option is enabled by default at optimization levels -O, -O2, -O3, -Os.
5059 -ffp-contract=style
5060 -ffp-contract=off disables floating-point expression contraction. -ffp-contract=fast enables floating-
5061 point expression contraction such as forming of fused multiply-add operations if the target has native
5062 support for them. -ffp-contract=on enables floating-point expression contraction if allowed by the
5063 language standard. This is currently not implemented and treated equal to -ffp-contract=off.
5064 The default is -ffp-contract=fast.
5065 -fomit-frame-pointer
5066 Omit the frame pointer in functions that don't need one. This avoids the instructions to save, set up and
5067 restore the frame pointer; on many targets it also makes an extra register available.
5068 On some targets this flag has no effect because the standard calling sequence always uses a frame pointer,
5069 so it cannot be omitted.
5070 Note that -fno-omit-frame-pointer doesn't guarantee the frame pointer is used in all functions. Several
5071 targets always omit the frame pointer in leaf functions.
5072 Enabled by default at -O and higher.
5073 -foptimize-sibling-calls
5074 Optimize sibling and tail recursive calls.
5075 Enabled at levels -O2, -O3, -Os.
5076 -foptimize-strlen
5077 Optimize various standard C string functions (e.g. "strlen", "strchr" or "strcpy") and their
5078 "_FORTIFY_SOURCE" counterparts into faster alternatives.
5079 Enabled at levels -O2, -O3.
5080 -fno-inline
5081 Do not expand any functions inline apart from those marked with the "always_inline" attribute. This is the
5082 default when not optimizing.
5083 Single functions can be exempted from inlining by marking them with the "noinline" attribute.
5084 -finline-small-functions
5085 Integrate functions into their callers when their body is smaller than expected function call code (so
5086 overall size of program gets smaller). The compiler heuristically decides which functions are simple
5087 enough to be worth integrating in this way. This inlining applies to all functions, even those not
5088 declared inline.
5089 Enabled at levels -O2, -O3, -Os.
5090 -findirect-inlining
5091 Inline also indirect calls that are discovered to be known at compile time thanks to previous inlining.
5092 This option has any effect only when inlining itself is turned on by the -finline-functions or
5093 -finline-small-functions options.
5094 Enabled at levels -O2, -O3, -Os.
5095 -finline-functions
5096 Consider all functions for inlining, even if they are not declared inline. The compiler heuristically
5097 decides which functions are worth integrating in this way.
5098 If all calls to a given function are integrated, and the function is declared "static", then the function
5099 is normally not output as assembler code in its own right.
5100 Enabled at levels -O2, -O3, -Os. Also enabled by -fprofile-use and -fauto-profile.
5101 -finline-functions-called-once
5102 Consider all "static" functions called once for inlining into their caller even if they are not marked
5103 "inline". If a call to a given function is integrated, then the function is not output as assembler code
5104 in its own right.
5105 Enabled at levels -O1, -O2, -O3 and -Os, but not -Og.
5106 -fearly-inlining
5107 Inline functions marked by "always_inline" and functions whose body seems smaller than the function call
5108 overhead early before doing -fprofile-generate instrumentation and real inlining pass. Doing so makes
5109 profiling significantly cheaper and usually inlining faster on programs having large chains of nested
5110 wrapper functions.
5111 Enabled by default.
5112 -fipa-sra
5113 Perform interprocedural scalar replacement of aggregates, removal of unused parameters and replacement of
5114 parameters passed by reference by parameters passed by value.
5115 Enabled at levels -O2, -O3 and -Os.
5116 -finline-limit=n
5117 By default, GCC limits the size of functions that can be inlined. This flag allows coarse control of this
5118 limit. n is the size of functions that can be inlined in number of pseudo instructions.
5119 Inlining is actually controlled by a number of parameters, which may be specified individually by using
5120 --param name=value. The -finline-limit=n option sets some of these parameters as follows:
5121 max-inline-insns-single
5122 is set to n/2.
5123 max-inline-insns-auto
5124 is set to n/2.
5125 See below for a documentation of the individual parameters controlling inlining and for the defaults of
5126 these parameters.
5127 Note: there may be no value to -finline-limit that results in default behavior.
5128 Note: pseudo instruction represents, in this particular context, an abstract measurement of function's
5129 size. In no way does it represent a count of assembly instructions and as such its exact meaning might
5130 change from one release to an another.
5131 -fno-keep-inline-dllexport
5132 This is a more fine-grained version of -fkeep-inline-functions, which applies only to functions that are
5133 declared using the "dllexport" attribute or declspec.
5134 -fkeep-inline-functions
5135 In C, emit "static" functions that are declared "inline" into the object file, even if the function has
5136 been inlined into all of its callers. This switch does not affect functions using the "extern inline"
5137 extension in GNU C90. In C++, emit any and all inline functions into the object file.
5138 -fkeep-static-functions
5139 Emit "static" functions into the object file, even if the function is never used.
5140 -fkeep-static-consts
5141 Emit variables declared "static const" when optimization isn't turned on, even if the variables aren't
5142 referenced.
5143 GCC enables this option by default. If you want to force the compiler to check if a variable is
5144 referenced, regardless of whether or not optimization is turned on, use the -fno-keep-static-consts option.
5145 -fmerge-constants
5146 Attempt to merge identical constants (string constants and floating-point constants) across compilation
5147 units.
5148 This option is the default for optimized compilation if the assembler and linker support it. Use
5149 -fno-merge-constants to inhibit this behavior.
5150 Enabled at levels -O, -O2, -O3, -Os.
5151 -fmerge-all-constants
5152 Attempt to merge identical constants and identical variables.
5153 This option implies -fmerge-constants. In addition to -fmerge-constants this considers e.g. even constant
5154 initialized arrays or initialized constant variables with integral or floating-point types. Languages like
5155 C or C++ require each variable, including multiple instances of the same variable in recursive calls, to
5156 have distinct locations, so using this option results in non-conforming behavior.
5157 -fmodulo-sched
5158 Perform swing modulo scheduling immediately before the first scheduling pass. This pass looks at innermost
5159 loops and reorders their instructions by overlapping different iterations.
5160 -fmodulo-sched-allow-regmoves
5161 Perform more aggressive SMS-based modulo scheduling with register moves allowed. By setting this flag
5162 certain anti-dependences edges are deleted, which triggers the generation of reg-moves based on the life-
5163 range analysis. This option is effective only with -fmodulo-sched enabled.
5164 -fno-branch-count-reg
5165 Disable the optimization pass that scans for opportunities to use "decrement and branch" instructions on a
5166 count register instead of instruction sequences that decrement a register, compare it against zero, and
5167 then branch based upon the result. This option is only meaningful on architectures that support such
5168 instructions, which include x86, PowerPC, IA-64 and S/390. Note that the -fno-branch-count-reg option
5169 doesn't remove the decrement and branch instructions from the generated instruction stream introduced by
5170 other optimization passes.
5171 The default is -fbranch-count-reg at -O1 and higher, except for -Og.
5172 -fno-function-cse
5173 Do not put function addresses in registers; make each instruction that calls a constant function contain
5174 the function's address explicitly.
5175 This option results in less efficient code, but some strange hacks that alter the assembler output may be
5176 confused by the optimizations performed when this option is not used.
5177 The default is -ffunction-cse
5178 -fno-zero-initialized-in-bss
5179 If the target supports a BSS section, GCC by default puts variables that are initialized to zero into BSS.
5180 This can save space in the resulting code.
5181 This option turns off this behavior because some programs explicitly rely on variables going to the data
5182 section---e.g., so that the resulting executable can find the beginning of that section and/or make
5183 assumptions based on that.
5184 The default is -fzero-initialized-in-bss.
5185 -fthread-jumps
5186 Perform optimizations that check to see if a jump branches to a location where another comparison subsumed
5187 by the first is found. If so, the first branch is redirected to either the destination of the second
5188 branch or a point immediately following it, depending on whether the condition is known to be true or
5189 false.
5190 Enabled at levels -O2, -O3, -Os.
5191 -fsplit-wide-types
5192 When using a type that occupies multiple registers, such as "long long" on a 32-bit system, split the
5193 registers apart and allocate them independently. This normally generates better code for those types, but
5194 may make debugging more difficult.
5195 Enabled at levels -O, -O2, -O3, -Os.
5196 -fsplit-wide-types-early
5197 Fully split wide types early, instead of very late. This option has no effect unless -fsplit-wide-types is
5198 turned on.
5199 This is the default on some targets.
5200 -fcse-follow-jumps
5201 In common subexpression elimination (CSE), scan through jump instructions when the target of the jump is
5202 not reached by any other path. For example, when CSE encounters an "if" statement with an "else" clause,
5203 CSE follows the jump when the condition tested is false.
5204 Enabled at levels -O2, -O3, -Os.
5205 -fcse-skip-blocks
5206 This is similar to -fcse-follow-jumps, but causes CSE to follow jumps that conditionally skip over blocks.
5207 When CSE encounters a simple "if" statement with no else clause, -fcse-skip-blocks causes CSE to follow the
5208 jump around the body of the "if".
5209 Enabled at levels -O2, -O3, -Os.
5210 -frerun-cse-after-loop
5211 Re-run common subexpression elimination after loop optimizations are performed.
5212 Enabled at levels -O2, -O3, -Os.
5213 -fgcse
5214 Perform a global common subexpression elimination pass. This pass also performs global constant and copy
5215 propagation.
5216 Note: When compiling a program using computed gotos, a GCC extension, you may get better run-time
5217 performance if you disable the global common subexpression elimination pass by adding -fno-gcse to the
5218 command line.
5219 Enabled at levels -O2, -O3, -Os.
5220 -fgcse-lm
5221 When -fgcse-lm is enabled, global common subexpression elimination attempts to move loads that are only
5222 killed by stores into themselves. This allows a loop containing a load/store sequence to be changed to a
5223 load outside the loop, and a copy/store within the loop.
5224 Enabled by default when -fgcse is enabled.
5225 -fgcse-sm
5226 When -fgcse-sm is enabled, a store motion pass is run after global common subexpression elimination. This
5227 pass attempts to move stores out of loops. When used in conjunction with -fgcse-lm, loops containing a
5228 load/store sequence can be changed to a load before the loop and a store after the loop.
5229 Not enabled at any optimization level.
5230 -fgcse-las
5231 When -fgcse-las is enabled, the global common subexpression elimination pass eliminates redundant loads
5232 that come after stores to the same memory location (both partial and full redundancies).
5233 Not enabled at any optimization level.
5234 -fgcse-after-reload
5235 When -fgcse-after-reload is enabled, a redundant load elimination pass is performed after reload. The
5236 purpose of this pass is to clean up redundant spilling.
5237 Enabled by -fprofile-use and -fauto-profile.
5238 -faggressive-loop-optimizations
5239 This option tells the loop optimizer to use language constraints to derive bounds for the number of
5240 iterations of a loop. This assumes that loop code does not invoke undefined behavior by for example
5241 causing signed integer overflows or out-of-bound array accesses. The bounds for the number of iterations
5242 of a loop are used to guide loop unrolling and peeling and loop exit test optimizations. This option is
5243 enabled by default.
5244 -funconstrained-commons
5245 This option tells the compiler that variables declared in common blocks (e.g. Fortran) may later be
5246 overridden with longer trailing arrays. This prevents certain optimizations that depend on knowing the
5247 array bounds.
5248 -fcrossjumping
5249 Perform cross-jumping transformation. This transformation unifies equivalent code and saves code size.
5250 The resulting code may or may not perform better than without cross-jumping.
5251 Enabled at levels -O2, -O3, -Os.
5252 -fauto-inc-dec
5253 Combine increments or decrements of addresses with memory accesses. This pass is always skipped on
5254 architectures that do not have instructions to support this. Enabled by default at -O and higher on
5255 architectures that support this.
5256 -fdce
5257 Perform dead code elimination (DCE) on RTL. Enabled by default at -O and higher.
5258 -fdse
5259 Perform dead store elimination (DSE) on RTL. Enabled by default at -O and higher.
5260 -fif-conversion
5261 Attempt to transform conditional jumps into branch-less equivalents. This includes use of conditional
5262 moves, min, max, set flags and abs instructions, and some tricks doable by standard arithmetics. The use
5263 of conditional execution on chips where it is available is controlled by -fif-conversion2.
5264 Enabled at levels -O, -O2, -O3, -Os, but not with -Og.
5265 -fif-conversion2
5266 Use conditional execution (where available) to transform conditional jumps into branch-less equivalents.
5267 Enabled at levels -O, -O2, -O3, -Os, but not with -Og.
5268 -fdeclone-ctor-dtor
5269 The C++ ABI requires multiple entry points for constructors and destructors: one for a base subobject, one
5270 for a complete object, and one for a virtual destructor that calls operator delete afterwards. For a
5271 hierarchy with virtual bases, the base and complete variants are clones, which means two copies of the
5272 function. With this option, the base and complete variants are changed to be thunks that call a common
5273 implementation.
5274 Enabled by -Os.
5275 -fdelete-null-pointer-checks
5276 Assume that programs cannot safely dereference null pointers, and that no code or data element resides at
5277 address zero. This option enables simple constant folding optimizations at all optimization levels. In
5278 addition, other optimization passes in GCC use this flag to control global dataflow analyses that eliminate
5279 useless checks for null pointers; these assume that a memory access to address zero always results in a
5280 trap, so that if a pointer is checked after it has already been dereferenced, it cannot be null.
5281 Note however that in some environments this assumption is not true. Use -fno-delete-null-pointer-checks to
5282 disable this optimization for programs that depend on that behavior.
5283 This option is enabled by default on most targets. On Nios II ELF, it defaults to off. On AVR, CR16, and
5284 MSP430, this option is completely disabled.
5285 Passes that use the dataflow information are enabled independently at different optimization levels.
5286 -fdevirtualize
5287 Attempt to convert calls to virtual functions to direct calls. This is done both within a procedure and
5288 interprocedurally as part of indirect inlining (-findirect-inlining) and interprocedural constant
今天的分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。
上一篇
已是最后文章
下一篇
已是最新文章