In clang, how do you use per-function optimization attributes?

后端 未结 2 645
一生所求
一生所求 2020-12-01 12:53

I\'m trying to compile a specific function with no optimization using clang, in order to prevent certain security-related calls to memset() from be

相关标签:
2条回答
  • 2020-12-01 13:35

    As advocated by @dulacc in his comment, __attribute__ ((optnone)) works on clang 9.0.0 on Mac's High Sierra.

    0 讨论(0)
  • 2020-12-01 13:44

    As clang documentation says,

    Clang supports GCC’s gnu attribute namespace. All GCC attributes which are accepted with the __attribute__((foo)) syntax are also accepted as [[gnu::foo]]. This only extends to attributes which are specified by GCC (see the list of GCC function attributes, GCC variable attributes, and GCC type attributes). As with the GCC implementation, these attributes must appertain to the declarator-id in a declaration, which means they must go either at the start of the declaration or immediately after the name being declared.

    Try

    void* always_memset(void *b, int c, size_t len) [[gnu::optimize(0)]]
    

    or

    void* always_memset(void *b, int c, size_t len) __attribute__ ((optimize("0")));
    
    0 讨论(0)
提交回复
热议问题