aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-06-11 23:09:25 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-06-11 23:09:25 +0000
commit1715bf5ed87c792c63278e739bc492921d512a88 (patch)
tree1ee76cb90a3b1df2b3d8b891607900ac657043ca
parent464ccb68f22a7e1c0a2844551c16f721540c91c3 (diff)
Fix PCH issue. Attributes of a declaration were truncated to just one when the decl was read from a PCH file.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105852 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/DeclBase.h1
-rw-r--r--lib/AST/DeclBase.cpp11
-rw-r--r--lib/Frontend/PCHReaderDecl.cpp2
-rw-r--r--test/PCH/attrs.h2
4 files changed, 14 insertions, 2 deletions
diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h
index 3e2435197d..f6478d9ea6 100644
--- a/include/clang/AST/DeclBase.h
+++ b/include/clang/AST/DeclBase.h
@@ -297,6 +297,7 @@ public:
}
bool hasAttrs() const { return HasAttrs; }
+ void initAttrs(Attr *attrs);
void addAttr(Attr *attr);
const Attr *getAttrs() const {
if (!HasAttrs) return 0; // common case, no attributes.
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp
index 8f6fdbc956..f1b78e40fc 100644
--- a/lib/AST/DeclBase.cpp
+++ b/lib/AST/DeclBase.cpp
@@ -314,9 +314,20 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {
return 0;
}
+void Decl::initAttrs(Attr *attrs) {
+ assert(!HasAttrs && "Decl already contains attrs.");
+
+ Attr *&AttrBlank = getASTContext().getDeclAttrs(this);
+ assert(AttrBlank == 0 && "HasAttrs was wrong?");
+
+ AttrBlank = attrs;
+ HasAttrs = true;
+}
+
void Decl::addAttr(Attr *NewAttr) {
Attr *&ExistingAttr = getASTContext().getDeclAttrs(this);
+ assert(NewAttr->getNext() == 0 && "Chain of attributes will be truncated!");
NewAttr->setNext(ExistingAttr);
ExistingAttr = NewAttr;
diff --git a/lib/Frontend/PCHReaderDecl.cpp b/lib/Frontend/PCHReaderDecl.cpp
index 7ccf14362f..cece1b659c 100644
--- a/lib/Frontend/PCHReaderDecl.cpp
+++ b/lib/Frontend/PCHReaderDecl.cpp
@@ -113,7 +113,7 @@ void PCHDeclReader::VisitDecl(Decl *D) {
D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
D->setInvalidDecl(Record[Idx++]);
if (Record[Idx++])
- D->addAttr(Reader.ReadAttributes());
+ D->initAttrs(Reader.ReadAttributes());
D->setImplicit(Record[Idx++]);
D->setUsed(Record[Idx++]);
D->setAccess((AccessSpecifier)Record[Idx++]);
diff --git a/test/PCH/attrs.h b/test/PCH/attrs.h
index 0d0156515c..58f0589704 100644
--- a/test/PCH/attrs.h
+++ b/test/PCH/attrs.h
@@ -4,4 +4,4 @@
-int f(int) __attribute__((overloadable));
+int f(int) __attribute__((visibility("default"), overloadable));