]> granicus.if.org Git - clang/commitdiff
Patch to fix a regression caused by recent rewrite changes.
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 26 Nov 2007 19:52:57 +0000 (19:52 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 26 Nov 2007 19:52:57 +0000 (19:52 +0000)
A potential API bug in ReplaceText pending (A FIXME is added).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44333 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/RewriteTest.cpp
test/Sema/rewrite-api-bug.m [new file with mode: 0644]

index 23bf240ac82e472a741efa3abd220cdc752c44ef..cc6d56959e28939f3e8b28f67f3cbd9f24c54c37 100644 (file)
@@ -1310,20 +1310,26 @@ void RewriteTest::SynthesizeObjcInternalStruct(ObjcInterfaceDecl *CDecl,
   }
   
   int NumIvars = CDecl->getNumInstanceVariables();
+  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)))
+  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();
-
-  SourceLocation LocStart = CDecl->getLocStart();
-  SourceLocation LocEnd = CDecl->getLocEnd();
-  
-  const char *startBuf = SM->getCharacterData(LocStart);
-  const char *endBuf = SM->getCharacterData(LocEnd);
   
   if (NumIvars > 0) {
     const char *cursor = strchr(startBuf, '{');
diff --git a/test/Sema/rewrite-api-bug.m b/test/Sema/rewrite-api-bug.m
new file mode 100644 (file)
index 0000000..35b919c
--- /dev/null
@@ -0,0 +1,13 @@
+// RUN: clang -rewrite-test %s
+
+#include <Objc/objc.h>
+
+@interface MyDerived
+- (void) instanceMethod;
+@end
+
+@implementation MyDerived
+- (void) instanceMethod {
+}
+@end
+