[llvm-commits] [PATCHES] don't include config.h in public headers

nobled nobled at dreamwidth.org
Wed Jun 22 05:18:46 PDT 2011


llvm/Config/config.h contains a lot of standard macros like
PACKAGE_VERSION that don't make sense to expose to clients, who will
probably have their own private config.h with its own definition of
PACKAGE_VERSION et al. Right now, Klee runs into this and seems to be
working around it with #undef[1].

It's not actually needed in most cases, and these four patches remove
all the uses in llvm and clang headers. Unless it's also being
included in dragonegg or lldb sources or something, the file can
probably be excluded from `make install` entirely after this (but I'm
not sure how to do that). Okay to commit?

[1] http://llvm.org/viewvc/llvm-project/klee/trunk/lib/Core/ExternalDispatcher.cpp?r1=98467&r2=98466&pathrev=98467
-------------- next part --------------
From 96493bc1061dd38b05e63fcf99808de7ed7ae429 Mon Sep 17 00:00:00 2001
From: nobled <nobled at dreamwidth.org>
Date: Tue, 21 Jun 2011 07:25:37 +0000
Subject: [PATCH 1/3] Only use llvm-config.h in public headers

llvm-config.h defines most of the important macros "so that
they can be in exported headers and won't override package
specific directives." e.g., PACKAGE_NAME.

Endian.h wasn't using any macros at all though, so just delete
the include there instead.
---
 include/llvm/Support/Endian.h       |    1 -
 include/llvm/Support/system_error.h |    2 +-
 2 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/include/llvm/Support/Endian.h b/include/llvm/Support/Endian.h
index f62eab0..af1b506 100644
--- a/include/llvm/Support/Endian.h
+++ b/include/llvm/Support/Endian.h
@@ -14,7 +14,6 @@
 #ifndef LLVM_SUPPORT_ENDIAN_H
 #define LLVM_SUPPORT_ENDIAN_H
 
-#include "llvm/Config/config.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Support/SwapByteOrder.h"
 #include "llvm/Support/type_traits.h"
diff --git a/include/llvm/Support/system_error.h b/include/llvm/Support/system_error.h
index b77030d..2c15b69 100644
--- a/include/llvm/Support/system_error.h
+++ b/include/llvm/Support/system_error.h
@@ -222,7 +222,7 @@ template <> struct hash<std::error_code>;
 
 */
 
-#include "llvm/Config/config.h"
+#include "llvm/Config/llvm-config.h"
 #include "llvm/Support/type_traits.h"
 #include <cerrno>
 #include <string>
-- 
1.7.0.4

-------------- next part --------------
From bbd1d7666736afe19b3b0c967666fab810e79aa7 Mon Sep 17 00:00:00 2001
From: nobled <nobled at dreamwidth.org>
Date: Tue, 21 Jun 2011 13:15:51 +0000
Subject: [PATCH] avoid using config.h in public headers

This is the only usage in clang's headers, and it's for a define
that only exists on CMake builds for the sake of the MSVC compiler,
so just use an ifdef instead.

Also add an include for config.h in a file that actually needs it,
but was picking it up by accident indirectly.
---
 include/clang/Basic/FileManager.h |    5 ++++-
 lib/Frontend/CompilerInstance.cpp |    1 +
 2 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/include/clang/Basic/FileManager.h b/include/clang/Basic/FileManager.h
index 2ca344d..1324533 100644
--- a/include/clang/Basic/FileManager.h
+++ b/include/clang/Basic/FileManager.h
@@ -21,10 +21,13 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/OwningPtr.h"
 #include "llvm/Support/Allocator.h"
-#include "llvm/Config/config.h" // for mode_t
 // FIXME: Enhance libsystem to support inode and other fields in stat.
 #include <sys/types.h>
 
+#ifdef _MSC_VER
+typedef unsigned short mode_t;
+#endif
+
 struct stat;
 
 namespace llvm {
diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp
index 38fcfe3..cb91c89 100644
--- a/lib/Frontend/CompilerInstance.cpp
+++ b/lib/Frontend/CompilerInstance.cpp
@@ -38,6 +38,7 @@
 #include "llvm/Support/Program.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/system_error.h"
+#include "llvm/Config/config.h"
 using namespace clang;
 
 CompilerInstance::CompilerInstance()
-- 
1.7.0.4

-------------- next part --------------
From fbc6303d169f7b50b4340c9380af66e00210ac0c Mon Sep 17 00:00:00 2001
From: nobled <nobled at dreamwidth.org>
Date: Tue, 21 Jun 2011 13:21:11 +0000
Subject: [PATCH 2/3] remove CMake mode_t define

It's now replaced with a simple ifdef _MSC_VER in the one
place it's needed (clang's FileManager.h header).
---
 cmake/config-ix.cmake              |    1 -
 include/llvm/Config/config.h.cmake |    3 ---
 2 files changed, 0 insertions(+), 4 deletions(-)

diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
index c1b22d4..1a2cba5 100755
--- a/cmake/config-ix.cmake
+++ b/cmake/config-ix.cmake
@@ -349,7 +349,6 @@ endif( MINGW )
 
 if( MSVC )
   set(error_t int)
-  set(mode_t "unsigned short")
   set(LTDL_SHLIBPATH_VAR "PATH")
   set(LTDL_SYSSEARCHPATH "")
   set(LTDL_DLOPEN_DEPLIBS 1)
diff --git a/include/llvm/Config/config.h.cmake b/include/llvm/Config/config.h.cmake
index 755daa6..d07e0b2 100644
--- a/include/llvm/Config/config.h.cmake
+++ b/include/llvm/Config/config.h.cmake
@@ -686,9 +686,6 @@
    `char[]'. */
 #undef YYTEXT_POINTER
 
-/* Define to a type to use for `mode_t' if it is not otherwise available. */
-#cmakedefine mode_t ${mode_t}
-
 /* Define to a function replacing strtoll */
 #cmakedefine strtoll ${strtoll}
 
-- 
1.7.0.4

-------------- next part --------------
From e28c74fd0a90b02cf541450004e3d16fb3949bbd Mon Sep 17 00:00:00 2001
From: nobled <nobled at dreamwidth.org>
Date: Tue, 21 Jun 2011 07:30:57 +0000
Subject: [PATCH 3/3] make floating-exception header private

It has only one user. This eliminates the last include of
config.h from the public headers -- it should probably not
even be installed at `make install` time now.
---
 include/llvm/Support/FEnv.h      |   56 --------------------------------------
 lib/Analysis/ConstantFolding.cpp |    3 +-
 lib/Analysis/FEnv.h              |   56 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+), 57 deletions(-)
 delete mode 100644 include/llvm/Support/FEnv.h
 create mode 100644 lib/Analysis/FEnv.h

diff --git a/include/llvm/Support/FEnv.h b/include/llvm/Support/FEnv.h
deleted file mode 100644
index f6f4333..0000000
--- a/include/llvm/Support/FEnv.h
+++ /dev/null
@@ -1,56 +0,0 @@
-//===- llvm/Support/FEnv.h - Host floating-point exceptions ------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file provides an operating system independent interface to
-// floating-point exception interfaces.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_SYSTEM_FENV_H
-#define LLVM_SYSTEM_FENV_H
-
-#include "llvm/Config/config.h"
-#include <cerrno>
-#ifdef HAVE_FENV_H
-#include <fenv.h>
-#endif
-
-// FIXME: Clang's #include handling apparently doesn't work for libstdc++'s
-// fenv.h; see PR6907 for details.
-#if defined(__clang__) && defined(_GLIBCXX_FENV_H)
-#undef HAVE_FENV_H
-#endif
-
-namespace llvm {
-namespace sys {
-
-/// llvm_fenv_clearexcept - Clear the floating-point exception state.
-static inline void llvm_fenv_clearexcept() {
-#ifdef HAVE_FENV_H
-  feclearexcept(FE_ALL_EXCEPT);
-#endif
-  errno = 0;
-}
-
-/// llvm_fenv_testexcept - Test if a floating-point exception was raised.
-static inline bool llvm_fenv_testexcept() {
-  int errno_val = errno;
-  if (errno_val == ERANGE || errno_val == EDOM)
-    return true;
-#ifdef HAVE_FENV_H
-  if (fetestexcept(FE_ALL_EXCEPT & ~FE_INEXACT))
-    return true;
-#endif
-  return false;
-}
-
-} // End sys namespace
-} // End llvm namespace
-
-#endif
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp
index b5fafd6..b64f3b9 100644
--- a/lib/Analysis/ConstantFolding.cpp
+++ b/lib/Analysis/ConstantFolding.cpp
@@ -31,9 +31,10 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/GetElementPtrTypeIterator.h"
 #include "llvm/Support/MathExtras.h"
-#include "llvm/Support/FEnv.h"
 #include <cerrno>
 #include <cmath>
+
+#include "FEnv.h"
 using namespace llvm;
 
 //===----------------------------------------------------------------------===//
diff --git a/lib/Analysis/FEnv.h b/lib/Analysis/FEnv.h
new file mode 100644
index 0000000..f6f4333
--- /dev/null
+++ b/lib/Analysis/FEnv.h
@@ -0,0 +1,56 @@
+//===- llvm/Support/FEnv.h - Host floating-point exceptions ------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file provides an operating system independent interface to
+// floating-point exception interfaces.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SYSTEM_FENV_H
+#define LLVM_SYSTEM_FENV_H
+
+#include "llvm/Config/config.h"
+#include <cerrno>
+#ifdef HAVE_FENV_H
+#include <fenv.h>
+#endif
+
+// FIXME: Clang's #include handling apparently doesn't work for libstdc++'s
+// fenv.h; see PR6907 for details.
+#if defined(__clang__) && defined(_GLIBCXX_FENV_H)
+#undef HAVE_FENV_H
+#endif
+
+namespace llvm {
+namespace sys {
+
+/// llvm_fenv_clearexcept - Clear the floating-point exception state.
+static inline void llvm_fenv_clearexcept() {
+#ifdef HAVE_FENV_H
+  feclearexcept(FE_ALL_EXCEPT);
+#endif
+  errno = 0;
+}
+
+/// llvm_fenv_testexcept - Test if a floating-point exception was raised.
+static inline bool llvm_fenv_testexcept() {
+  int errno_val = errno;
+  if (errno_val == ERANGE || errno_val == EDOM)
+    return true;
+#ifdef HAVE_FENV_H
+  if (fetestexcept(FE_ALL_EXCEPT & ~FE_INEXACT))
+    return true;
+#endif
+  return false;
+}
+
+} // End sys namespace
+} // End llvm namespace
+
+#endif
-- 
1.7.0.4



More information about the llvm-commits mailing list