From 4dddb6194bccead1564f6b8189c4fdad307a4417 Mon Sep 17 00:00:00 2001 From: Steve Naroff Date: Mon, 9 Jul 2007 18:55:26 +0000 Subject: [PATCH] Bug #: Submitted by: Reviewed by: Fix a bozo bug in HandleDeclAttribute...only install a new type when appropriate. Also changed setType/setUnderlyingType to return void. llvm-svn: 39716 --- clang/Sema/SemaDecl.cpp | 10 ++++------ clang/include/clang/AST/Decl.h | 12 ++---------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/clang/Sema/SemaDecl.cpp b/clang/Sema/SemaDecl.cpp index c86175dbaceb..bef5c674296d 100644 --- a/clang/Sema/SemaDecl.cpp +++ b/clang/Sema/SemaDecl.cpp @@ -942,16 +942,14 @@ void Sema::HandleDeclAttribute(Decl *New, AttributeList *rawAttr) { if (strcmp(rawAttr->getAttributeName()->getName(), "vector_size") == 0) { if (ValueDecl *vDecl = dyn_cast(New)) { QualType newType = HandleVectorTypeAttribute(vDecl->getType(), rawAttr); - // install the new vector type into the decl - QualType oldType = vDecl->setType(newType); - // FIXME: deal with memory management for oldType! + if (!newType.isNull()) // install the new vector type into the decl + vDecl->setType(newType); } if (TypedefDecl *tDecl = dyn_cast(New)) { QualType newType = HandleVectorTypeAttribute(tDecl->getUnderlyingType(), rawAttr); - // install the new vector type into the decl - QualType oldType = tDecl->setUnderlyingType(newType); - // FIXME: deal with memory management for oldType! + if (!newType.isNull()) // install the new vector type into the decl + tDecl->setUnderlyingType(newType); } } // FIXME: add other attributes... diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 063f98347723..2d3b01d3ced0 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -128,11 +128,7 @@ protected: Decl *PrevDecl) : Decl(DK, L, Id, PrevDecl), DeclType(T) {} public: QualType getType() const { return DeclType; } - QualType setType(QualType newType) { - QualType oldType = DeclType; - DeclType = newType; - return oldType; - } + void setType(QualType newType) { DeclType = newType; } QualType getCanonicalType() const { return DeclType.getCanonicalType(); } // Implement isa/cast/dyncast/etc. @@ -330,11 +326,7 @@ public: : TypeDecl(Typedef, L, Id, PrevDecl), UnderlyingType(T) {} QualType getUnderlyingType() const { return UnderlyingType; } - QualType setUnderlyingType(QualType newType) { - QualType oldType = UnderlyingType; - UnderlyingType = newType; - return oldType; - } + void setUnderlyingType(QualType newType) { UnderlyingType = newType; } // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return D->getKind() == Typedef; } -- GitLab