> -----Original Message----- > From: Joseph Myers [mailto:jos...@codesourcery.com] > Sent: Wednesday, May 07, 2014 9:01 PM > To: Herman, Andrei > Cc: gcc-patches@gcc.gnu.org; herman_and...@mentor.com > Subject: Re: [PATCH GCC]Add 'force-dwarf-lexical-blocks' command line > option > > On Wed, 7 May 2014, Herman, Andrei wrote: > > > When this flag is set, a DW_TAG_lexical_block DIE will be emitted for > > every function body, loop body, switch body, case statement, if-then > > and if-else statement, even if the body is a single statement. > > Likewise, a lexical block will be emitted for the first label of a > > labeled statement. This block ends at the end of the current lexical > > scope, or when a break, continue, goto or return statement is > > encountered at the same lexical scope level. > > Consequently, any case in a switch statement that does not flow > > through to the next case, will have its own dwarf lexical block. > > The documentation appears to suggest it's purely about debug info and has > no effect on language semantics. However, the implementation appears to > force C99 scoping rules. I don't think it's appropriate for a debug info > option
You are right. The C99 scoping rules are forced with this option. > to have that effect; that is, gcc.dg/c90-scope-1.c should still pass even with > the option enabled (more generally, the whole C testsuite should be verified > to work with the option enabled). I suspect the changes adding scopes for > labels would also affect language semantics; it's valid in C to have a > declaration (not having variably modified type) after one case in a switch > statement that gets used in another case even when control does not flow > through. The changes in gcc/c/c-decl.c are meant to deal with this problem. Declarations that would fall into the scope of a newly created label scope are moved into the enclosing "normal" (non label) scope, where they actually belong. > > If you can't avoid affecting language semantics then you need to be very > clear in the documentation that the option makes some invalid programs > valid and vice versa and changes the semantics of some valid programs > (even if you then assert the affected cases are uncommon in real C code). > Here is the changed documentation: @item -fforce-dwarf-lexical-blocks Produce debug information (a DW_TAG_lexical_block) for every function body, loop body, switch body, case statement, if-then and if-else statement, even if the body is a single statement. Likewise, a lexical block will be emitted for the first label of a statement. This block ends at the end of the current lexical scope, or when a break, continue, goto or return statement is encountered at the same lexical scope level. This option is useful for coverage tools that utilize the dwarf debug information. This option only applies to C/C++ code and is available when using DWARF Version 4 or higher. Note that when this option is used, it will enforce the scoping rules of the C99 standard, which may make some programs that are invalid, to become valid and vice versa. > -- > Joseph S. Myers > jos...@codesourcery.com Regards, Andrei Herman Mentor Graphics Israel branch