[cfe-dev] [RFC] `_Mangle` compiler extension.

Kristina Brooks via cfe-dev cfe-dev at lists.llvm.org
Sat Nov 17 03:22:37 PST 2018


Hi,

I was wondering, is there any interest in the following compiler
extension for Clang (converting strings to identifiers/symbols) and
tackling the issue with C++ mangling and the fact that there is no
way to generically address anything in another TU without going through
`dlsym` or alike unless it's exposed via a header.

This simple extension allows for doing just that, it's something I wrote
out of need mostly to save time and simplify a lot of existing code
in some codebase based around the idea of components.

The test below should be illustrative enough of what the extension does
and as far as its applications. It's already developed and has test
coverage in my fork as well as necessary diagnostics so I was wondering
if there was general interest in seeing this upstreamed.

I don't mind if there's no interest, since as I said, this was written
for the sake of convenience, others may have different views on whether
this is useful or not.

Thanks.
- Kristina

-----------------------------------------------------------------------

// RUN: %clang_cc1 -E %s | FileCheck -strict-whitespace %s

#define SECOND_PART "createInstance"
#define WITH_PREFIX(_rest) "_Z" _rest

// Reference
1: _Mangle("_ZNK{ MyClassName }{ createInstance }Ei")

// String macro
2: _Mangle("_ZNK{ MyClassName }{ " SECOND_PART " }Ei")

// Macro with parameter
3: _Mangle(WITH_PREFIX("NK{ MyClassName }{ createInstance }Ei"))

// Whitespace insigificance
4: _Mangle("_ZNK  {MyClassName}{createInstance}Ei")

// Less synthetic example
5: _Mangle("_ZN{google}{protobuf}{RepeatedField}IdED2Ev")

// CHECK: {{^}}1:_ZNK11MyClassName14createInstanceEi
// CHECK: {{^}}2:_ZNK11MyClassName14createInstanceEi
// CHECK: {{^}}3:_ZNK11MyClassName14createInstanceEi
// CHECK: {{^}}4:_ZNK11MyClassName14createInstanceEi
// CHECK: {{^}}5:_ZN6google8protobuf13RepeatedFieldIdED2Ev

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4010 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181117/e3409514/attachment.bin>


More information about the cfe-dev mailing list