[Bug preprocessor/90400] New: _Pragma not always expanded in the right location within macros

remi at machet dot us gcc-bugzilla@gcc.gnu.org
Wed May 8 21:56:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90400

            Bug ID: 90400
           Summary: _Pragma not always expanded in the right location
                    within macros
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
          Assignee: unassigned at gcc dot gnu.org
          Reporter: remi at machet dot us
  Target Milestone: ---

When the preprocessor does not understand the pragma inside _Pragma it calls
cb_def_pragma to print it (converting it to '#pragma'). Unfortunately that
function uses puts() to print the pragma directly to file.

If we are within a macro being expanded inside another macro then this will
results in all pragma within that macro being expanded at the top instead of at
their original location within the macro.

For example I would expect the following test to pass:
/* { dg-do assemble }
 * { dg-additional-options "-save-temps -Wall" }
 */


extern int b;

#define OUTPUT(stmt) \
  stmt

#define WITH_PRAGMA() \
  _Pragma("GCC diagnostic push"); \
  _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\""); \
  a--; \
  _Pragma("GCC diagnostic pop")


int main()
{
  int a;

  if (b) {
    b++;
  }
  OUTPUT( else {
    b--;
    WITH_PRAGMA();
  } )
}

Instead with trunk gcc I get:
test.c: In function 'main':
test.c:28:3: error: 'else' without a previous 'if'

Because the pragma statements are printed right at the beginning of output
instead of where WITH_PRAGMA is.


More information about the Gcc-bugs mailing list