On Sun, Nov 15, 2020 at 11:53 AM Uecker, Martin <martin.uec...@med.uni-goettingen.de> wrote: > > > > On Wed, Nov 04, 2020 at 07:31:42PM +0100, Uros Bizjak wrote: > > > Hello! > > > > > > I was looking at the recent linux patch series [1] where segment > > > qualifiers (named address spaces) were introduced to handle percpu > > > variables. In the patch [2], the author mentions that: > > > > > > --q-- > > > Unfortunately, gcc does not provide a way to remove segment > > > qualifiers, which is needed to use typeof() to create local instances > > > of the per-cpu variable. For this reason, do not use the segment > > > qualifier for per-cpu variables, and do casting using the segment > > > qualifier instead. > > > --/q-- > > > > C in general does not provide means to strip qualifiers. We recently had > > a _lot_ of 'fun' trying to strip volatile from a type, see here: > > > > https://lore.kernel.org/lkml/875zimp0ay....@mpe.ellerman.id.au > > > > which resulted in the current __unqual_scalar_typeof() hack. > > > > If we're going to do compiler extentions here, can we pretty please have > > a sane means of modifying qualifiers in general? > > Another way to drop qualifiers is using a cast. So you > can use typeof twice: > > typeof((typeof(_var))_var) tmp__; > > This also works for non-scalars but this is a GCC extension. > > > WG14 plans to standardize typeof. I would like to hear opinion > whether we should have typeof drop qualifiers or not. > > Currently, it does not do this on all compilers I tested > (except _Atomic on GCC) and there are also use cases for > keeping qualifiers. This is an argument for keeping qualifiers > should we standardize it, but then we need a way to drop > qualifiers. > > > lvalue conversion drops qualifers in C. In GCC, this is not > implemented correctly as it is unobvervable in standard C > (but it using typeof). > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97702 > > A have a working patch in preparation to change this. Then you > could use > > typeof( ((void)0, x) ) > > to drop qualifiers. But this would then > also do array-to-pointer conversion. I am not sure > whether this is a problem. > > > For fun, I tried to come up with a standard+typeof-compliant > macro that drops qualifiers for all types without doing > array-to-pointer conversion > > https://github.com/uecker/unqual/blob/main/unqual.c > > but recursing into multi-dim. array types causes > a macro-explosion.... (but maybe multi-dim arrays are > also not too important) > > > Of course, we could also introduce a new feature for > dropping qualifiers. Thoughts?
Just add a new qualifier that un-qualifies? _Unqual volatile T x; is T with volatile (evenually) removed. Or just a way to drop all using _Unqual? _Unqual T x; removing all qualifiers from T. Or add a special _Unqual_all to achieve that. I think removing a specific qualification is useful. Leaves cases like _Unqual volatile volatile T x; to be specified (that is ordering and cancellation of the unqual and qual variants of qualifiers). Richard. > > Best, > Martin > > > > _ > >