Skip to content

Conversation

@DominikAdamski
Copy link
Contributor

Declarations of stdio functions can be skipped for wrapper headers. Previous declarations of stdio functions caused compilation errors when the -std=c99 option is set.

Declarations of stdio functions can be skipped for wrapper
headers. Previous declarations of stdio functions caused
compilation errors when the -std=c99 option is set.
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics labels Nov 17, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 17, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-x86

Author: Dominik Adamski (DominikAdamski)

Changes

Declarations of stdio functions can be skipped for wrapper headers. Previous declarations of stdio functions caused compilation errors when the -std=c99 option is set.


Full diff: https://github.com/llvm/llvm-project/pull/168386.diff

1 Files Affected:

  • (modified) clang/lib/Headers/llvm_libc_wrappers/stdio.h (+16-1)
diff --git a/clang/lib/Headers/llvm_libc_wrappers/stdio.h b/clang/lib/Headers/llvm_libc_wrappers/stdio.h
index 950f91b3763e8..99b58c1b23254 100644
--- a/clang/lib/Headers/llvm_libc_wrappers/stdio.h
+++ b/clang/lib/Headers/llvm_libc_wrappers/stdio.h
@@ -60,7 +60,22 @@
 
 #pragma omp begin declare target
 
-#include <llvm-libc-decls/stdio.h>
+#ifndef __LIBC_ATTRS
+#define __LIBC_ATTRS
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern FILE * stderr; __LIBC_ATTRS;
+
+extern FILE * stdin; __LIBC_ATTRS;
+
+extern FILE * stdout; __LIBC_ATTRS;
+
+#ifdef __cplusplus
+}
+#endif
 
 #pragma omp end declare target
 

Copy link
Contributor

@jhuber6 jhuber6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this cause errors? I figured redeclarations of externs was legal. Maybe the attributes?

@github-actions
Copy link

github-actions bot commented Nov 17, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@DominikAdamski
Copy link
Contributor Author

Why does this cause errors? I figured redeclarations of externs was legal. Maybe the attributes?

The problem relates to different declarations of the stdio functions if std=c99 is set.

@DominikAdamski
Copy link
Contributor Author

Fixed by PR: #168438

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants