<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - clang does not build binutils/gdb when -D_FORTIFY_SOURCE=2 and -O2 are set."
   href="https://llvm.org/bugs/show_bug.cgi?id=23562">23562</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang does not build binutils/gdb when -D_FORTIFY_SOURCE=2 and -O2 are set.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>yunlian@chromium.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Below is a reduced case when building binutils/gdb with clang. This code
compiles well if -D_FORTIFY_SOURCE=2 and -O2 are not set. It pops out the
following error if -D_FORTIFY_SOURCE=2 and -O2 are set. gcc does not have this
problem.

cat f.c
<<<<<<<<
#define _GNU_SOURCE
#define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m)))

#define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
ATTRIBUTE_NONNULL(m)
#define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3)
#include <stdio.h>
extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2;
<span class="quote">>>>>>>>>>>>>>>></span >



 /usr/bin/clang   -D_FORTIFY_SOURCE=2 -c -O2 ./f.c -o a
-B/usr/libexec/gcc/x86_64-cros-linux-gnu -target x86_64-cros-linux-gnu




./f.c:30:12: error: expected parameter declarator
extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2;
           ^
/usr/include/bits/stdio2.h:199:24: note: expanded from macro 'asprintf'
  __asprintf_chk (ptr, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__)
                       ^
/usr/include/features.h:346:31: note: expanded from macro '__USE_FORTIFY_LEVEL'
#  define __USE_FORTIFY_LEVEL 2
                              ^
./f.c:30:12: error: expected ')'
/usr/include/bits/stdio2.h:199:24: note: expanded from macro 'asprintf'
  __asprintf_chk (ptr, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__)
                       ^
/usr/include/features.h:346:31: note: expanded from macro '__USE_FORTIFY_LEVEL'
#  define __USE_FORTIFY_LEVEL 2
                              ^
./f.c:30:12: note: to match this '('
/usr/include/bits/stdio2.h:199:18: note: expanded from macro 'asprintf'
  __asprintf_chk (ptr, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__)
                 ^
./f.c:30:50: error: '__nonnull__' attribute parameter 1 is out of bounds
extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2;
                                                 ^~~~~~~~~~~~~~~~~~
./f.c:26:28: note: expanded from macro 'ATTRIBUTE_PRINTF_2'
#define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3)
                           ^                ~
./f.c:25:80: note: expanded from macro 'ATTRIBUTE_PRINTF'
#define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
ATTRIBUTE_NONNULL(m)
                                                                              
^
./f.c:23:46: note: expanded from macro 'ATTRIBUTE_NONNULL'
#define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m)))
                                             ^
./f.c:30:50: error: '__format__' attribute parameter 2 is out of bounds
extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2;
                                                 ^~~~~~~~~~~~~~~~~~
./f.c:26:28: note: expanded from macro 'ATTRIBUTE_PRINTF_2'
#define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3)
                           ^                ~
./f.c:25:48: note: expanded from macro 'ATTRIBUTE_PRINTF'
#define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
ATTRIBUTE_NONNULL(m)
                                               ^
./f.c:30:12: error: conflicting types for '__asprintf_chk'
extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2;
           ^
/usr/include/bits/stdio2.h:199:3: note: expanded from macro 'asprintf'
  __asprintf_chk (ptr, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__)
  ^
/usr/include/bits/stdio2.h:158:12: note: previous declaration is here
extern int __asprintf_chk (char **__restrict __ptr, int __flag,
           ^
5 errors generated.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>