[libc-commits] [PATCH] D154036: [libc] Add support for creating wrapper headers for offloading in clang
    Joseph Huber via Phabricator via libc-commits 
    libc-commits at lists.llvm.org
       
    Wed Jun 28 18:27:59 PDT 2023
    
    
  
jhuber6 added a comment.
For reference, here is what one of the newly generated headers looks like that is used.
  #ifndef __LLVM_LIBC_DECLARATIONS_STDIO_H
  #define __LLVM_LIBC_DECLARATIONS_STDIO_H
  
  #ifndef __LIBC_ATTRS
  #define __LIBC_ATTRS
  #endif
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  int puts(const char *__restrict) __LIBC_ATTRS;
  
  int fputs(const char *__restrict, FILE *__restrict) __LIBC_ATTRS;
  
  extern FILE * stdin __LIBC_ATTRS;
  extern FILE * stdout __LIBC_ATTRS;
  extern FILE * stderr __LIBC_ATTRS;
  
  #ifdef __cplusplus
  }
  #endif
Unfortunately I have already run into a few problems with the re-declarations given the GNU `libc` headers. Here is the error message when including `string.h` now,
  /home/jhuber/Documents/llvm/clang/lib/clang/17/include/llvm_libc_wrappers/llvm-libc-decls/string.h:54:8: error: 'strstr' is missing exception specification 'noexcept(true)'
     54 | char * strstr(const char *, const char *) __LIBC_ATTRS;
        |        ^
  /usr/include/string.h:343:1: note: previous declaration is here
    343 | strstr (const char *__haystack, const char *__needle) __THROW
        | ^
  5 errors generated.
This occurs for `memchr`, `strchr`, `strpbrk`, `strchr`, and `strstr`. If you define `__LIBC_ATTRS` to the `noexcept(true)` you get a different error,
  /home/jhuber/Documents/llvm/clang/lib/clang/17/include/llvm_libc_wrappers/llvm-libc-decls/string.h:54:8: error: functions that differ only in their return type cannot be overloaded
     54 | char * strstr(const char *, const char *) __LIBC_ATTRS;
        | ~~~~~~ ^
  /usr/include/string.h:343:1: note: previous definition is here
    343 | __extern_always_inline const char *
        |                              ~~~~~~
    344 | strstr (const char *__haystack, const char *__needle) __THROW
        | ^
Looking at the definitions, they look like this in the GNU headers,
  extern char *strstr (char *__haystack, const char *__needle)    
       __THROW __asm ("strstr") __attribute_pure__ __nonnull ((1, 2));    
  extern const char *strstr (const char *__haystack, const char *__needle)    
       __THROW __asm ("strstr") __attribute_pure__ __nonnull ((1, 2));
Does anyone have any suggestions on working around this? The other supported headers work as far as I can tell.
Repository:
  rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154036/new/
https://reviews.llvm.org/D154036
    
    
More information about the libc-commits
mailing list