[libcxx-commits] [PATCH] D122536: [libc++] Optimize `exception_ptr`, especially for the empty case

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Apr 12 09:38:28 PDT 2022


philnik added a comment.

I think I'm abusing `__gnu_inline__` here a bit, but hey:

First of all, you have to have both the declaration and the definition inside the header, because neither clang nor GCC are happy to have an out of line definition of an already defined function.
`a.h`:

  #pragma once
  
  #ifdef EMIT_FUNCTION
  #  define GNU_INLINE
  #else
  #  define GNU_INLINE __attribute__((__gnu_inline__)) inline
  #endif
  
  struct A {
    GNU_INLINE int foo();
  };
  
  // Defining the function this way forces the compiler to emit the function when it's not marked inline,
  // but if it's maked '__attribute__((__gnu_inline__)) inline' it forces the compiler to _not_ emit the function.
  GNU_INLINE int A::foo() {
    return 1;
  }

`a.cpp`:

  #define EMIT_FUNCTION
  #include "a.h"

You have to use a different name and suppress a warning, but I left that away for simplicity.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122536/new/

https://reviews.llvm.org/D122536



More information about the libcxx-commits mailing list