diff options
author | Nico Weber <nicolasweber@gmx.de> | 2016-09-13 18:55:26 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2016-09-13 18:55:26 +0000 |
commit | 88f5ed9430a99667261c24c6082aa4c0ccc4df83 (patch) | |
tree | 91df1209dd801e326f3b1758f61e459ab262a8e6 /clang/lib/Sema/SemaDeclAttr.cpp | |
parent | 39ccd24126fcb99e95f15e49278a88adece2319a (diff) | |
download | bcm5719-llvm-88f5ed9430a99667261c24c6082aa4c0ccc4df83.tar.gz bcm5719-llvm-88f5ed9430a99667261c24c6082aa4c0ccc4df83.zip |
[clang-cl] Diagnose duplicate uuids.
This mostly behaves cl.exe's behavior, even though clang-cl is stricter in some
corner cases and more lenient in others (see the included test).
To make the uuid declared previously here diagnostic work correctly, tweak
stripTypeAttributesOffDeclSpec() to keep attributes in the right order.
https://reviews.llvm.org/D24469
llvm-svn: 281367
Diffstat (limited to 'clang/lib/Sema/SemaDeclAttr.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 824d68e838e..c23db571415 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -4604,6 +4604,19 @@ static void handleObjCPreciseLifetimeAttr(Sema &S, Decl *D, // Microsoft specific attribute handlers. //===----------------------------------------------------------------------===// +UuidAttr *Sema::mergeUuidAttr(Decl *D, SourceRange Range, + unsigned AttrSpellingListIndex, StringRef Uuid) { + if (const auto *UA = D->getAttr<UuidAttr>()) { + if (UA->getGuid() == Uuid) + return nullptr; + Diag(UA->getLocation(), diag::err_mismatched_uuid); + Diag(Range.getBegin(), diag::note_previous_uuid); + D->dropAttr<UuidAttr>(); + } + + return ::new (Context) UuidAttr(Range, Context, Uuid, AttrSpellingListIndex); +} + static void handleUuidAttr(Sema &S, Decl *D, const AttributeList &Attr) { if (!S.LangOpts.CPlusPlus) { S.Diag(Attr.getLoc(), diag::err_attribute_not_supported_in_lang) @@ -4645,8 +4658,10 @@ static void handleUuidAttr(Sema &S, Decl *D, const AttributeList &Attr) { } } - D->addAttr(::new (S.Context) UuidAttr(Attr.getRange(), S.Context, StrRef, - Attr.getAttributeSpellingListIndex())); + UuidAttr *UA = S.mergeUuidAttr(D, Attr.getRange(), + Attr.getAttributeSpellingListIndex(), StrRef); + if (UA) + D->addAttr(UA); } static void handleMSInheritanceAttr(Sema &S, Decl *D, const AttributeList &Attr) { |