Portable way of optimizing a single function or TU by a specific flag in both GCC and Clang

Viewed 78

GCC provides two ways of optimizing a function or TU with a specific optimization flag:

[[gnu::optimize("-ffast-math")]]
void foo() { /* ... */ }
#pragma GCC optimize("ffast-math")
void foo() { /* ... */ }

I have checked the Clang documentation, and it seems that only a way to either completely disable optimization for a function is provided ([[clang::optnone]]), or a way to control whether any optimization is enabled or disabled via #pragma clang optimize [on/off].

Is there a way to optimize a function or TU with a specific optimization flag in Clang, similarly to what GCC offers?

0 Answers
Related