On Darwin, the linker removes functions in CommentDumper.o (Comment::dump())
despite __attribute__(__used__). As explained by Argyrios,
> .a archive files do some stripping of their own and they remove .o files that
> contain functions that are not referenced by any other .o file.
The fix is to use these functions from another .o file.
Thanks, Argyrios!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160437 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Comment.cpp b/lib/AST/Comment.cpp
index 1520d13..e215e63 100644
--- a/lib/AST/Comment.cpp
+++ b/lib/AST/Comment.cpp
@@ -9,6 +9,7 @@
#include "clang/AST/Comment.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/raw_ostream.h"
namespace clang {
namespace comments {
@@ -27,6 +28,19 @@
llvm_unreachable("Unknown comment kind!");
}
+void Comment::dump() const {
+ // It is important that Comment::dump() is defined in a different TU than
+ // Comment::dump(raw_ostream, SourceManager). If both functions were defined
+ // in CommentDumper.cpp, that object file would be removed by linker because
+ // none of its functions are referenced by other object files, despite the
+ // LLVM_ATTRIBUTE_USED.
+ dump(llvm::errs(), NULL);
+}
+
+void Comment::dump(SourceManager &SM) const {
+ dump(llvm::errs(), &SM);
+}
+
namespace {
struct good {};
struct bad {};