Fix an obscure rewriter bug when rewriting implementations that don't have a corresponding interface (found while doing random testing on another bug).

llvm-svn: 59259
This commit is contained in:
Steve Naroff 2008-11-13 20:07:04 +00:00
parent 935963de81
commit f8cfd1647e
1 changed files with 15 additions and 6 deletions

View File

@ -245,7 +245,8 @@ namespace {
void SynthesizeIvarOffsetComputation(ObjCImplementationDecl *IDecl, void SynthesizeIvarOffsetComputation(ObjCImplementationDecl *IDecl,
ObjCIvarDecl *ivar, ObjCIvarDecl *ivar,
std::string &Result); std::string &Result);
void RewriteImplementations(std::string &Result); void RewriteImplementations();
void SynthesizeMetaDataIntoBuffer(std::string &Result);
// Block rewriting. // Block rewriting.
void RewriteBlocksInFunctionTypeProto(QualType funcType, NamedDecl *D); void RewriteBlocksInFunctionTypeProto(QualType funcType, NamedDecl *D);
@ -3071,7 +3072,7 @@ void RewriteObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl,
/// RewriteImplementations - This routine rewrites all method implementations /// RewriteImplementations - This routine rewrites all method implementations
/// and emits meta-data. /// and emits meta-data.
void RewriteObjC::RewriteImplementations(std::string &Result) { void RewriteObjC::RewriteImplementations() {
int ClsDefCount = ClassImplementation.size(); int ClsDefCount = ClassImplementation.size();
int CatDefCount = CategoryImplementation.size(); int CatDefCount = CategoryImplementation.size();
@ -3083,6 +3084,11 @@ void RewriteObjC::RewriteImplementations(std::string &Result) {
for (int i = 0; i < CatDefCount; i++) for (int i = 0; i < CatDefCount; i++)
RewriteImplementationDecl(CategoryImplementation[i]); RewriteImplementationDecl(CategoryImplementation[i]);
}
void RewriteObjC::SynthesizeMetaDataIntoBuffer(std::string &Result) {
int ClsDefCount = ClassImplementation.size();
int CatDefCount = CategoryImplementation.size();
// This is needed for determining instance variable offsets. // This is needed for determining instance variable offsets.
Result += "\n#define __OFFSETOFIVAR__(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)\n"; Result += "\n#define __OFFSETOFIVAR__(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)\n";
@ -4125,9 +4131,7 @@ void RewriteObjC::HandleTranslationUnit(TranslationUnit& TU) {
InsertText(SourceLocation::getFileLoc(MainFileID, 0), InsertText(SourceLocation::getFileLoc(MainFileID, 0),
Preamble.c_str(), Preamble.size(), false); Preamble.c_str(), Preamble.size(), false);
// Rewrite Objective-c meta data* RewriteImplementations();
std::string ResultStr;
RewriteImplementations(ResultStr);
// Get the buffer corresponding to MainFileID. If we haven't changed it, then // Get the buffer corresponding to MainFileID. If we haven't changed it, then
// we are done. // we are done.
@ -4138,6 +4142,11 @@ void RewriteObjC::HandleTranslationUnit(TranslationUnit& TU) {
} else { } else {
fprintf(stderr, "No changes\n"); fprintf(stderr, "No changes\n");
} }
// Rewrite Objective-c meta data*
std::string ResultStr;
SynthesizeMetaDataIntoBuffer(ResultStr);
// Emit metadata. // Emit metadata.
*OutFile << ResultStr; *OutFile << ResultStr;
OutFile->flush(); OutFile->flush();