Clang tool: Force-undefine feature preprocessor defines

To avoid code that is being parsed to include the intrinsics headers, undefine
a few key preprocessor defines.

PiperOrigin-RevId: 539878995
Change-Id: I8afb7cbdadcab3214c943c0acb9006e8bcc30611
This commit is contained in:
Christian Blichmann 2023-06-13 00:37:30 -07:00 committed by Copybara-Service
parent 654668fc4e
commit f2048d028f

View File

@ -145,6 +145,7 @@ bool GeneratorFactory::runInvocation(
// TODO(b/222241644): Figure out how to deal with intrinsics properly // TODO(b/222241644): Figure out how to deal with intrinsics properly
// Note: The definitions below just need to parse, they don't need to // Note: The definitions below just need to parse, they don't need to
// compile into useful code. // compile into useful code.
// Intel
"__builtin_ia32_cvtsbf162ss_32=[](auto)->long long{return 0;}", "__builtin_ia32_cvtsbf162ss_32=[](auto)->long long{return 0;}",
"__builtin_ia32_paddsb128=", "__builtin_ia32_paddsb128=",
"__builtin_ia32_paddsb256=", "__builtin_ia32_paddsb256=",
@ -176,6 +177,33 @@ bool GeneratorFactory::runInvocation(
"__builtin_ia32_reduce_mul_q512=[](auto)->long long{return 0;}", "__builtin_ia32_reduce_mul_q512=[](auto)->long long{return 0;}",
}) { }) {
options.addMacroDef(def); options.addMacroDef(def);
// To avoid code to include header with compiler intrinsics, undefine a few
// key pre-defines.
for (
const auto& undef : {
// ARM ISA (see
// https://developer.arm.com/documentation/101028/0010/Feature-test-macros)
"__ARM_NEON",
"__ARM_NEON__",
// Intel
"__AVX__",
"__AVX2__",
"__AVX512BW__",
"__AVX512CD__",
"__AVX512DQ__",
"__AVX512F__",
"__AVX512VL__",
"__SSE__",
"__SSE2__",
"__SSE2_MATH__",
"__SSE3__",
"__SSE4_1__",
"__SSE4_2__",
"__SSE_MATH__",
"__SSSE3__",
}) {
options.addMacroUndef(undef);
}
} }
return FrontendActionFactory::runInvocation(std::move(invocation), files, return FrontendActionFactory::runInvocation(std::move(invocation), files,
std::move(pch_container_ops), std::move(pch_container_ops),