[Bug tree-optimization/53436] New: Volatile behaves strange with OpenMP
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53436 Bug #: 53436 Summary: Volatile behaves strange with OpenMP Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: o.mang...@googlemail.com When I compile the program below (gcc 4.7.0) > gcc -g -O3 -std=c99 -fopenmp volatile.c I find, that the volatile is ignored (when optimizing with -O or higher) for the statement while(!x); >From objdump I see that x is not reread for each loop > objdump -S a.out ... while(!x); sleep(1); printf("b finished\n"); 4007bf:bf 9c 08 40 00 mov$0x40089c,%edi 4007c4:e9 37 fe ff ff jmpq 400600 4007c9:eb fejmp4007c9 4007cb:0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) volatile bool x=false; #pragma omp parallel num_threads(2) shared(x) { if (omp_get_thread_num()==0) { sleep(1); 4007d0:bf 01 00 00 00 mov$0x1,%edi 4007d5:e8 66 fe ff ff callq 400640 ... At 4007c9 an unconditional (endless) loop is generated. I don't know if it is valid to use volatile this way in combination with OpenMP (maybe the standard doesn't cover it), but I guess that kind of optimization is at least a dangerous thing to do. --- volatile.c --- #include #include #include #include int main() { volatile bool x=false; #pragma omp parallel num_threads(2) { if (omp_get_thread_num()==0) { sleep(1); x=true; printf("a finished\n"); } else { while(!x); sleep(1); printf("b finished\n"); } } }
[Bug tree-optimization/53436] Volatile behaves strange with OpenMP
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53436 --- Comment #4 from o.mangold at googlemail dot com 2012-05-22 07:45:46 UTC --- (In reply to comment #3) > The testcase is not valid OpenMP, there is no flush operation in between the > store and reads, Is that also needed with volatile variables? Would be quite counterintuitive. > that said, there was a bug on the GCC side that I've fixed. Great, thanks.
[Bug tree-optimization/53436] Volatile behaves strange with OpenMP
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53436 --- Comment #6 from o.mangold at googlemail dot com 2012-05-22 08:32:03 UTC --- Yes, I get, that it's not a good way to do things, as (among other reasons) a volatile access is no memory fence. So accesses to other locations may not be ordered. But just for the sake of correctness, accesses should be ordered, if they all go to volatile variables, no? From the C99-standard, section 5.1.2.3: > At sequence points, volatile objects are stable in the sense that previous > accesses are complete and subsequent accesses have not yet occurred. This means buffering the reads to the volatile variable over multiple iterations of the while loop is not allowed, or do I get this wrong?
[Bug c++/53498] New: Compiler crashes during C++11 template magic compilation
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53498 Bug #: 53498 Summary: Compiler crashes during C++11 template magic compilation Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: o.mang...@googlemail.com I was trying to create some template magic to create a check for the existence of a function with variable number of arguments in C++11. Honestly, I don't know, if my code should compile through, as the problem happened when I was trying to figure out how to make it work. I got a compiler crash (which I guess shouldn't happen in any case). I cooked it down to the example below: > g++ -std=c++11 Crash.cxx g++: internal compiler error: Segmentation fault (program cc1plus) Please submit a full bug report, with preprocessed source if appropriate. See for instructions. kiwi/SafePrintf$g++ -std=c++11 Crash.cxx g++: internal compiler error: Segmentation fault (program cc1plus) Please submit a full bug report, with preprocessed source if appropriate. See for instructions. --- --- Crash.cxx --- template class A { public: template auto a(const U& u,const ARGS&... args,int) -> decltype(u.print(args...)) { } template int a(const U& u,const ARGS&... args,...) { } }; template class B { public: template static void b(const U& u,const ARGS&... args, decltype(A::a(u,args...,0)) dummy) { } }; int main() { B dummy; return 0; }
[Bug c++/53498] Compiler crashes during C++11 template magic compilation
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53498 --- Comment #2 from o.mangold at googlemail dot com 2012-05-27 15:33:16 UTC --- (In reply to comment #1) > While the test code is somewhat broken, Yes, I'm not surprised, this template stuff is a complete nightmare to me. As you mention it, you don't accidently know, how a correct version would look? I want to test, if the class U has a method print compatible with the given ARGS.
[Bug c++/53506] New: Variadic templates in combination with function pointer problem
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53506 Bug #: 53506 Summary: Variadic templates in combination with function pointer problem Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: o.mang...@googlemail.com The example code below appears to be correct to me, but does not compiler with g++. I tried it also with Intel compiler 12.1, and icc compiles it just fine. Neither the first, nor the second version of the call of a() seems to work. It can't deduce the template args from the function pointer and also does not accept explicit specification. I had expected at least the second version of the call to work. Is gcc wrong here or icc? > icpc -strict-ansi -std=c++0x fpointers.cxx > g++ -std=c++11 fpointers.cxx fpointers.cxx: In function ‘int main()’: fpointers.cxx:17:18: error: no matching function for call to ‘A::a(int (&)(int, int), int)’ fpointers.cxx:17:18: note: candidate is: fpointers.cxx:5:3: note: template static void A::a(RES (*)(FARGS ..., SARGS ...), FARGS ...) [with RES = RES; FARGS = {FARGS ...}; SARGS = {int}] fpointers.cxx:5:3: note: template argument deduction/substitution failed: fpointers.cxx:17:18: note: candidate expects 1 argument, 2 provided fpointers.cxx:18:27: error: no matching function for call to ‘A::a(int (&)(int, int), int)’ fpointers.cxx:18:27: note: candidate is: fpointers.cxx:5:3: note: template static void A::a(RES (*)(FARGS ..., SARGS ...), FARGS ...) [with RES = RES; FARGS = {FARGS ...}; SARGS = {int}] fpointers.cxx:5:3: note: template argument deduction/substitution failed: fpointers.cxx:18:27: note: candidate expects 1 argument, 2 provided --- fpointers.cxx --- template struct A { template static void a(RES(*func)(FARGS...,SARGS...),FARGS...) { } }; int foo(int,int) { return 0; } int main() { A::a(foo,0); A::a(foo,0); return 0; }
[Bug c++/53763] New: Missing error check on decltype when used within variadic template argument list
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53763 Bug #: 53763 Summary: Missing error check on decltype when used within variadic template argument list Classification: Unclassified Product: gcc Version: 4.7.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: o.mang...@googlemail.com In the example below, which is invalid code, no appropriate compiler error is reported. The code is wrong, because "decltype(A::a(2))" is invalid as A is a template class and would need template arguments. The compiler seams to silently skip the function call to B::b as if it was not there (it produces only a message for the first call of b). The only thing that is reported, though, is that y is used uninitialized. Apparently a later stage knows that the function was not called. It seems necessary that B takes a variadic template argument list for the problem to appear, but I couldn't nail it down further. --- compiler output --- > g++ -Wall -std=c++11 example.c example.c: In function ‘int main()’: example.c:26:12: warning: ‘y’ is used uninitialized in this function [-Wuninitialized] --- example.cxx --- #include template struct A { static int a(TYPE value) { return value; } }; template struct B { static int b(ARGS... args) { printf("hello world %i\n",args...); return 0; } }; int main() { int x = B::a(1))>::b(A::a(1)); int y = B::b(A::a(2)); return x+y; }