[Bug c/78657] New: Using macro with _Pragma gives error: '#pragma' is not allowed here
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78657 Bug ID: 78657 Summary: Using macro with _Pragma gives error: '#pragma' is not allowed here Product: gcc Version: 5.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: jquinsey at entrenet dot com Target Milestone: --- The following two-line source file test.c: #define FOO _Pragma("GCC diagnostic push") 42 int foo = FOO; gives: gcc test.c -E # 1 "test.c" # 1 "" # 1 "" # 1 "test.c" int foo = # 2 "test.c" #pragma GCC diagnostic push # 2 "test.c" 42; gcc test.c test.c:2:1: error: expected expression before '#pragma' int foo = FOO; ^ g++ -x c++ test.c test.c:2:1: error: '#pragma' is not allowed here int foo = FOO; ^ This appears to be consistent across many versions of gcc and g++. For example, 5.4.0 from Cygwin, 5.1 from this test sample at http://ideone.com/6unk5c, and versions 4.4 through to 6.2 and 7 at https://godbolt.org/. The icc and clang compilers (from 3.2 upwards) seem handle this correctly. The text within the _Pragma doesn't seem relevant. Reversing the order of the two parts of the macro gives a slightly different error message for C: error: expected ',' or ';' before '#pragma'
[Bug c/78657] Using macro with _Pragma gives error: '#pragma' is not allowed here
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78657 --- Comment #2 from Joseph Quinsey --- The code int foo = #pragma GCC diagnostic push 42; gives exactly the same error messages. So this report is not about _Pragma per se, but about #pragma. But I cannot see where or if the standard addresses this. N1570 section 5.1.1.2, Translation phases, item 4 seems to say "All preprocessing directives are then deleted". Other preprocessor directives on the second line, such as int foo = #define BAR bar 42; are perfectly fine in gcc/g++ (including #include).
[Bug preprocessor/78657] Using macro with _Pragma gives error: '#pragma' is not allowed here
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78657 --- Comment #3 from Joseph Quinsey --- Similar or duplicate reports: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70811, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63326, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60875, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59367, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50387.
[Bug preprocessor/78657] Using macro with _Pragma gives error: '#pragma' is not allowed here
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78657 Joseph Quinsey changed: What|Removed |Added See Also||https://gcc.gnu.org/bugzill ||a/show_bug.cgi?id=70811 --- Comment #4 from Joseph Quinsey --- Similar or duplicate reports: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70811, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63326, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60875, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59367, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50387.
[Bug preprocessor/78657] Using macro with _Pragma gives error: '#pragma' is not allowed here
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78657 --- Comment #5 from Joseph Quinsey --- More similar or duplicate reports: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63612 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43027 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=37267
[Bug c/45036] New: Copying array to static location with -O3 -march=native causes SEGV at runtime
Source: int main(void) { static int foo[4]; int bar[4]; int i; for (i = 0; i < 4; i++) foo[i] = bar[i]; return 0; } Compile and run: gcc -O3 -march=native foobar.c a.exe Segmentation fault (core dumped) The loop is compiled as: movdqu -20(%ebp), %xmm0 xorl%eax, %eax movaps %xmm0, _foo.1548 Version: gcc -v Using built-in specs. Target: i686-pc-cygwin Configured with: /gnu/gcc/releases/packaging/4.3.4-3/gcc4-4.3.4-3/src/gcc-4.3.4/configure --srcdir=/gnu/gcc/releases/packaging/4.3.4-3/gcc4-4.3.4-3/src/gcc-4.3.4 --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --datadir=/usr/share --localstatedir=/var --sysconfdir=/etc --infodir=/usr/share/info --mandir=/usr/share/man --datadir=/usr/share --infodir=/usr/share/info --mandir=/usr/share/man -v --with-gmp=/usr --with-mpfr=/usr --enable-bootstrap --enable-version-specific-runtime-libs --with-slibdir=/usr/bin --libexecdir=/usr/lib --enable-static --enable-shared --enable-shared-libgcc --disable-__cxa_atexit --with-gnu-ld --with-gnu-as --with-dwarf2 --disable-sjlj-exceptions --enable-languages=ada,c,c++,fortran,java,objc,obj-c++ --disable-symvers --enable-libjava --program-suffix=-4 --enable-libgomp --enable-libssp --enable-libada --enable-threads=posix --with-arch=i686 --with-tune=generic --enable-libgcj-sublibs CC=gcc-4 CXX=g++-4 CC_FOR_TARGET=gcc-4 CXX_FOR_TARGET=g++-4 GNATMAKE_FOR_TARGET=gnatmake GNATBIND_FOR_TARGET=gnatbind AS=/opt/gcc-tools/bin/as.exe AS_FOR_TARGET=/opt/gcc-tools/bin/as.exe LD=/opt/gcc-tools/bin/ld.exe LD_FOR_TARGET=/opt/gcc-tools/bin/ld.exe --with-ecj-jar=/usr/share/java/ecj.jar Thread model: posix gcc version 4.3.4 20090804 (release) 1 (GCC) -- Summary: Copying array to static location with -O3 -march=native causes SEGV at runtime Product: gcc Version: 4.3.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jquinsey at entrenet dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45036
[Bug c/49915] New: Function call with 2-D arrays and -O2 (or strict-aliasing and inlining) gives random results
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49915 Summary: Function call with 2-D arrays and -O2 (or strict-aliasing and inlining) gives random results Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassig...@gcc.gnu.org ReportedBy: jquin...@entrenet.com Created attachment 24872 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24872 test.i from gcc -v -save-temps -O2 test.c A function call with two-dimensional arrays and -O2 (or the switches -fstrict-aliasing and -finline) gives random results. Complete source code (14 lines): static void copy(int n, int a[][n], int b[][n]) { int i, j; for (i = 0; i < 2; i++)// 'n' not used in this example for (j = 0; j < 2; j++) // 'n' hard-coded to 2 for simplicity b[i][j] = a[i][j]; } int main(int argc, char *argv[]) { int a[2][2] = {{1, 2},{3, 4}}; int b[2][2]; copy(2, a, b); printf("%d %d %d %d\n", b[0][0], b[0][1], b[1][0], b[1][1]); return 0; } Test results: gcc -O1 test.c && a.out 1 2 3 4 gcc -O2 test.c && a.out 12173125 -1079787588 -1079787736 13389812 gcc -O1 -fstrict-aliasing -finline test.c && a.out 12173125 -1080040260 -1080040408 13389812 All three tests also produced the (obvious) warning: test.c: In function 'main': test.c:12: warning: incompatible implicit declaration of built-in function 'printf' gcc -v -save-temps -O2 test.c Using built-in specs. Target: i386-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --disable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux Thread model: posix gcc version 4.1.2 20080704 (Red Hat 4.1.2-50) /usr/libexec/gcc/i386-redhat-linux/4.1.2/cc1 -E -quiet -v test.c -mtune=generic -O2 -fpch-preprocess -o test.i ignoring nonexistent directory "/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../i386-redhat-linux/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include /usr/lib/gcc/i386-redhat-linux/4.1.2/include /usr/include End of search list. /usr/libexec/gcc/i386-redhat-linux/4.1.2/cc1 -fpreprocessed test.i -quiet -dumpbase test.c -mtune=generic -auxbase test -O2 -version -o test.s GNU C version 4.1.2 20080704 (Red Hat 4.1.2-50) (i386-redhat-linux) compiled by GNU C version 4.1.2 20080704 (Red Hat 4.1.2-50). GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: d8d95095eb3c93dae4bed2137d559f95 test.c: In function 'main': test.c:12: warning: incompatible implicit declaration of built-in function 'printf' as -V -Qy -o test.o test.s GNU assembler version 2.17.50.0.6-14.el5 (i386-redhat-linux) using BFD version 2.17.50.0.6-14.el5 20061020 /usr/libexec/gcc/i386-redhat-linux/4.1.2/collect2 --eh-frame-hdr -m elf_i386 --hash-style=gnu -dynamic-linker /lib/ld-linux.so.2 /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crt1.o /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crti.o /usr/lib/gcc/i386-redhat-linux/4.1.2/crtbegin.o -L/usr/lib/gcc/i386-redhat-linux/4.1.2 -L/usr/lib/gcc/i386-redhat-linux/4.1.2 -L/usr/lib/gcc/i386-redhat-linux/4.1.2/../../.. test.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/i386-redhat-linux/4.1.2/crtend.o /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crtn.o