]> granicus.if.org Git - clang/commitdiff
On Darwin, the linker removes functions in CommentDumper.o (Comment::dump())
authorDmitri Gribenko <gribozavr@gmail.com>
Wed, 18 Jul 2012 16:30:42 +0000 (16:30 +0000)
committerDmitri Gribenko <gribozavr@gmail.com>
Wed, 18 Jul 2012 16:30:42 +0000 (16:30 +0000)
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

include/clang/AST/Comment.h
lib/AST/Comment.cpp
lib/AST/CommentDumper.cpp

index 05ad33fe3a507f8cfb0bbaa99e5935b060259dec..39753cfbd9a2f3d4f4c0ff3942bb651390a8a5e2 100644 (file)
@@ -115,6 +115,7 @@ public:
 
   LLVM_ATTRIBUTE_USED void dump() const;
   LLVM_ATTRIBUTE_USED void dump(SourceManager &SM) const;
+  void dump(llvm::raw_ostream &OS, SourceManager *SM) const;
 
   static bool classof(const Comment *) { return true; }
 
index 1520d1341722fcf8f7102244cdebb0133faf9ad2..e215e63dec94d301c94f16d923d74c845df4bf9c 100644 (file)
@@ -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 @@ const char *Comment::getCommentKindName() const {
   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 {};
index 7a075a67488d60a9b534f2e523d847ccb480dce3..5de5ef544f1b5707acd512432e751ddd3e1e9891 100644 (file)
@@ -181,14 +181,8 @@ void CommentDumper::visitFullComment(const FullComment *C) {
 
 } // unnamed namespace
 
-void Comment::dump() const {
-  CommentDumper D(llvm::errs(), NULL);
-  D.dumpSubtree(this);
-  llvm::errs() << '\n';
-}
-
-void Comment::dump(SourceManager &SM) const {
-  CommentDumper D(llvm::errs(), &SM);
+void Comment::dump(llvm::raw_ostream &OS, SourceManager *SM) const {
+  CommentDumper D(llvm::errs(), SM);
   D.dumpSubtree(this);
   llvm::errs() << '\n';
 }