[lkml]   [2008]   [Jul]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    SubjectRe: linux-next: build failure

    On Tue, 29 Jul 2008, Ingo Molnar wrote:
    > > @@ -287,7 +287,7 @@ static inline const cpumask_t *get_cpu_mask(unsigned int cpu)
    > > * gcc optimizes it out (it's a constant) and there's no huge stack
    > > * variable created:
    > > */
    > > -#define cpumask_of_cpu(cpu) ({ *get_cpu_mask(cpu); })
    > > +#define cpumask_of_cpu(cpu) (*get_cpu_mask(cpu))
    > hm, i'm wondering - is this a compiler bug?

    Not necessarily. The code is fragile.

    Doing a statement expression basically creates a new temporary variable
    with pretty much undefined scope. Taking the address of it *may* be
    optimized away to the original cpu_mask pointer, but it's not really a
    well-defined operation: there really _is_ a local temporary variable, and
    if you were to change things through the address-of thing, gcc would be
    buggy if it had done the optimization.

    So the "address-of statement expression" really is a dubious construct.

    That said, the change that Stephen introduces is _not_ a no-op. It very
    fundamentally changes the code - exactly because now there is no temporary
    value created any more: it's a real lvalue, and now anybody who does
    &cpumask_of_cpu(cpu) will fundamentally get the original pointer back,
    except it has lost the "const".

    And that's actually dangerous - exactly because it now loses the "const"
    thing, there may be people who end up modifying the result without
    getting any compile-time warnings.

    I would _seriously_ suggest that both the original code and Stephen's
    modified version is really bad. And you should have taken my interface
    as-is - one that returns a "const cpumask_t *", and nothing else.

    Anything else is simply fundamentally broken.


     \ /
      Last update: 2008-07-29 18:31    [W:0.020 / U:3.328 seconds]
    ©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site