[clang] 8c48405 - Wrap C APIs with pragmas enforcing -Werror=strict-prototypes
Duncan P. N. Exon Smith via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 19 13:18:51 PST 2019
Author: Duncan P. N. Exon Smith
Date: 2019-11-19T13:18:43-08:00
New Revision: 8c48405069085a2c8b6b80816eda99e5dad31fc1
URL: https://github.com/llvm/llvm-project/commit/8c48405069085a2c8b6b80816eda99e5dad31fc1
DIFF: https://github.com/llvm/llvm-project/commit/8c48405069085a2c8b6b80816eda99e5dad31fc1.diff
LOG: Wrap C APIs with pragmas enforcing -Werror=strict-prototypes
Force `-Werror=strict-prototypes` so that C API tests fail to compile if
we add a non-prototype declaration. This should help avoid regressions
like bddecba4b333f7772029b4937d2c34f9f2fda6ca was fixing.
https://reviews.llvm.org/D70285
rdar://problem/57203137
Added:
clang/include/clang-c/ExternC.h
llvm/include/llvm-c/ExternC.h
Modified:
clang/include/clang-c/BuildSystem.h
clang/include/clang-c/CXCompilationDatabase.h
clang/include/clang-c/CXErrorCode.h
clang/include/clang-c/CXString.h
clang/include/clang-c/Documentation.h
clang/include/clang-c/FatalErrorHandler.h
clang/include/clang-c/Index.h
clang/include/clang-c/Platform.h
llvm/include/llvm-c/Analysis.h
llvm/include/llvm-c/BitReader.h
llvm/include/llvm-c/BitWriter.h
llvm/include/llvm-c/Comdat.h
llvm/include/llvm-c/Core.h
llvm/include/llvm-c/DebugInfo.h
llvm/include/llvm-c/Disassembler.h
llvm/include/llvm-c/Error.h
llvm/include/llvm-c/ErrorHandling.h
llvm/include/llvm-c/ExecutionEngine.h
llvm/include/llvm-c/IRReader.h
llvm/include/llvm-c/Initialization.h
llvm/include/llvm-c/LinkTimeOptimizer.h
llvm/include/llvm-c/Linker.h
llvm/include/llvm-c/Object.h
llvm/include/llvm-c/OrcBindings.h
llvm/include/llvm-c/Remarks.h
llvm/include/llvm-c/Support.h
llvm/include/llvm-c/Target.h
llvm/include/llvm-c/TargetMachine.h
llvm/include/llvm-c/Transforms/AggressiveInstCombine.h
llvm/include/llvm-c/Transforms/Coroutines.h
llvm/include/llvm-c/Transforms/IPO.h
llvm/include/llvm-c/Transforms/InstCombine.h
llvm/include/llvm-c/Transforms/PassManagerBuilder.h
llvm/include/llvm-c/Transforms/Scalar.h
llvm/include/llvm-c/Transforms/Utils.h
llvm/include/llvm-c/Transforms/Vectorize.h
llvm/include/llvm-c/Types.h
llvm/include/llvm-c/lto.h
Removed:
################################################################################
diff --git a/clang/include/clang-c/BuildSystem.h b/clang/include/clang-c/BuildSystem.h
index 8f26a8611719..4e9f6dee0279 100644
--- a/clang/include/clang-c/BuildSystem.h
+++ b/clang/include/clang-c/BuildSystem.h
@@ -14,13 +14,12 @@
#ifndef LLVM_CLANG_C_BUILDSYSTEM_H
#define LLVM_CLANG_C_BUILDSYSTEM_H
-#include "clang-c/Platform.h"
#include "clang-c/CXErrorCode.h"
#include "clang-c/CXString.h"
+#include "clang-c/ExternC.h"
+#include "clang-c/Platform.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_CLANG_C_EXTERN_C_BEGIN
/**
* \defgroup BUILD_SYSTEM Build system utilities
@@ -148,9 +147,7 @@ CINDEX_LINKAGE void clang_ModuleMapDescriptor_dispose(CXModuleMapDescriptor);
* @}
*/
-#ifdef __cplusplus
-}
-#endif
+LLVM_CLANG_C_EXTERN_C_END
#endif /* CLANG_C_BUILD_SYSTEM_H */
diff --git a/clang/include/clang-c/CXCompilationDatabase.h b/clang/include/clang-c/CXCompilationDatabase.h
index 2669c1a792c1..2b336e5464a2 100644
--- a/clang/include/clang-c/CXCompilationDatabase.h
+++ b/clang/include/clang-c/CXCompilationDatabase.h
@@ -15,12 +15,11 @@
#ifndef LLVM_CLANG_C_CXCOMPILATIONDATABASE_H
#define LLVM_CLANG_C_CXCOMPILATIONDATABASE_H
-#include "clang-c/Platform.h"
#include "clang-c/CXString.h"
+#include "clang-c/ExternC.h"
+#include "clang-c/Platform.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_CLANG_C_EXTERN_C_BEGIN
/** \defgroup COMPILATIONDB CompilationDatabase functions
* \ingroup CINDEX
@@ -169,8 +168,7 @@ clang_CompileCommand_getMappedSourceContent(CXCompileCommand, unsigned I);
* @}
*/
-#ifdef __cplusplus
-}
-#endif
+LLVM_CLANG_C_EXTERN_C_END
+
#endif
diff --git a/clang/include/clang-c/CXErrorCode.h b/clang/include/clang-c/CXErrorCode.h
index fed195ec1f33..b3a0b9d66d5f 100644
--- a/clang/include/clang-c/CXErrorCode.h
+++ b/clang/include/clang-c/CXErrorCode.h
@@ -14,11 +14,10 @@
#ifndef LLVM_CLANG_C_CXERRORCODE_H
#define LLVM_CLANG_C_CXERRORCODE_H
+#include "clang-c/ExternC.h"
#include "clang-c/Platform.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_CLANG_C_EXTERN_C_BEGIN
/**
* Error codes returned by libclang routines.
@@ -57,8 +56,7 @@ enum CXErrorCode {
CXError_ASTReadError = 4
};
-#ifdef __cplusplus
-}
-#endif
+LLVM_CLANG_C_EXTERN_C_END
+
#endif
diff --git a/clang/include/clang-c/CXString.h b/clang/include/clang-c/CXString.h
index 1eb3442ccb24..f117010c71a4 100644
--- a/clang/include/clang-c/CXString.h
+++ b/clang/include/clang-c/CXString.h
@@ -14,11 +14,10 @@
#ifndef LLVM_CLANG_C_CXSTRING_H
#define LLVM_CLANG_C_CXSTRING_H
+#include "clang-c/ExternC.h"
#include "clang-c/Platform.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_CLANG_C_EXTERN_C_BEGIN
/**
* \defgroup CINDEX_STRING String manipulation routines
@@ -64,8 +63,7 @@ CINDEX_LINKAGE void clang_disposeStringSet(CXStringSet *set);
* @}
*/
-#ifdef __cplusplus
-}
-#endif
+LLVM_CLANG_C_EXTERN_C_END
+
#endif
diff --git a/clang/include/clang-c/Documentation.h b/clang/include/clang-c/Documentation.h
index 4af8c93a367e..ad3dd3bc78be 100644
--- a/clang/include/clang-c/Documentation.h
+++ b/clang/include/clang-c/Documentation.h
@@ -15,11 +15,10 @@
#ifndef LLVM_CLANG_C_DOCUMENTATION_H
#define LLVM_CLANG_C_DOCUMENTATION_H
+#include "clang-c/ExternC.h"
#include "clang-c/Index.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_CLANG_C_EXTERN_C_BEGIN
/**
* \defgroup CINDEX_COMMENT Comment introspection
@@ -545,10 +544,7 @@ CINDEX_LINKAGE CXString clang_FullComment_getAsXML(CXComment Comment);
* @}
*/
-
-#ifdef __cplusplus
-}
-#endif
+LLVM_CLANG_C_EXTERN_C_END
#endif /* CLANG_C_DOCUMENTATION_H */
diff --git a/clang/include/clang-c/ExternC.h b/clang/include/clang-c/ExternC.h
new file mode 100644
index 000000000000..384f24d47b0b
--- /dev/null
+++ b/clang/include/clang-c/ExternC.h
@@ -0,0 +1,39 @@
+/*===- clang-c/ExternC.h - Wrapper for 'extern "C"' ---------------*- C -*-===*\
+|* *|
+|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
+|* Exceptions. *|
+|* See https://llvm.org/LICENSE.txt for license information. *|
+|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
+|* *|
+|*===----------------------------------------------------------------------===*|
+|* *|
+|* This file defines an 'extern "C"' wrapper. *|
+|* *|
+\*===----------------------------------------------------------------------===*/
+
+#ifndef LLVM_CLANG_C_EXTERN_C_H
+#define LLVM_CLANG_C_EXTERN_C_H
+
+#ifdef __clang__
+#define LLVM_CLANG_C_STRICT_PROTOTYPES_BEGIN \
+ _Pragma("clang diagnostic push") \
+ _Pragma("clang diagnostic error \"-Wstrict-prototypes\"")
+#define LLVM_CLANG_C_STRICT_PROTOTYPES_END _Pragma("clang diagnostic pop")
+#else
+#define LLVM_CLANG_C_STRICT_PROTOTYPES_BEGIN
+#define LLVM_CLANG_C_STRICT_PROTOTYPES_END
+#endif
+
+#ifdef __cplusplus
+#define LLVM_CLANG_C_EXTERN_C_BEGIN \
+ extern "C" { \
+ LLVM_CLANG_C_STRICT_PROTOTYPES_BEGIN
+#define LLVM_CLANG_C_EXTERN_C_END \
+ LLVM_CLANG_C_STRICT_PROTOTYPES_END \
+ }
+#else
+#define LLVM_CLANG_C_EXTERN_C_BEGIN LLVM_CLANG_C_STRICT_PROTOTYPES_BEGIN
+#define LLVM_CLANG_C_EXTERN_C_END LLVM_CLANG_C_STRICT_PROTOTYPES_END
+#endif
+
+#endif
diff --git a/clang/include/clang-c/FatalErrorHandler.h b/clang/include/clang-c/FatalErrorHandler.h
index ce8ff2cae735..22f34fa815cc 100644
--- a/clang/include/clang-c/FatalErrorHandler.h
+++ b/clang/include/clang-c/FatalErrorHandler.h
@@ -10,9 +10,9 @@
#ifndef LLVM_CLANG_C_FATAL_ERROR_HANDLER_H
#define LLVM_CLANG_C_FATAL_ERROR_HANDLER_H
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "clang-c/ExternC.h"
+
+LLVM_CLANG_C_EXTERN_C_BEGIN
/**
* Installs error handler that prints error message to stderr and calls abort().
@@ -27,7 +27,6 @@ void clang_install_aborting_llvm_fatal_error_handler(void);
*/
void clang_uninstall_llvm_fatal_error_handler(void);
-#ifdef __cplusplus
-}
-#endif
+LLVM_CLANG_C_EXTERN_C_END
+
#endif
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 438ee3698a1a..5ff887ea5bc6 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -18,10 +18,11 @@
#include <time.h>
-#include "clang-c/Platform.h"
+#include "clang-c/BuildSystem.h"
#include "clang-c/CXErrorCode.h"
#include "clang-c/CXString.h"
-#include "clang-c/BuildSystem.h"
+#include "clang-c/ExternC.h"
+#include "clang-c/Platform.h"
/**
* The version constants for the libclang API.
@@ -51,9 +52,7 @@
CINDEX_VERSION_MAJOR, \
CINDEX_VERSION_MINOR)
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_CLANG_C_EXTERN_C_BEGIN
/** \defgroup CINDEX libclang: C Interface to Clang
*
@@ -6774,7 +6773,6 @@ CINDEX_LINKAGE unsigned clang_Type_visitFields(CXType T,
* @}
*/
-#ifdef __cplusplus
-}
-#endif
+LLVM_CLANG_C_EXTERN_C_END
+
#endif
diff --git a/clang/include/clang-c/Platform.h b/clang/include/clang-c/Platform.h
index 5284b533253d..3bb66bb0df48 100644
--- a/clang/include/clang-c/Platform.h
+++ b/clang/include/clang-c/Platform.h
@@ -14,9 +14,9 @@
#ifndef LLVM_CLANG_C_PLATFORM_H
#define LLVM_CLANG_C_PLATFORM_H
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "clang-c/ExternC.h"
+
+LLVM_CLANG_C_EXTERN_C_BEGIN
/* MSVC DLL import/export. */
#ifdef _MSC_VER
@@ -39,7 +39,6 @@ extern "C" {
#endif
#endif
-#ifdef __cplusplus
-}
-#endif
+LLVM_CLANG_C_EXTERN_C_END
+
#endif
diff --git a/llvm/include/llvm-c/Analysis.h b/llvm/include/llvm-c/Analysis.h
index cb9e8ece3c53..270b145a4d27 100644
--- a/llvm/include/llvm-c/Analysis.h
+++ b/llvm/include/llvm-c/Analysis.h
@@ -19,11 +19,10 @@
#ifndef LLVM_C_ANALYSIS_H
#define LLVM_C_ANALYSIS_H
+#include "llvm-c/ExternC.h"
#include "llvm-c/Types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/**
* @defgroup LLVMCAnalysis Analysis
@@ -58,8 +57,6 @@ void LLVMViewFunctionCFGOnly(LLVMValueRef Fn);
* @}
*/
-#ifdef __cplusplus
-}
-#endif
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/BitReader.h b/llvm/include/llvm-c/BitReader.h
index b307ee979f8a..012c0e63d3bb 100644
--- a/llvm/include/llvm-c/BitReader.h
+++ b/llvm/include/llvm-c/BitReader.h
@@ -19,11 +19,10 @@
#ifndef LLVM_C_BITREADER_H
#define LLVM_C_BITREADER_H
+#include "llvm-c/ExternC.h"
#include "llvm-c/Types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/**
* @defgroup LLVMCBitReader Bit Reader
@@ -78,8 +77,6 @@ LLVMBool LLVMGetBitcodeModule2(LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM);
* @}
*/
-#ifdef __cplusplus
-}
-#endif
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/BitWriter.h b/llvm/include/llvm-c/BitWriter.h
index 187051555b9a..ea84b6593d12 100644
--- a/llvm/include/llvm-c/BitWriter.h
+++ b/llvm/include/llvm-c/BitWriter.h
@@ -19,11 +19,10 @@
#ifndef LLVM_C_BITWRITER_H
#define LLVM_C_BITWRITER_H
+#include "llvm-c/ExternC.h"
#include "llvm-c/Types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/**
* @defgroup LLVMCBitWriter Bit Writer
@@ -52,8 +51,6 @@ LLVMMemoryBufferRef LLVMWriteBitcodeToMemoryBuffer(LLVMModuleRef M);
* @}
*/
-#ifdef __cplusplus
-}
-#endif
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/Comdat.h b/llvm/include/llvm-c/Comdat.h
index 81fee3fc9a6b..45b4007695fd 100644
--- a/llvm/include/llvm-c/Comdat.h
+++ b/llvm/include/llvm-c/Comdat.h
@@ -14,11 +14,10 @@
#ifndef LLVM_C_COMDAT_H
#define LLVM_C_COMDAT_H
+#include "llvm-c/ExternC.h"
#include "llvm-c/Types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
typedef enum {
LLVMAnyComdatSelectionKind, ///< The linker may choose any COMDAT.
@@ -68,8 +67,6 @@ LLVMComdatSelectionKind LLVMGetComdatSelectionKind(LLVMComdatRef C);
*/
void LLVMSetComdatSelectionKind(LLVMComdatRef C, LLVMComdatSelectionKind Kind);
-#ifdef __cplusplus
-}
-#endif
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index 83bf7077bcba..7a39731d3e0c 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -16,11 +16,10 @@
#define LLVM_C_CORE_H
#include "llvm-c/ErrorHandling.h"
+#include "llvm-c/ExternC.h"
#include "llvm-c/Types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/**
* @defgroup LLVMC LLVM-C: C interface to LLVM
@@ -4090,8 +4089,6 @@ LLVMBool LLVMIsMultithreaded(void);
* @}
*/
-#ifdef __cplusplus
-}
-#endif
+LLVM_C_EXTERN_C_END
#endif /* LLVM_C_CORE_H */
diff --git a/llvm/include/llvm-c/DebugInfo.h b/llvm/include/llvm-c/DebugInfo.h
index 41e9f96bbb92..ab60b88a31f4 100644
--- a/llvm/include/llvm-c/DebugInfo.h
+++ b/llvm/include/llvm-c/DebugInfo.h
@@ -17,10 +17,9 @@
#define LLVM_C_DEBUGINFO_H
#include "llvm-c/Core.h"
+#include "llvm-c/ExternC.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/**
* Debug info flags.
@@ -1353,8 +1352,6 @@ void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc);
*/
LLVMMetadataKind LLVMGetMetadataKind(LLVMMetadataRef Metadata);
-#ifdef __cplusplus
-} /* end extern "C" */
-#endif
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/Disassembler.h b/llvm/include/llvm-c/Disassembler.h
index 3adcc3c47a3f..b1cb35da6687 100644
--- a/llvm/include/llvm-c/Disassembler.h
+++ b/llvm/include/llvm-c/Disassembler.h
@@ -16,6 +16,7 @@
#define LLVM_C_DISASSEMBLER_H
#include "llvm-c/DisassemblerTypes.h"
+#include "llvm-c/ExternC.h"
/**
* @defgroup LLVMCDisassembler Disassembler
@@ -24,9 +25,7 @@
* @{
*/
-#ifdef __cplusplus
-extern "C" {
-#endif /* !defined(__cplusplus) */
+LLVM_C_EXTERN_C_BEGIN
/**
* Create a disassembler for the TripleName. Symbolic disassembly is supported
@@ -106,8 +105,6 @@ size_t LLVMDisasmInstruction(LLVMDisasmContextRef DC, uint8_t *Bytes,
* @}
*/
-#ifdef __cplusplus
-}
-#endif /* !defined(__cplusplus) */
+LLVM_C_EXTERN_C_END
#endif /* LLVM_C_DISASSEMBLER_H */
diff --git a/llvm/include/llvm-c/Error.h b/llvm/include/llvm-c/Error.h
index 52943063c697..92f81bf38304 100644
--- a/llvm/include/llvm-c/Error.h
+++ b/llvm/include/llvm-c/Error.h
@@ -14,9 +14,9 @@
#ifndef LLVM_C_ERROR_H
#define LLVM_C_ERROR_H
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "llvm-c/ExternC.h"
+
+LLVM_C_EXTERN_C_BEGIN
#define LLVMErrorSuccess 0
@@ -62,8 +62,6 @@ void LLVMDisposeErrorMessage(char *ErrMsg);
*/
LLVMErrorTypeId LLVMGetStringErrorTypeId(void);
-#ifdef __cplusplus
-}
-#endif
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/ErrorHandling.h b/llvm/include/llvm-c/ErrorHandling.h
index 4927349d8983..c6f7ff3ed693 100644
--- a/llvm/include/llvm-c/ErrorHandling.h
+++ b/llvm/include/llvm-c/ErrorHandling.h
@@ -14,9 +14,9 @@
#ifndef LLVM_C_ERROR_HANDLING_H
#define LLVM_C_ERROR_HANDLING_H
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "llvm-c/ExternC.h"
+
+LLVM_C_EXTERN_C_BEGIN
typedef void (*LLVMFatalErrorHandler)(const char *Reason);
@@ -42,8 +42,6 @@ void LLVMResetFatalErrorHandler(void);
*/
void LLVMEnablePrettyStackTrace(void);
-#ifdef __cplusplus
-}
-#endif
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/ExecutionEngine.h b/llvm/include/llvm-c/ExecutionEngine.h
index ef714cd06384..f31b97ad7623 100644
--- a/llvm/include/llvm-c/ExecutionEngine.h
+++ b/llvm/include/llvm-c/ExecutionEngine.h
@@ -19,13 +19,12 @@
#ifndef LLVM_C_EXECUTIONENGINE_H
#define LLVM_C_EXECUTIONENGINE_H
+#include "llvm-c/ExternC.h"
#include "llvm-c/Target.h"
#include "llvm-c/TargetMachine.h"
#include "llvm-c/Types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/**
* @defgroup LLVMCExecutionEngine Execution Engine
@@ -193,8 +192,6 @@ LLVMJITEventListenerRef LLVMCreatePerfJITEventListener(void);
* @}
*/
-#ifdef __cplusplus
-}
-#endif /* defined(__cplusplus) */
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/ExternC.h b/llvm/include/llvm-c/ExternC.h
new file mode 100644
index 000000000000..4240f7c31a3b
--- /dev/null
+++ b/llvm/include/llvm-c/ExternC.h
@@ -0,0 +1,39 @@
+/*===- llvm-c/ExternC.h - Wrapper for 'extern "C"' ----------------*- C -*-===*\
+|* *|
+|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
+|* Exceptions. *|
+|* See https://llvm.org/LICENSE.txt for license information. *|
+|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
+|* *|
+|*===----------------------------------------------------------------------===*|
+|* *|
+|* This file defines an 'extern "C"' wrapper *|
+|* *|
+\*===----------------------------------------------------------------------===*/
+
+#ifndef LLVM_C_EXTERN_C_H
+#define LLVM_C_EXTERN_C_H
+
+#ifdef __clang__
+#define LLVM_C_STRICT_PROTOTYPES_BEGIN \
+ _Pragma("clang diagnostic push") \
+ _Pragma("clang diagnostic error \"-Wstrict-prototypes\"")
+#define LLVM_C_STRICT_PROTOTYPES_END _Pragma("clang diagnostic pop")
+#else
+#define LLVM_C_STRICT_PROTOTYPES_BEGIN
+#define LLVM_C_STRICT_PROTOTYPES_END
+#endif
+
+#ifdef __cplusplus
+#define LLVM_C_EXTERN_C_BEGIN \
+ extern "C" { \
+ LLVM_C_STRICT_PROTOTYPES_BEGIN
+#define LLVM_C_EXTERN_C_END \
+ LLVM_C_STRICT_PROTOTYPES_END \
+ }
+#else
+#define LLVM_C_EXTERN_C_BEGIN LLVM_C_STRICT_PROTOTYPES_BEGIN
+#define LLVM_C_EXTERN_C_END LLVM_C_STRICT_PROTOTYPES_END
+#endif
+
+#endif
diff --git a/llvm/include/llvm-c/IRReader.h b/llvm/include/llvm-c/IRReader.h
index 4d0b696e9583..5a3f633c3d91 100644
--- a/llvm/include/llvm-c/IRReader.h
+++ b/llvm/include/llvm-c/IRReader.h
@@ -14,11 +14,10 @@
#ifndef LLVM_C_IRREADER_H
#define LLVM_C_IRREADER_H
+#include "llvm-c/ExternC.h"
#include "llvm-c/Types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/**
* Read LLVM IR from a memory buffer and convert it into an in-memory Module
@@ -33,8 +32,6 @@ LLVMBool LLVMParseIRInContext(LLVMContextRef ContextRef,
LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM,
char **OutMessage);
-#ifdef __cplusplus
-}
-#endif
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/Initialization.h b/llvm/include/llvm-c/Initialization.h
index 36c41dbd8d31..0d59de8728c8 100644
--- a/llvm/include/llvm-c/Initialization.h
+++ b/llvm/include/llvm-c/Initialization.h
@@ -16,11 +16,10 @@
#ifndef LLVM_C_INITIALIZATION_H
#define LLVM_C_INITIALIZATION_H
+#include "llvm-c/ExternC.h"
#include "llvm-c/Types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/**
* @defgroup LLVMCInitialization Initialization Routines
@@ -49,8 +48,6 @@ void LLVMInitializeTarget(LLVMPassRegistryRef R);
* @}
*/
-#ifdef __cplusplus
-}
-#endif
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/LinkTimeOptimizer.h b/llvm/include/llvm-c/LinkTimeOptimizer.h
index 19b4f5cf7491..9ae65b8fe5e0 100644
--- a/llvm/include/llvm-c/LinkTimeOptimizer.h
+++ b/llvm/include/llvm-c/LinkTimeOptimizer.h
@@ -15,9 +15,9 @@
#ifndef LLVM_C_LINKTIMEOPTIMIZER_H
#define LLVM_C_LINKTIMEOPTIMIZER_H
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "llvm-c/ExternC.h"
+
+LLVM_C_EXTERN_C_BEGIN
/**
* @defgroup LLVMCLinkTimeOptimizer Link Time Optimization
@@ -61,8 +61,6 @@ extern "C" {
* @}
*/
-#ifdef __cplusplus
-}
-#endif
+ LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/Linker.h b/llvm/include/llvm-c/Linker.h
index 908513041661..1ad9cc958753 100644
--- a/llvm/include/llvm-c/Linker.h
+++ b/llvm/include/llvm-c/Linker.h
@@ -14,11 +14,10 @@
#ifndef LLVM_C_LINKER_H
#define LLVM_C_LINKER_H
+#include "llvm-c/ExternC.h"
#include "llvm-c/Types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/* This enum is provided for backwards-compatibility only. It has no effect. */
typedef enum {
@@ -34,8 +33,6 @@ typedef enum {
*/
LLVMBool LLVMLinkModules2(LLVMModuleRef Dest, LLVMModuleRef Src);
-#ifdef __cplusplus
-}
-#endif
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/Object.h b/llvm/include/llvm-c/Object.h
index 1e9b703a68ff..9a9596aaa08c 100644
--- a/llvm/include/llvm-c/Object.h
+++ b/llvm/include/llvm-c/Object.h
@@ -19,12 +19,11 @@
#ifndef LLVM_C_OBJECT_H
#define LLVM_C_OBJECT_H
+#include "llvm-c/ExternC.h"
#include "llvm-c/Types.h"
#include "llvm/Config/llvm-config.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/**
* @defgroup LLVMCObject Object file reading and writing
@@ -226,8 +225,6 @@ LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile,
* @}
*/
-#ifdef __cplusplus
-}
-#endif /* defined(__cplusplus) */
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/OrcBindings.h b/llvm/include/llvm-c/OrcBindings.h
index 9e92371b5a3a..11cdade7c26f 100644
--- a/llvm/include/llvm-c/OrcBindings.h
+++ b/llvm/include/llvm-c/OrcBindings.h
@@ -23,12 +23,11 @@
#define LLVM_C_ORCBINDINGS_H
#include "llvm-c/Error.h"
+#include "llvm-c/ExternC.h"
#include "llvm-c/Object.h"
#include "llvm-c/TargetMachine.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
typedef struct LLVMOrcOpaqueJITStack *LLVMOrcJITStackRef;
typedef uint64_t LLVMOrcModuleHandle;
@@ -165,8 +164,6 @@ void LLVMOrcRegisterJITEventListener(LLVMOrcJITStackRef JITStack, LLVMJITEventLi
*/
void LLVMOrcUnregisterJITEventListener(LLVMOrcJITStackRef JITStack, LLVMJITEventListenerRef L);
-#ifdef __cplusplus
-}
-#endif /* extern "C" */
+LLVM_C_EXTERN_C_END
#endif /* LLVM_C_ORCBINDINGS_H */
diff --git a/llvm/include/llvm-c/Remarks.h b/llvm/include/llvm-c/Remarks.h
index 5444aebddd60..ffe647a6554a 100644
--- a/llvm/include/llvm-c/Remarks.h
+++ b/llvm/include/llvm-c/Remarks.h
@@ -15,14 +15,16 @@
#ifndef LLVM_C_REMARKS_H
#define LLVM_C_REMARKS_H
+#include "llvm-c/ExternC.h"
#include "llvm-c/Types.h"
#ifdef __cplusplus
#include <cstddef>
-extern "C" {
#else
#include <stddef.h>
#endif /* !defined(__cplusplus) */
+LLVM_C_EXTERN_C_BEGIN
+
/**
* @defgroup LLVMCREMARKS Remarks
* @ingroup LLVMC
@@ -337,8 +339,6 @@ extern uint32_t LLVMRemarkVersion(void);
* @} // endgoup LLVMCREMARKS
*/
-#ifdef __cplusplus
-}
-#endif /* !defined(__cplusplus) */
+LLVM_C_EXTERN_C_END
#endif /* LLVM_C_REMARKS_H */
diff --git a/llvm/include/llvm-c/Support.h b/llvm/include/llvm-c/Support.h
index 097f784246c5..866df32efa98 100644
--- a/llvm/include/llvm-c/Support.h
+++ b/llvm/include/llvm-c/Support.h
@@ -15,11 +15,10 @@
#define LLVM_C_SUPPORT_H
#include "llvm-c/DataTypes.h"
+#include "llvm-c/ExternC.h"
#include "llvm-c/Types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/**
* This function permanently loads the dynamic library at the given path.
@@ -58,8 +57,6 @@ void *LLVMSearchForAddressOfSymbol(const char *symbolName);
*/
void LLVMAddSymbol(const char *symbolName, void *symbolValue);
-#ifdef __cplusplus
-}
-#endif
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/Target.h b/llvm/include/llvm-c/Target.h
index 4ef641eaf232..518b46d55bc3 100644
--- a/llvm/include/llvm-c/Target.h
+++ b/llvm/include/llvm-c/Target.h
@@ -19,12 +19,11 @@
#ifndef LLVM_C_TARGET_H
#define LLVM_C_TARGET_H
+#include "llvm-c/ExternC.h"
#include "llvm-c/Types.h"
#include "llvm/Config/llvm-config.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/**
* @defgroup LLVMCTarget Target information
@@ -288,8 +287,6 @@ unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD,
* @}
*/
-#ifdef __cplusplus
-}
-#endif /* defined(__cplusplus) */
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/TargetMachine.h b/llvm/include/llvm-c/TargetMachine.h
index 28d7c096871e..f82edd948b59 100644
--- a/llvm/include/llvm-c/TargetMachine.h
+++ b/llvm/include/llvm-c/TargetMachine.h
@@ -19,12 +19,12 @@
#ifndef LLVM_C_TARGETMACHINE_H
#define LLVM_C_TARGETMACHINE_H
+#include "llvm-c/ExternC.h"
#include "llvm-c/Target.h"
#include "llvm-c/Types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
+
typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef;
typedef struct LLVMTarget *LLVMTargetRef;
@@ -156,8 +156,6 @@ char* LLVMGetHostCPUFeatures(void);
/** Adds the target-specific analysis passes to the pass manager. */
void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM);
-#ifdef __cplusplus
-}
-#endif
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/Transforms/AggressiveInstCombine.h b/llvm/include/llvm-c/Transforms/AggressiveInstCombine.h
index c0b0141c3da1..db061a7ad1fc 100644
--- a/llvm/include/llvm-c/Transforms/AggressiveInstCombine.h
+++ b/llvm/include/llvm-c/Transforms/AggressiveInstCombine.h
@@ -15,11 +15,10 @@
#ifndef LLVM_C_TRANSFORMS_AGGRESSIVEINSTCOMBINE_H
#define LLVM_C_TRANSFORMS_AGGRESSIVEINSTCOMBINE_H
+#include "llvm-c/ExternC.h"
#include "llvm-c/Types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/**
* @defgroup LLVMCTransformsAggressiveInstCombine Aggressive Instruction Combining transformations
@@ -35,9 +34,7 @@ void LLVMAddAggressiveInstCombinerPass(LLVMPassManagerRef PM);
* @}
*/
-#ifdef __cplusplus
-}
-#endif /* defined(__cplusplus) */
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/Transforms/Coroutines.h b/llvm/include/llvm-c/Transforms/Coroutines.h
index 227e7cf0a360..687f9b550538 100644
--- a/llvm/include/llvm-c/Transforms/Coroutines.h
+++ b/llvm/include/llvm-c/Transforms/Coroutines.h
@@ -19,11 +19,10 @@
#ifndef LLVM_C_TRANSFORMS_COROUTINES_H
#define LLVM_C_TRANSFORMS_COROUTINES_H
+#include "llvm-c/ExternC.h"
#include "llvm-c/Types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/**
* @defgroup LLVMCTransformsCoroutines Coroutine transformations
@@ -48,8 +47,6 @@ void LLVMAddCoroCleanupPass(LLVMPassManagerRef PM);
* @}
*/
-#ifdef __cplusplus
-}
-#endif /* defined(__cplusplus) */
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/Transforms/IPO.h b/llvm/include/llvm-c/Transforms/IPO.h
index 51d007581283..cde3d2460920 100644
--- a/llvm/include/llvm-c/Transforms/IPO.h
+++ b/llvm/include/llvm-c/Transforms/IPO.h
@@ -15,11 +15,10 @@
#ifndef LLVM_C_TRANSFORMS_IPO_H
#define LLVM_C_TRANSFORMS_IPO_H
+#include "llvm-c/ExternC.h"
#include "llvm-c/Types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/**
* @defgroup LLVMCTransformsIPO Interprocedural transformations
@@ -95,8 +94,6 @@ void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM);
* @}
*/
-#ifdef __cplusplus
-}
-#endif /* defined(__cplusplus) */
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/Transforms/InstCombine.h b/llvm/include/llvm-c/Transforms/InstCombine.h
index 166f278d9a69..ebe17d667061 100644
--- a/llvm/include/llvm-c/Transforms/InstCombine.h
+++ b/llvm/include/llvm-c/Transforms/InstCombine.h
@@ -15,11 +15,10 @@
#ifndef LLVM_C_TRANSFORMS_INSTCOMBINE_H
#define LLVM_C_TRANSFORMS_INSTCOMBINE_H
+#include "llvm-c/ExternC.h"
#include "llvm-c/Types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/**
* @defgroup LLVMCTransformsInstCombine Instruction Combining transformations
@@ -35,9 +34,7 @@ void LLVMAddInstructionCombiningPass(LLVMPassManagerRef PM);
* @}
*/
-#ifdef __cplusplus
-}
-#endif /* defined(__cplusplus) */
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/Transforms/PassManagerBuilder.h b/llvm/include/llvm-c/Transforms/PassManagerBuilder.h
index d164c00d49c5..6e13e18e063b 100644
--- a/llvm/include/llvm-c/Transforms/PassManagerBuilder.h
+++ b/llvm/include/llvm-c/Transforms/PassManagerBuilder.h
@@ -14,13 +14,12 @@
#ifndef LLVM_C_TRANSFORMS_PASSMANAGERBUILDER_H
#define LLVM_C_TRANSFORMS_PASSMANAGERBUILDER_H
+#include "llvm-c/ExternC.h"
#include "llvm-c/Types.h"
typedef struct LLVMOpaquePassManagerBuilder *LLVMPassManagerBuilderRef;
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/**
* @defgroup LLVMCTransformsPassManagerBuilder Pass manager builder
@@ -83,8 +82,6 @@ void LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB,
* @}
*/
-#ifdef __cplusplus
-}
-#endif
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/Transforms/Scalar.h b/llvm/include/llvm-c/Transforms/Scalar.h
index 6f3a3d8b3750..93d79a205195 100644
--- a/llvm/include/llvm-c/Transforms/Scalar.h
+++ b/llvm/include/llvm-c/Transforms/Scalar.h
@@ -19,11 +19,10 @@
#ifndef LLVM_C_TRANSFORMS_SCALAR_H
#define LLVM_C_TRANSFORMS_SCALAR_H
+#include "llvm-c/ExternC.h"
#include "llvm-c/Types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/**
* @defgroup LLVMCTransformsScalar Scalar transformations
@@ -166,8 +165,6 @@ void LLVMAddUnifyFunctionExitNodesPass(LLVMPassManagerRef PM);
* @}
*/
-#ifdef __cplusplus
-}
-#endif /* defined(__cplusplus) */
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/Transforms/Utils.h b/llvm/include/llvm-c/Transforms/Utils.h
index 63594abfa460..30d1ae63de1d 100644
--- a/llvm/include/llvm-c/Transforms/Utils.h
+++ b/llvm/include/llvm-c/Transforms/Utils.h
@@ -19,11 +19,10 @@
#ifndef LLVM_C_TRANSFORMS_UTILS_H
#define LLVM_C_TRANSFORMS_UTILS_H
+#include "llvm-c/ExternC.h"
#include "llvm-c/Types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/**
* @defgroup LLVMCTransformsUtils Transformation Utilities
@@ -45,9 +44,7 @@ void LLVMAddAddDiscriminatorsPass(LLVMPassManagerRef PM);
* @}
*/
-#ifdef __cplusplus
-}
-#endif /* defined(__cplusplus) */
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/Transforms/Vectorize.h b/llvm/include/llvm-c/Transforms/Vectorize.h
index e383481fe4f4..0de458381399 100644
--- a/llvm/include/llvm-c/Transforms/Vectorize.h
+++ b/llvm/include/llvm-c/Transforms/Vectorize.h
@@ -20,11 +20,10 @@
#ifndef LLVM_C_TRANSFORMS_VECTORIZE_H
#define LLVM_C_TRANSFORMS_VECTORIZE_H
+#include "llvm-c/ExternC.h"
#include "llvm-c/Types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/**
* @defgroup LLVMCTransformsVectorize Vectorization transformations
@@ -43,8 +42,6 @@ void LLVMAddSLPVectorizePass(LLVMPassManagerRef PM);
* @}
*/
-#ifdef __cplusplus
-}
-#endif /* defined(__cplusplus) */
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/Types.h b/llvm/include/llvm-c/Types.h
index 612c7d3eff32..4e02498a2348 100644
--- a/llvm/include/llvm-c/Types.h
+++ b/llvm/include/llvm-c/Types.h
@@ -15,10 +15,9 @@
#define LLVM_C_TYPES_H
#include "llvm-c/DataTypes.h"
+#include "llvm-c/ExternC.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/**
* @defgroup LLVMCSupportTypes Types and Enumerations
@@ -172,8 +171,6 @@ typedef struct LLVMOpaqueBinary *LLVMBinaryRef;
* @}
*/
-#ifdef __cplusplus
-}
-#endif
+LLVM_C_EXTERN_C_END
#endif
diff --git a/llvm/include/llvm-c/lto.h b/llvm/include/llvm-c/lto.h
index 41e6067cf44f..0c6ce673162a 100644
--- a/llvm/include/llvm-c/lto.h
+++ b/llvm/include/llvm-c/lto.h
@@ -16,6 +16,8 @@
#ifndef LLVM_C_LTO_H
#define LLVM_C_LTO_H
+#include "llvm-c/ExternC.h"
+
#ifdef __cplusplus
#include <cstddef>
#else
@@ -98,9 +100,7 @@ typedef struct LLVMOpaqueLTOCodeGenerator *lto_code_gen_t;
/** opaque reference to a thin code generator */
typedef struct LLVMOpaqueThinLTOCodeGenerator *thinlto_code_gen_t;
-#ifdef __cplusplus
-extern "C" {
-#endif
+LLVM_C_EXTERN_C_BEGIN
/**
* Returns a printable string.
@@ -900,8 +900,6 @@ extern void thinlto_codegen_set_cache_size_files(thinlto_code_gen_t cg,
* @} // endgroup LLVMCTLTO_CACHING
*/
-#ifdef __cplusplus
-}
-#endif
+LLVM_C_EXTERN_C_END
#endif /* LLVM_C_LTO_H */
More information about the cfe-commits
mailing list