Skip to content

Commit

Permalink
[libc] Adjust headers for some implementations of 'stdio.h'
Browse files Browse the repository at this point in the history
Summary:
This is sometimes a macro, undefine it so we can declare it as the GPU
needs.
  • Loading branch information
jhuber6 committed Nov 20, 2023
1 parent 4a02001 commit 88b672b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions clang/lib/Headers/llvm_libc_wrappers/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@
#define __LIBC_ATTRS __attribute__((device))
#endif

// Some headers provide these as macros. Temporarily undefine them so they do
// not conflict with any definitions for the GPU.

#pragma push_macro("stdout")
#pragma push_macro("stdin")
#pragma push_macro("stderr")

#undef stdout
#undef stderr
#undef stdin

#pragma omp begin declare target

#include <llvm-libc-decls/stdio.h>
Expand All @@ -29,6 +40,13 @@

#undef __LIBC_ATTRS

// Restore the original macros when compiling on the host.
#if !defined(__NVPTX__) && !defined(__AMDGPU__)
#pragma pop_macro("stdout")
#pragma pop_macro("stderr")
#pragma pop_macro("stdin")
#endif

#endif

#endif // __CLANG_LLVM_LIBC_WRAPPERS_STDIO_H__

0 comments on commit 88b672b

Please sign in to comment.