This is an archive of the discontinued LLVM Phabricator instance.

[X86][bugfix] redefine __SSC_MARK to escape cpp string literal concatenation problem
ClosedPublic

Authored by xiangzhangllvm on Aug 25 2022, 12:53 AM.

Details

Summary

Redefine __SSC_MARK to escape cpp string literal concatenation problem.

This patch is to refine D129826
The old definition #define __MOVEGPR(__r1, __r2) "mov {%%"__r1 ", %%"__r2 "|"__r2 ", "__r1"};" is not support in c++11.

So this patch conservatively re-implement it.

For example:
The old way will cause build c++ file test.cpp fail:

#include <immintrin.h>
int main()
{
    __SSC_MARK(222);
    return 0;
}

clang test.cpp -std=c++11 -S

test.cpp:7:5: error: differing user-defined suffixes ('__r1' and '__r2') in string literal concatenation
    __SSC_MARK(222);

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptAug 25 2022, 12:53 AM
Herald added a subscriber: StephenFan. · View Herald Transcript
xiangzhangllvm requested review of this revision.Aug 25 2022, 12:53 AM
RKSimon edited the summary of this revision. (Show Details)Aug 25 2022, 3:06 AM
RKSimon added inline comments.Aug 25 2022, 3:11 AM
clang/lib/Headers/x86gprintrin.h
39

I assume all these defines are for internal use and only __SSC_MARK should be public?

In which case should the bottom of the header have something like this:

#undef __TMPGPR
#undef __SAVE_GPRBX
#undef __RESTORE_GPRBX
xiangzhangllvm added inline comments.Aug 25 2022, 5:46 PM
clang/lib/Headers/x86gprintrin.h
39

This will meet problem, Because these definitions in *.h file, the source file include it before.

so if we undef them like:

#define AA
#define BB AA
...
#undef AA
...
use BB  // The AA has been undef

Thank you!

RKSimon added inline comments.Aug 25 2022, 11:51 PM
clang/lib/Headers/x86gprintrin.h
39

Sorry - wasn't thinking that one through properly!

What about repeating the __SSC_MARK define - for 32/64 bit cases and without the other defines?

xiangzhangllvm added inline comments.Aug 27 2022, 6:29 PM
clang/lib/Headers/x86gprintrin.h
39

The user should make sure not repeating the __SSC_MARK when they include the x86gprintrin.h.
We have a lot of similar macro definition in clang/lib/Headers/*.h (e.g. xmmintrin.h::#define _MM_SHUFFLE)
Thanks!

ping, The patch is small : )

pengfei accepted this revision.Aug 30 2022, 7:13 PM

LGTM.

This revision is now accepted and ready to land.Aug 30 2022, 7:13 PM

Given it is only a c++ problem, it is also possible to solve it by using extern "C" { ... }? We use this method in some headers.

Given it is only a c++ problem, it is also possible to solve it by using extern "C" { ... }? We use this method in some headers.

I tried it before, it doesn't works for macro literal concatenation, I think the extern "C" { ... } mainly work for name decoration (e.g. Function signature)
Thanks for your reviewing!

Herald added a project: Restricted Project. · View Herald TranscriptAug 31 2022, 6:38 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript