From 88f5ed9430a99667261c24c6082aa4c0ccc4df83 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 13 Sep 2016 18:55:26 +0000 Subject: [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 --- clang/lib/Sema/SemaDeclAttr.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'clang/lib/Sema/SemaDeclAttr.cpp') 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()) { + if (UA->getGuid() == Uuid) + return nullptr; + Diag(UA->getLocation(), diag::err_mismatched_uuid); + Diag(Range.getBegin(), diag::note_previous_uuid); + D->dropAttr(); + } + + 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) { -- cgit v1.2.3