diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-06-15 05:45:11 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-06-15 05:45:11 +0000 |
commit | b30cd4a09bbf0adfa644b957a2b28fe31c5d45e4 (patch) | |
tree | 2575b4040d2b99238b79026ea5598fd034e876cf /lib/Sema/SemaDeclAttr.cpp | |
parent | 210c05b10317a11971f87e474ffa4c30bb8e4df9 (diff) |
Don't add redundant FormatAttr, ConstAttr, or NoThrowAttr attributes,
either imlicitly (for builtins) or explicitly (due to multiple
specification of the same attributes). Fixes <rdar://problem/9612060>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133045 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDeclAttr.cpp')
-rw-r--r-- | lib/Sema/SemaDeclAttr.cpp | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 7f93ab72d6..1ec7199562 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -1525,8 +1525,13 @@ static void HandleNothrowAttr(Decl *d, const AttributeList &Attr, Sema &S) { S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0; return; } - - d->addAttr(::new (S.Context) NoThrowAttr(Attr.getLoc(), S.Context)); + + if (NoThrowAttr *Existing = d->getAttr<NoThrowAttr>()) { + if (Existing->getLocation().isInvalid()) + Existing->setLocation(Attr.getLoc()); + } else { + d->addAttr(::new (S.Context) NoThrowAttr(Attr.getLoc(), S.Context)); + } } static void HandleConstAttr(Decl *d, const AttributeList &Attr, Sema &S) { @@ -1536,7 +1541,12 @@ static void HandleConstAttr(Decl *d, const AttributeList &Attr, Sema &S) { return; } - d->addAttr(::new (S.Context) ConstAttr(Attr.getLoc(), S.Context)); + if (ConstAttr *Existing = d->getAttr<ConstAttr>()) { + if (Existing->getLocation().isInvalid()) + Existing->setLocation(Attr.getLoc()); + } else { + d->addAttr(::new (S.Context) ConstAttr(Attr.getLoc(), S.Context)); + } } static void HandlePureAttr(Decl *d, const AttributeList &Attr, Sema &S) { @@ -1904,6 +1914,23 @@ static void HandleFormatAttr(Decl *d, const AttributeList &Attr, Sema &S) { return; } + // Check whether we already have an equivalent format attribute. + for (specific_attr_iterator<FormatAttr> + i = d->specific_attr_begin<FormatAttr>(), + e = d->specific_attr_end<FormatAttr>(); + i != e ; ++i) { + FormatAttr *f = *i; + if (f->getType() == Format && + f->getFormatIdx() == (int)Idx.getZExtValue() && + f->getFirstArg() == (int)FirstArg.getZExtValue()) { + // If we don't have a valid location for this attribute, adopt the + // location. + if (f->getLocation().isInvalid()) + f->setLocation(Attr.getLoc()); + return; + } + } + d->addAttr(::new (S.Context) FormatAttr(Attr.getLoc(), S.Context, Format, Idx.getZExtValue(), FirstArg.getZExtValue())); |