Author: akirtzidis Date: Mon Oct 18 14:20:11 2010 New Revision: 116737 URL: http://llvm.org/viewvc/llvm-project?rev=116737&view=rev Log: Read/write declaration attributes from/to PCH properly. Embed them in the declaration block instead of trying to create another block.
The new block was messing with the assumption that after decls block comes the stmts block. Fixes http://llvm.org/PR8406 Added: cfe/trunk/test/PCH/attrs-PR8406.c Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h cfe/trunk/include/clang/Serialization/ASTReader.h cfe/trunk/include/clang/Serialization/ASTWriter.h cfe/trunk/lib/Serialization/ASTReaderDecl.cpp cfe/trunk/lib/Serialization/ASTWriter.cpp cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=116737&r1=116736&r2=116737&view=diff ============================================================================== --- cfe/trunk/include/clang/Serialization/ASTBitCodes.h (original) +++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h Mon Oct 18 14:20:11 2010 @@ -579,10 +579,8 @@ /// constant describes a record for a specific declaration class /// in the AST. enum DeclCode { - /// \brief Attributes attached to a declaration. - DECL_ATTR = 50, /// \brief A TranslationUnitDecl record. - DECL_TRANSLATION_UNIT, + DECL_TRANSLATION_UNIT = 50, /// \brief A TypedefDecl record. DECL_TYPEDEF, /// \brief An EnumDecl record. Modified: cfe/trunk/include/clang/Serialization/ASTReader.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=116737&r1=116736&r2=116737&view=diff ============================================================================== --- cfe/trunk/include/clang/Serialization/ASTReader.h (original) +++ cfe/trunk/include/clang/Serialization/ASTReader.h Mon Oct 18 14:20:11 2010 @@ -1095,7 +1095,8 @@ CXXTemporary *ReadCXXTemporary(const RecordData &Record, unsigned &Idx); /// \brief Reads attributes from the current stream position. - void ReadAttributes(PerFileData &F, AttrVec &Attrs); + void ReadAttributes(PerFileData &F, AttrVec &Attrs, + const RecordData &Record, unsigned &Idx); /// \brief Reads a statement. Stmt *ReadStmt(PerFileData &F); Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=116737&r1=116736&r2=116737&view=diff ============================================================================== --- cfe/trunk/include/clang/Serialization/ASTWriter.h (original) +++ cfe/trunk/include/clang/Serialization/ASTWriter.h Mon Oct 18 14:20:11 2010 @@ -279,7 +279,7 @@ void WriteSelectors(Sema &SemaRef); void WriteReferencedSelectorsPool(Sema &SemaRef); void WriteIdentifierTable(Preprocessor &PP); - void WriteAttributeRecord(const AttrVec &Attrs); + void WriteAttributes(const AttrVec &Attrs, RecordData &Record); void WriteDeclUpdateBlock(); void WriteDeclContextVisibleUpdate(const DeclContext *DC); void WriteAdditionalTemplateSpecializations(); Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=116737&r1=116736&r2=116737&view=diff ============================================================================== --- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original) +++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Mon Oct 18 14:20:11 2010 @@ -172,9 +172,9 @@ cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++]))); D->setLocation(ReadSourceLocation(Record, Idx)); D->setInvalidDecl(Record[Idx++]); - if (Record[Idx++]) { + if (Record[Idx++]) { // hasAttrs AttrVec Attrs; - Reader.ReadAttributes(F, Attrs); + Reader.ReadAttributes(F, Attrs, Record, Idx); D->setAttrs(Attrs); } D->setImplicit(Record[Idx++]); @@ -1200,19 +1200,9 @@ //===----------------------------------------------------------------------===// /// \brief Reads attributes from the current stream position. -void ASTReader::ReadAttributes(PerFileData &F, AttrVec &Attrs) { - llvm::BitstreamCursor &DeclsCursor = F.DeclsCursor; - unsigned Code = DeclsCursor.ReadCode(); - assert(Code == llvm::bitc::UNABBREV_RECORD && - "Expected unabbreviated record"); (void)Code; - - RecordData Record; - unsigned Idx = 0; - unsigned RecCode = DeclsCursor.ReadRecord(Code, Record); - assert(RecCode == DECL_ATTR && "Expected attribute record"); - (void)RecCode; - - while (Idx < Record.size()) { +void ASTReader::ReadAttributes(PerFileData &F, AttrVec &Attrs, + const RecordData &Record, unsigned &Idx) { + for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) { Attr *New = 0; attr::Kind Kind = (attr::Kind)Record[Idx++]; SourceLocation Loc = ReadSourceLocation(F, Record, Idx); @@ -1299,7 +1289,6 @@ Decl *D = 0; switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) { - case DECL_ATTR: case DECL_CONTEXT_LEXICAL: case DECL_CONTEXT_VISIBLE: assert(false && "Record cannot be de-serialized with ReadDeclRecord"); Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=116737&r1=116736&r2=116737&view=diff ============================================================================== --- cfe/trunk/lib/Serialization/ASTWriter.cpp (original) +++ cfe/trunk/lib/Serialization/ASTWriter.cpp Mon Oct 18 14:20:11 2010 @@ -684,7 +684,6 @@ RECORD(TYPE_OBJC_INTERFACE); RECORD(TYPE_OBJC_OBJECT); RECORD(TYPE_OBJC_OBJECT_POINTER); - RECORD(DECL_ATTR); RECORD(DECL_TRANSLATION_UNIT); RECORD(DECL_TYPEDEF); RECORD(DECL_ENUM); @@ -2168,8 +2167,8 @@ //===----------------------------------------------------------------------===// /// \brief Write a record containing the given attributes. -void ASTWriter::WriteAttributeRecord(const AttrVec &Attrs) { - RecordData Record; +void ASTWriter::WriteAttributes(const AttrVec &Attrs, RecordData &Record) { + Record.push_back(Attrs.size()); for (AttrVec::const_iterator i = Attrs.begin(), e = Attrs.end(); i != e; ++i){ const Attr * A = *i; Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs @@ -2179,8 +2178,6 @@ #include "clang/Serialization/AttrPCHWrite.inc" } - - Stream.EmitRecord(DECL_ATTR, Record); } void ASTWriter::AddString(llvm::StringRef Str, RecordData &Record) { Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=116737&r1=116736&r2=116737&view=diff ============================================================================== --- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original) +++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Mon Oct 18 14:20:11 2010 @@ -133,6 +133,8 @@ Writer.AddSourceLocation(D->getLocation(), Record); Record.push_back(D->isInvalidDecl()); Record.push_back(D->hasAttrs()); + if (D->hasAttrs()) + Writer.WriteAttributes(D->getAttrs(), Record); Record.push_back(D->isImplicit()); Record.push_back(D->isUsed(false)); Record.push_back(D->getAccess()); @@ -1212,10 +1214,6 @@ D->getDeclKindName() + "'"); Stream.EmitRecord(W.Code, Record, W.AbbrevToUse); - // If the declaration had any attributes, write them now. - if (D->hasAttrs()) - WriteAttributeRecord(D->getAttrs()); - // Flush any expressions that were written as part of this declaration. FlushStmts(); Added: cfe/trunk/test/PCH/attrs-PR8406.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/attrs-PR8406.c?rev=116737&view=auto ============================================================================== --- cfe/trunk/test/PCH/attrs-PR8406.c (added) +++ cfe/trunk/test/PCH/attrs-PR8406.c Mon Oct 18 14:20:11 2010 @@ -0,0 +1,23 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %s -emit-llvm -o - %s | FileCheck %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t %s +// RUN: %clang_cc1 -include-pch %t -emit-llvm -o - %s | FileCheck %s + +#ifndef HEADER +#define HEADER + +struct Bar +{ + // CHECK: align 512 + int buffer[123] __attribute__((__aligned__(512))); +}; + +#else + +void foo() { + struct Bar bar; +} + +#endif _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
