Hi all, I'm seeing a new build issue with the linux kernel: CC kernel/smpboot.o In file included from include/linux/mutex.h:15:0, from include/linux/kernfs.h:13, from include/linux/sysfs.h:15, from include/linux/kobject.h:21, from include/linux/device.h:17, from include/linux/node.h:17, from include/linux/cpu.h:16, from kernel/smpboot.c:4: include/linux/spinlock_types.h:82:2: error: initializer element is not constant (spinlock_t ) __SPIN_LOCK_INITIALIZER(lockname) ^ include/linux/mutex.h:112:18: note: in expansion of macro ‘__SPIN_LOCK_UNLOCKED’ , .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) \ ^ include/linux/mutex.h:118:27: note: in expansion of macro ‘__MUTEX_INITIALIZER’ struct mutex mutexname = __MUTEX_INITIALIZER(mutexname) ^ kernel/smpboot.c:80:8: note: in expansion of macro ‘DEFINE_MUTEX’ static DEFINE_MUTEX(smpboot_threads_lock); ^ include/linux/spinlock_types.h:82:2: note: (near initialization for ‘smpboot_threads_lock.wait_lock’) (spinlock_t ) __SPIN_LOCK_INITIALIZER(lockname) ^ include/linux/mutex.h:112:18: note: in expansion of macro ‘__SPIN_LOCK_UNLOCKED’ , .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) \ ^ include/linux/mutex.h:118:27: note: in expansion of macro ‘__MUTEX_INITIALIZER’ struct mutex mutexname = __MUTEX_INITIALIZER(mutexname) ^ kernel/smpboot.c:80:8: note: in expansion of macro ‘DEFINE_MUTEX’ static DEFINE_MUTEX(smpboot_threads_lock); ^ make[1]: *** [kernel/smpboot.o] Error 1 make: *** [kernel/smpboot.o] Error 2 This was bisected down to: commit b2601928b5bf34a817b5a9a2a371c476018e634d Author: mpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Wed Oct 15 10:08:00 2014 +0000 * doc/invoke.texi: Update to reflect that GNU11 is the default mode for C. * c-common.h (c_language_kind): Update comment. c-family/ * c-opts.c (c_common_init_options): Make -std=gnu11 the default for C. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@216247 138bc75d-0d04-0410-961f-82ee72b054a4
I Just reported this to the mailing list: https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01640.html The reduced testcase that shows the difference between GNU 89 and GNU 11/99: typedef struct { volatile unsigned int lock; } arch_rwlock_t; typedef struct { arch_rwlock_t raw_lock; } rwlock_t; static rwlock_t step_hook_lock = (rwlock_t) { .raw_lock = { 0 }, };
I believe we should just allow initializing objects with static storage duration with compound literals even in gnu99/gnu11.
(But warn with -pedantic.)
Author: mpolacek Date: Fri Oct 17 21:02:54 2014 New Revision: 216416 URL: https://gcc.gnu.org/viewcvs?rev=216416&root=gcc&view=rev Log: PR c/63567 * c-typeck.c (digest_init): Allow initializing objects with static storage duration with compound literals even in C99 and add pedwarn for it. * gcc.dg/pr61096-1.c: Change dg-error into dg-warning. * gcc.dg/pr63567-1.c: New test. * gcc.dg/pr63567-2.c: New test. Added: trunk/gcc/testsuite/gcc.dg/pr63567-1.c trunk/gcc/testsuite/gcc.dg/pr63567-2.c Modified: trunk/gcc/c/ChangeLog trunk/gcc/c/c-typeck.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gcc.dg/pr61096-1.c
Should be fixed. I did what I outlined in #c2 and #c3.
I'm still seeing the issue with the fix applied: CC kernel/smpboot.o In file included from include/linux/mutex.h:15:0, from include/linux/kernfs.h:13, from include/linux/sysfs.h:15, from include/linux/kobject.h:21, from include/linux/device.h:17, from include/linux/node.h:17, from include/linux/cpu.h:16, from kernel/smpboot.c:4: include/linux/spinlock_types.h:82:2: error: initializer element is not constant (spinlock_t ) __SPIN_LOCK_INITIALIZER(lockname) ^ include/linux/mutex.h:112:18: note: in expansion of macro ‘__SPIN_LOCK_UNLOCKED’ , .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) \ ^ include/linux/mutex.h:118:27: note: in expansion of macro ‘__MUTEX_INITIALIZER’ struct mutex mutexname = __MUTEX_INITIALIZER(mutexname) ^ kernel/smpboot.c:80:8: note: in expansion of macro ‘DEFINE_MUTEX’ static DEFINE_MUTEX(smpboot_threads_lock); ^ include/linux/spinlock_types.h:82:2: note: (near initialization for ‘smpboot_threads_lock.wait_lock’) (spinlock_t ) __SPIN_LOCK_INITIALIZER(lockname) ^ include/linux/mutex.h:112:18: note: in expansion of macro ‘__SPIN_LOCK_UNLOCKED’ , .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) \ ^ include/linux/mutex.h:118:27: note: in expansion of macro ‘__MUTEX_INITIALIZER’ struct mutex mutexname = __MUTEX_INITIALIZER(mutexname) ^ kernel/smpboot.c:80:8: note: in expansion of macro ‘DEFINE_MUTEX’ static DEFINE_MUTEX(smpboot_threads_lock);
Well, can you give me preprocessed source code then? Because the short testcase in Comment 1 is accepted now.
Created attachment 33756 [details] Preprocessed kernel/smpboot.c
I've attached the preprocessed kernel/smpboot.c. The problem seems to be in line 24563: static struct mutex smpboot_threads_lock = { .count = { (1) } , .wait_lock = (spinlock_t ) { { .rlock = { .raw_lock = { { 0 } }, .magic = 0xdead4ead, .owner_cpu = -1, .owner = ((void *)-1L), .dep_map = { .name = "smpboot_threads_lock.wait_lock" } } } } , .wait_list = { &(smpboot_threads_lock.wait_list), &(smpboot_threads_lock.wait_list) } , .magic = &smpboot_threads_lock , .dep_map = { .name = "smpboot_threads_lock" } };
Thanks. This fixes it (I need to write a proper testcase and test it). 2014-10-18 Marek Polacek <polacek@redhat.com> PR c/63567 * c-typeck.c (output_init_element): Allow initializing objects with static storage duration with compound literals even in C99 and add pedwarn for it. diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c index 0dd3366..ee874da 100644 --- gcc/c/c-typeck.c +++ gcc/c/c-typeck.c @@ -8251,11 +8251,14 @@ output_init_element (location_t loc, tree value, tree origtype, value = array_to_pointer_conversion (input_location, value); if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR - && require_constant_value && !flag_isoc99 && pending) + && require_constant_value && pending) { /* As an extension, allow initializing objects with static storage duration with compound literals (which are then treated just as the brace enclosed list they contain). */ + if (flag_isoc99) + pedwarn_init (loc, OPT_Wpedantic, "initializer element is not " + "constant"); tree decl = COMPOUND_LITERAL_EXPR_DECL (value); value = DECL_INITIAL (decl); }
That does the trick. Thanks! A different issue with the patch I've previously bisected came up, I'll open a different bug report for that.
Author: mpolacek Date: Sun Oct 19 16:47:35 2014 New Revision: 216440 URL: https://gcc.gnu.org/viewcvs?rev=216440&root=gcc&view=rev Log: PR c/63567 * c-typeck.c (output_init_element): Allow initializing objects with static storage duration with compound literals even in C99 and add pedwarn for it. * gcc.dg/pr63567-3.c: New test. * gcc.dg/pr63567-4.c: New test. Added: trunk/gcc/testsuite/gcc.dg/pr63567-3.c trunk/gcc/testsuite/gcc.dg/pr63567-4.c Modified: trunk/gcc/c/ChangeLog trunk/gcc/c/c-typeck.c trunk/gcc/testsuite/ChangeLog
Now fixed for real.