Skip to content

Commit 88b672b

Browse files
committed
[libc] Adjust headers for some implementations of 'stdio.h'
Summary: This is sometimes a macro, undefine it so we can declare it as the GPU needs.
1 parent 4a02001 commit 88b672b

File tree

1 file changed

+18
-0
lines changed
  • clang/lib/Headers/llvm_libc_wrappers

1 file changed

+18
-0
lines changed

clang/lib/Headers/llvm_libc_wrappers/stdio.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@
2121
#define __LIBC_ATTRS __attribute__((device))
2222
#endif
2323

24+
// Some headers provide these as macros. Temporarily undefine them so they do
25+
// not conflict with any definitions for the GPU.
26+
27+
#pragma push_macro("stdout")
28+
#pragma push_macro("stdin")
29+
#pragma push_macro("stderr")
30+
31+
#undef stdout
32+
#undef stderr
33+
#undef stdin
34+
2435
#pragma omp begin declare target
2536

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

3041
#undef __LIBC_ATTRS
3142

43+
// Restore the original macros when compiling on the host.
44+
#if !defined(__NVPTX__) && !defined(__AMDGPU__)
45+
#pragma pop_macro("stdout")
46+
#pragma pop_macro("stderr")
47+
#pragma pop_macro("stdin")
48+
#endif
49+
3250
#endif
3351

3452
#endif // __CLANG_LLVM_LIBC_WRAPPERS_STDIO_H__

0 commit comments

Comments
 (0)