llvm-project
llvm-project copied to clipboard
clang report error when compile with -D_FORTIFY_SOURCE=2
testcase
#include <stdio.h>
extern int printf(const char *format, ...);
int main() {
printf("Hello World\n");
return 0;
}
clang -O2 -D_FORTIFY_SOURCE=2 test_1.c
output:
extern int printf(const char *format, ...);
^
/usr/include/x86_64-linux-gnu/bits/stdio2.h:111:17: note: expanded from macro 'printf'
__printf_chk (__USE_FORTIFY_LEVEL - 1, __VA_ARGS__)
^
/usr/include/features.h:398:31: note: expanded from macro '__USE_FORTIFY_LEVEL'
# define __USE_FORTIFY_LEVEL 2
^
test_1.c:3:12: error: expected ')'
/usr/include/x86_64-linux-gnu/bits/stdio2.h:111:17: note: expanded from macro 'printf'
__printf_chk (__USE_FORTIFY_LEVEL - 1, __VA_ARGS__)
^
/usr/include/features.h:398:31: note: expanded from macro '__USE_FORTIFY_LEVEL'
# define __USE_FORTIFY_LEVEL 2
^
test_1.c:3:12: note: to match this '('
/usr/include/x86_64-linux-gnu/bits/stdio2.h:111:16: note: expanded from macro 'printf'
__printf_chk (__USE_FORTIFY_LEVEL - 1, __VA_ARGS__)
^
test_1.c:3:12: warning: a function declaration without a prototype is deprecated in all versions of C and is treated as a zero-parameter prototype in C2x, con
flicting with a previous declaration [-Wdeprecated-non-prototype]
extern int printf(const char *format, ...);
^
/usr/include/x86_64-linux-gnu/bits/stdio2.h:111:3: note: expanded from macro 'printf'
__printf_chk (__USE_FORTIFY_LEVEL - 1, __VA_ARGS__)
clang version:
clang version 15.0.5
Target: x86_64-unknown-linux-gnu
Thread model: posix
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Candidate multilib: .;@m64
Selected multilib: .;@m64
gcc 12.2 compile pass