[cfe-commits] r150456 - in /cfe/trunk/tools: c-index-test/c-index-test.c libclang/CIndexDiagnostic.cpp libclang/CIndexDiagnostic.h
Ted Kremenek
kremenek at apple.com
Mon Feb 13 23:01:34 PST 2012
Fixed in 150461.
On Feb 13, 2012, at 10:26 PM, Ted Kremenek wrote:
> Just got back online. Looking at it now.
>
> On Feb 13, 2012, at 9:38 PM, David Blaikie wrote:
>
>> On Mon, Feb 13, 2012 at 9:35 PM, Douglas Gregor <dgregor at apple.com> wrote:
>>>
>>> On Feb 13, 2012, at 6:46 PM, Ted Kremenek wrote:
>>>
>>>> Author: kremenek
>>>> Date: Mon Feb 13 20:46:03 2012
>>>> New Revision: 150456
>>>>
>>>> URL: http://llvm.org/viewvc/llvm-project?rev=150456&view=rev
>>>> Log:
>>>> Implement new DiagnosticsRenderer that packages notes retrieved by clang_getDiagnosticSetFromTU() as
>>>> child diagnostics of primary diagnostics. By using the DiagnosticRenderer, these Diagnostics now
>>>> match with those generated for serialized diagnostics.
>>>
>>> I'm seeing occasional use-after-free errors in test/Index/fix-its.c after this patch. Backtrace follows.
>>
>> I'm seeing this quite consistently on this test (on Ubuntu, for
>> whatever that's worth) & idly poking to see if I can find a fix.
>> Buildbots have been reporting this for a while so I assume Ted isn't
>> around to see the mail.
>>
>>>
>>> - Doug
>>>
>>> #1 0x00007fff8e69e805 in free ()
>>> #2 0x00000001000c00ba in clang_disposeString (string={data = 0x103200c70, private_flags = 1}) at /Users/dgregor/Projects/llvm/tools/clang/tools/libclang/CXString.cpp:126
>>> #3 0x0000000100088e83 in ~CXDiagnosticCustomNoteImpl (this=0x103200c10) at /Users/dgregor/Projects/llvm/tools/clang/tools/libclang/CIndexDiagnostic.cpp:55
>>> #4 0x0000000100088c55 in ~CXDiagnosticCustomNoteImpl (this=0x103200c10) at /Users/dgregor/Projects/llvm/tools/clang/tools/libclang/CIndexDiagnostic.cpp:54
>>> #5 0x0000000100088c79 in ~CXDiagnosticCustomNoteImpl (this=0x103200c10) at /Users/dgregor/Projects/llvm/tools/clang/tools/libclang/CIndexDiagnostic.cpp:54
>>> #6 0x00000001000870f7 in clang::CXDiagnosticSetImpl::~CXDiagnosticSetImpl (this=0x103200ad8) at /Users/dgregor/Projects/llvm/tools/clang/tools/libclang/CIndexDiagnostic.cpp:39
>>> #7 0x0000000100086f65 in clang::CXDiagnosticSetImpl::~CXDiagnosticSetImpl (this=0x103200ad8) at /Users/dgregor/Projects/llvm/tools/clang/tools/libclang/CIndexDiagnostic.cpp:35
>>> #8 0x00000001000871bc in clang::CXDiagnosticImpl::~CXDiagnosticImpl (this=0x103200ad0) at /Users/dgregor/Projects/llvm/tools/clang/tools/libclang/CIndexDiagnostic.cpp:43
>>> #9 0x000000010006fc55 in clang::CXStoredDiagnostic::~CXStoredDiagnostic (this=0x103200ad0) at CIndexDiagnostic.h:118
>>> #10 0x000000010006f615 in clang::CXStoredDiagnostic::~CXStoredDiagnostic (this=0x103200ad0) at CIndexDiagnostic.h:118
>>> #11 0x00000001000bf6d9 in clang::CXStoredDiagnostic::~CXStoredDiagnostic (this=0x103200ad0) at CIndexDiagnostic.h:118
>>> #12 0x00000001000870f7 in clang::CXDiagnosticSetImpl::~CXDiagnosticSetImpl (this=0x103200aa0) at /Users/dgregor/Projects/llvm/tools/clang/tools/libclang/CIndexDiagnostic.cpp:39
>>> #13 0x0000000100086f65 in clang::CXDiagnosticSetImpl::~CXDiagnosticSetImpl (this=0x103200aa0) at /Users/dgregor/Projects/llvm/tools/clang/tools/libclang/CIndexDiagnostic.cpp:35
>>> #14 0x0000000100086f39 in clang::CXDiagnosticSetImpl::~CXDiagnosticSetImpl (this=0x103200aa0) at /Users/dgregor/Projects/llvm/tools/clang/tools/libclang/CIndexDiagnostic.cpp:35
>>> #15 0x000000010001af11 in clang_disposeTranslationUnit (CTUnit=0x103309be0) at /Users/dgregor/Projects/llvm/tools/clang/tools/libclang/CIndex.cpp:2623
>>> #16 0x0000000100003f10 in perform_test_load (Idx=0x103200a50, TU=0x103309be0, filter=0x7fff5fbff81a "all", prefix=0x0, Visitor=0x100002470 <FilteredPrintingVisitor>, PV=0) at /Users/dgregor/Projects/llvm/tools/clang/tools/c-index-test/c-index-test.c:725
>>> #17 0x00000001000040fb in perform_test_load_source (argc=2, argv=0x7fff5fbff690, filter=0x7fff5fbff81a "all", Visitor=0x100002470 <FilteredPrintingVisitor>, PV=0) at /Users/dgregor/Projects/llvm/tools/clang/tools/c-index-test/c-index-test.c:780
>>> #18 0x00000001000074fd in cindextest_main (argc=5, argv=0x7fff5fbff678) at /Users/dgregor/Projects/llvm/tools/clang/tools/c-index-test/c-index-test.c:2658
>>> #19 0x0000000100009407 in thread_runner (client_data_v=0x7fff5fbff628) at /Users/dgregor/Projects/llvm/tools/clang/tools/c-index-test/c-index-test.c:2708
>>> #20 0x0000000100febabe in ExecuteOnThread_Dispatch (Arg=0x7fff5fbff5b8) at /Users/dgregor/Projects/llvm/lib/Support/Threading.cpp:75
>>> #21 0x00007fff8e64c8bf in _pthread_start ()
>>> #22 0x00007fff8e64fb75 in thread_start ()
>>>
>>>> Modified:
>>>> cfe/trunk/tools/c-index-test/c-index-test.c
>>>> cfe/trunk/tools/libclang/CIndexDiagnostic.cpp
>>>> cfe/trunk/tools/libclang/CIndexDiagnostic.h
>>>>
>>>> Modified: cfe/trunk/tools/c-index-test/c-index-test.c
>>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=150456&r1=150455&r2=150456&view=diff
>>>> ==============================================================================
>>>> --- cfe/trunk/tools/c-index-test/c-index-test.c (original)
>>>> +++ cfe/trunk/tools/c-index-test/c-index-test.c Mon Feb 13 20:46:03 2012
>>>> @@ -418,13 +418,21 @@
>>>> }
>>>> }
>>>>
>>>> -void PrintDiagnostics(CXTranslationUnit TU) {
>>>> - int i, n = clang_getNumDiagnostics(TU);
>>>> - for (i = 0; i != n; ++i) {
>>>> - CXDiagnostic Diag = clang_getDiagnostic(TU, i);
>>>> +void PrintDiagnosticSet(CXDiagnosticSet Set) {
>>>> + int i = 0, n = clang_getNumDiagnosticsInSet(Set);
>>>> + for ( ; i != n ; ++i) {
>>>> + CXDiagnostic Diag = clang_getDiagnosticInSet(Set, i);
>>>> + CXDiagnosticSet ChildDiags = clang_getChildDiagnostics(Diag);
>>>> PrintDiagnostic(Diag);
>>>> - clang_disposeDiagnostic(Diag);
>>>> - }
>>>> + if (ChildDiags)
>>>> + PrintDiagnosticSet(ChildDiags);
>>>> + }
>>>> +}
>>>> +
>>>> +void PrintDiagnostics(CXTranslationUnit TU) {
>>>> + CXDiagnosticSet TUSet = clang_getDiagnosticSetFromTU(TU);
>>>> + PrintDiagnosticSet(TUSet);
>>>> + clang_disposeDiagnosticSet(TUSet);
>>>> }
>>>>
>>>> void PrintMemoryUsage(CXTranslationUnit TU) {
>>>>
>>>> Modified: cfe/trunk/tools/libclang/CIndexDiagnostic.cpp
>>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexDiagnostic.cpp?rev=150456&r1=150455&r2=150456&view=diff
>>>> ==============================================================================
>>>> --- cfe/trunk/tools/libclang/CIndexDiagnostic.cpp (original)
>>>> +++ cfe/trunk/tools/libclang/CIndexDiagnostic.cpp Mon Feb 13 20:46:03 2012
>>>> @@ -18,6 +18,8 @@
>>>>
>>>> #include "clang/Frontend/ASTUnit.h"
>>>> #include "clang/Frontend/FrontendDiagnostic.h"
>>>> +#include "clang/Frontend/DiagnosticRenderer.h"
>>>> +#include "clang/Frontend/DiagnosticOptions.h"
>>>> #include "llvm/ADT/SmallString.h"
>>>> #include "llvm/ADT/Twine.h"
>>>> #include "llvm/Support/MemoryBuffer.h"
>>>> @@ -40,6 +42,109 @@
>>>>
>>>> CXDiagnosticImpl::~CXDiagnosticImpl() {}
>>>>
>>>> +namespace {
>>>> +class CXDiagnosticCustomNoteImpl : public CXDiagnosticImpl {
>>>> + CXString Message;
>>>> + CXSourceLocation Loc;
>>>> +public:
>>>> + CXDiagnosticCustomNoteImpl(StringRef Msg, CXSourceLocation L)
>>>> + : CXDiagnosticImpl(CustomNoteDiagnosticKind),
>>>> + Message(createCXString(Msg)), Loc(L) {}
>>>> +
>>>> + virtual ~CXDiagnosticCustomNoteImpl() {
>>>> + clang_disposeString(Message);
>>>> + }
>>>> +
>>>> + CXDiagnosticSeverity getSeverity() const {
>>>> + return CXDiagnostic_Note;
>>>> + }
>>>> +
>>>> + CXSourceLocation getLocation() const {
>>>> + return Loc;
>>>> + }
>>>> +
>>>> + CXString getSpelling() const {
>>>> + return Message;
>>>> + }
>>>> +
>>>> + CXString getDiagnosticOption(CXString *Disable) const {
>>>> + if (Disable)
>>>> + *Disable = createCXString("", false);
>>>> + return createCXString("", false);
>>>> + }
>>>> +
>>>> + unsigned getCategory() const { return 0; }
>>>> + unsigned getNumRanges() const { return 0; }
>>>> + CXSourceRange getRange(unsigned Range) const { return clang_getNullRange(); }
>>>> + unsigned getNumFixIts() const { return 0; }
>>>> + CXString getFixIt(unsigned FixIt, CXSourceRange *ReplacementRange) const {
>>>> + if (ReplacementRange)
>>>> + *ReplacementRange = clang_getNullRange();
>>>> + return createCXString("", false);
>>>> + }
>>>> +};
>>>> +
>>>> +class CXDiagnosticRenderer : public DiagnosticNoteRenderer {
>>>> +public:
>>>> + CXDiagnosticRenderer(const SourceManager &SM,
>>>> + const LangOptions &LangOpts,
>>>> + const DiagnosticOptions &DiagOpts,
>>>> + CXDiagnosticSetImpl *mainSet)
>>>> + : DiagnosticNoteRenderer(SM, LangOpts, DiagOpts),
>>>> + CurrentSet(mainSet), MainSet(mainSet) {}
>>>> +
>>>> + virtual ~CXDiagnosticRenderer() {}
>>>> +
>>>> + virtual void beginDiagnostic(DiagOrStoredDiag D,
>>>> + DiagnosticsEngine::Level Level) {
>>>> +
>>>> + const StoredDiagnostic *SD = D.dyn_cast<const StoredDiagnostic*>();
>>>> + if (!SD)
>>>> + return;
>>>> +
>>>> + if (Level != DiagnosticsEngine::Note)
>>>> + CurrentSet = MainSet;
>>>> +
>>>> + CXStoredDiagnostic *CD = new CXStoredDiagnostic(*SD, LangOpts);
>>>> + CurrentSet->appendDiagnostic(CD);
>>>> +
>>>> + if (Level != DiagnosticsEngine::Note)
>>>> + CurrentSet = &CD->getChildDiagnostics();
>>>> + }
>>>> +
>>>> + virtual void emitDiagnosticMessage(SourceLocation Loc, PresumedLoc PLoc,
>>>> + DiagnosticsEngine::Level Level,
>>>> + StringRef Message,
>>>> + ArrayRef<CharSourceRange> Ranges,
>>>> + DiagOrStoredDiag D) {
>>>> + if (!D.isNull())
>>>> + return;
>>>> +
>>>> + CXSourceLocation L = translateSourceLocation(SM, LangOpts, Loc);
>>>> + CXDiagnosticImpl *CD = new CXDiagnosticCustomNoteImpl(Message, L);
>>>> + CurrentSet->appendDiagnostic(CD);
>>>> + }
>>>> +
>>>> + virtual void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
>>>> + DiagnosticsEngine::Level Level,
>>>> + ArrayRef<CharSourceRange> Ranges) {}
>>>> +
>>>> + virtual void emitCodeContext(SourceLocation Loc,
>>>> + DiagnosticsEngine::Level Level,
>>>> + SmallVectorImpl<CharSourceRange>& Ranges,
>>>> + ArrayRef<FixItHint> Hints) {};
>>>> +
>>>> + virtual void emitNote(SourceLocation Loc, StringRef Message) {
>>>> + CXSourceLocation L = translateSourceLocation(SM, LangOpts, Loc);
>>>> + CurrentSet->appendDiagnostic(new CXDiagnosticCustomNoteImpl(Message,
>>>> + L));
>>>> + }
>>>> +
>>>> + CXDiagnosticSetImpl *CurrentSet;
>>>> + CXDiagnosticSetImpl *MainSet;
>>>> +};
>>>> +}
>>>> +
>>>> CXDiagnosticSetImpl *cxdiag::lazyCreateDiags(CXTranslationUnit TU,
>>>> bool checkIfChanged) {
>>>> ASTUnit *AU = static_cast<ASTUnit *>(TU->TUData);
>>>> @@ -75,12 +180,14 @@
>>>> if (!TU->Diagnostics) {
>>>> CXDiagnosticSetImpl *Set = new CXDiagnosticSetImpl();
>>>> TU->Diagnostics = Set;
>>>> + DiagnosticOptions DOpts;
>>>> + CXDiagnosticRenderer Renderer(AU->getSourceManager(),
>>>> + AU->getASTContext().getLangOptions(),
>>>> + DOpts, Set);
>>>>
>>>> for (ASTUnit::stored_diag_iterator it = AU->stored_diag_begin(),
>>>> ei = AU->stored_diag_end(); it != ei; ++it) {
>>>> - CXStoredDiagnostic *D =
>>>> - new CXStoredDiagnostic(*it, AU->getASTContext().getLangOptions());
>>>> - Set->appendDiagnostic(D);
>>>> + Renderer.emitStoredDiagnostic(*it);
>>>> }
>>>> }
>>>> return static_cast<CXDiagnosticSetImpl*>(TU->Diagnostics);
>>>>
>>>> Modified: cfe/trunk/tools/libclang/CIndexDiagnostic.h
>>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexDiagnostic.h?rev=150456&r1=150455&r2=150456&view=diff
>>>> ==============================================================================
>>>> --- cfe/trunk/tools/libclang/CIndexDiagnostic.h (original)
>>>> +++ cfe/trunk/tools/libclang/CIndexDiagnostic.h Mon Feb 13 20:46:03 2012
>>>> @@ -54,7 +54,8 @@
>>>>
>>>> class CXDiagnosticImpl {
>>>> public:
>>>> - enum Kind { StoredDiagnosticKind, LoadedDiagnosticKind };
>>>> + enum Kind { StoredDiagnosticKind, LoadedDiagnosticKind,
>>>> + CustomNoteDiagnosticKind };
>>>>
>>>> virtual ~CXDiagnosticImpl();
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> cfe-commits mailing list
>>>> cfe-commits at cs.uiuc.edu
>>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>>
>>> _______________________________________________
>>> cfe-commits mailing list
>>> cfe-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list