aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDeclAttr.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2012-05-11 00:36:07 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2012-05-11 00:36:07 +0000
commitbf9da1f8292bb66720ada94a050ede9dca17f60a (patch)
tree757f69354e83f6218807fe73995b622d07405946 /lib/Sema/SemaDeclAttr.cpp
parent7d9ae25d93554bdb238da83f9bb3e0b05475c16c (diff)
Fix a recent regression with the merging of format attributes.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156597 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDeclAttr.cpp')
-rw-r--r--lib/Sema/SemaDeclAttr.cpp47
1 files changed, 27 insertions, 20 deletions
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 9cd72b2e1e..93516501aa 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -2535,6 +2535,31 @@ static void handleInitPriorityAttr(Sema &S, Decl *D,
prioritynum));
}
+bool Sema::mergeFormatAttr(Decl *D, SourceRange Range, bool Inherited,
+ StringRef Format, int FormatIdx, int FirstArg) {
+ // 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() == FormatIdx &&
+ f->getFirstArg() == FirstArg) {
+ // If we don't have a valid location for this attribute, adopt the
+ // location.
+ if (f->getLocation().isInvalid())
+ f->setRange(Range);
+ return false;
+ }
+ }
+
+ FormatAttr *Attr = ::new (Context) FormatAttr(Range, Context, Format,
+ FormatIdx, FirstArg);
+ D->addAttr(Attr);
+ return true;
+}
+
/// Handle __attribute__((format(type,idx,firstarg))) attributes based on
/// http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
static void handleFormatAttr(Sema &S, Decl *D, const AttributeList &Attr) {
@@ -2670,26 +2695,8 @@ static void handleFormatAttr(Sema &S, Decl *D, const AttributeList &Attr) {
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->setRange(Attr.getRange());
- return;
- }
- }
-
- D->addAttr(::new (S.Context) FormatAttr(Attr.getRange(), S.Context, Format,
- Idx.getZExtValue(),
- FirstArg.getZExtValue()));
+ S.mergeFormatAttr(D, Attr.getRange(), false, Format, Idx.getZExtValue(),
+ FirstArg.getZExtValue());
}
static void handleTransparentUnionAttr(Sema &S, Decl *D,