[cfe-commits] r160437 - in /cfe/trunk: include/clang/AST/Comment.h lib/AST/Comment.cpp lib/AST/CommentDumper.cpp
Dmitri Gribenko
gribozavr at gmail.com
Wed Jul 18 09:30:43 PDT 2012
Author: gribozavr
Date: Wed Jul 18 11:30:42 2012
New Revision: 160437
URL: http://llvm.org/viewvc/llvm-project?rev=160437&view=rev
Log:
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!
Modified:
cfe/trunk/include/clang/AST/Comment.h
cfe/trunk/lib/AST/Comment.cpp
cfe/trunk/lib/AST/CommentDumper.cpp
Modified: cfe/trunk/include/clang/AST/Comment.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Comment.h?rev=160437&r1=160436&r2=160437&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Comment.h (original)
+++ cfe/trunk/include/clang/AST/Comment.h Wed Jul 18 11:30:42 2012
@@ -115,6 +115,7 @@
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; }
Modified: cfe/trunk/lib/AST/Comment.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Comment.cpp?rev=160437&r1=160436&r2=160437&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Comment.cpp (original)
+++ cfe/trunk/lib/AST/Comment.cpp Wed Jul 18 11:30:42 2012
@@ -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 {};
Modified: cfe/trunk/lib/AST/CommentDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentDumper.cpp?rev=160437&r1=160436&r2=160437&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CommentDumper.cpp (original)
+++ cfe/trunk/lib/AST/CommentDumper.cpp Wed Jul 18 11:30:42 2012
@@ -181,14 +181,8 @@
} // 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';
}
More information about the cfe-commits
mailing list