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

2019-05-10 Thread remi at machet dot us
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90400

--- Comment #2 from Remi  ---
I found 69543 which looks similar but is different (and fixed): the cause of
the bug is different and it applies to the first level of a macro, while this
bug requires 2 levels of macro to show up.

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

2019-05-08 Thread remi at machet dot us
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.

[Bug other/89094] New: collect2.c:main c_argv buffer is undersized when -EL, -EB or -B used in COLLECT_GCC_OPTIONS

2019-01-28 Thread remi at machet dot us
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89094

Bug ID: 89094
   Summary: collect2.c:main c_argv buffer is undersized when -EL,
-EB or -B used in COLLECT_GCC_OPTIONS
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: other
  Assignee: unassigned at gcc dot gnu.org
  Reporter: remi at machet dot us
  Target Milestone: ---

collect2.c main() uses an array to store filtered arguments called c_argv. The
size of that array is based on num_c_args which account for 15 entries plus
command line arguments and one entry per -qm or -qf argument inside
COLLECT_GCC_OPTIONS:
/* Now pick up any flags we want early from COLLECT_GCC_OPTIONS
   The LTO options are passed here as are other options that might
   be unsuitable for ld (e.g. -save-temps).  */
p = getenv ("COLLECT_GCC_OPTIONS");
while (p && *p)
  {
const char *q = extract_string ();
if (*q == '-' && (q[1] == 'm' || q[1] == 'f'))
  num_c_args++;
...

But later, when the array is filled, more options not accounted for above are
added to the array if found in COLLECT_GCC_OPTIONS: -EL, -EB, -B and 2
entries for '-B ':
  if (*q == '-' && (q[1] == 'm' || q[1] == 'f'))
*c_ptr++ = xstrdup (q);
  if (strcmp (q, "-EL") == 0 || strcmp (q, "-EB") == 0)
*c_ptr++ = xstrdup (q);
  if (strcmp (q, "-shared") == 0)
shared_obj = 1;
  if (strcmp (q, "-static") == 0)
static_obj = 1;
  if (*q == '-' && q[1] == 'B')
{
  *c_ptr++ = xstrdup (q);
  if (q[2] == 0)
{
  q = extract_string ();
  *c_ptr++ = xstrdup (q);
}
}

Any of the extra options, if present, is causing c_argv to overflow.