Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of && in the context of bitwise_cast<void*>(&&__opcode);

Tags:

c++

webkit

I am looking at the code below which comes from JavascriptCore and I don't know what the meaning of the && is in the context below. An address of an address does not really make sense.

So can someone explain what the && means in the context below.

(the bitwise_cast uses a union to avoid strict aliasing problems that come with a reinterpret_cast)

The code below compiles on clang (and presumably gcc) but does not compile on our own proprietary C++ compiler.

The full source can be found here.

#if ENABLE(COMPUTED_GOTO_OPCODES)
    Opcode* opcodeMap = LLInt::opcodeMap();
    #define OPCODE_ENTRY(__opcode, length) \
    opcodeMap[__opcode] = bitwise_cast<void*>(&&__opcode); //<---- The double && 
    FOR_EACH_OPCODE_ID(OPCODE_ENTRY)
    #undef OPCODE_ENTRY

    #define LLINT_OPCODE_ENTRY(__opcode, length) \
        opcodeMap[__opcode] = bitwise_cast<void*>(&&__opcode);

    FOR_EACH_LLINT_NATIVE_HELPER(LLINT_OPCODE_ENTRY)
    #undef LLINT_OPCODE_ENTRY
#endif
like image 597
doron Avatar asked Jan 09 '23 06:01

doron


1 Answers

That's a GCC extension: computed goto.

Given a goto label

label:

in standard C++, you can only jump to it directly:

goto label;

but GCC allows you to store its address with a non-standard use of && as a unary operator (analogous to & for taking the address of an object, function, or member):

void * ptr = &&label;

and use that pointer later:

goto *ptr;

It looks like you can disable this through the preprocessor, for your compiler which doesn't have this extension. It will use some scheme based on a switch statement instead of computed jump label.

like image 115
Mike Seymour Avatar answered Jan 18 '23 19:01

Mike Seymour