From a883d6ed8959d0acb599239e303ebcc969e0a083 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Mon, 26 Nov 2007 19:52:57 +0000 Subject: [PATCH] Patch to fix a regression caused by recent rewrite changes. A potential API bug in ReplaceText pending (A FIXME is added). llvm-svn: 44333 --- clang/Driver/RewriteTest.cpp | 24 +++++++++++++++--------- clang/test/Sema/rewrite-api-bug.m | 13 +++++++++++++ 2 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 clang/test/Sema/rewrite-api-bug.m diff --git a/clang/Driver/RewriteTest.cpp b/clang/Driver/RewriteTest.cpp index 23bf240ac82e..cc6d56959e28 100644 --- a/clang/Driver/RewriteTest.cpp +++ b/clang/Driver/RewriteTest.cpp @@ -1310,20 +1310,26 @@ void RewriteTest::SynthesizeObjcInternalStruct(ObjcInterfaceDecl *CDecl, } int NumIvars = CDecl->getNumInstanceVariables(); - // If no ivars and no root or if its root, directly or indirectly, - // have no ivars (thus not synthesized) then no need to synthesize this class. - if (NumIvars <= 0 && (!RCDecl || !ObjcSynthesizedStructs.count(RCDecl))) - return; - // FIXME: This has potential of causing problem. If - // SynthesizeObjcInternalStruct is ever called recursively. - Result += "\nstruct "; - Result += CDecl->getName(); - SourceLocation LocStart = CDecl->getLocStart(); SourceLocation LocEnd = CDecl->getLocEnd(); const char *startBuf = SM->getCharacterData(LocStart); const char *endBuf = SM->getCharacterData(LocEnd); + // If no ivars and no root or if its root, directly or indirectly, + // have no ivars (thus not synthesized) then no need to synthesize this class. + if (NumIvars <= 0 && (!RCDecl || !ObjcSynthesizedStructs.count(RCDecl))) { + //FIXME: This does not replace @interface class-name with the + //Result text. Could be a bug in ReplaceText API. + endBuf += Lexer::MeasureTokenLength(LocEnd, *SM); + Rewrite.ReplaceText(LocStart, endBuf-startBuf, + Result.c_str(), Result.size()); + return; + } + + // FIXME: This has potential of causing problem. If + // SynthesizeObjcInternalStruct is ever called recursively. + Result += "\nstruct "; + Result += CDecl->getName(); if (NumIvars > 0) { const char *cursor = strchr(startBuf, '{'); diff --git a/clang/test/Sema/rewrite-api-bug.m b/clang/test/Sema/rewrite-api-bug.m new file mode 100644 index 000000000000..35b919c4cea7 --- /dev/null +++ b/clang/test/Sema/rewrite-api-bug.m @@ -0,0 +1,13 @@ +// RUN: clang -rewrite-test %s + +#include + +@interface MyDerived +- (void) instanceMethod; +@end + +@implementation MyDerived +- (void) instanceMethod { +} +@end +