This is an archive of the discontinued LLVM Phabricator instance.

[clang-cl] Diagnose duplicate uuids.
ClosedPublic

Authored by thakis on Sep 12 2016, 1:34 PM.

Details

Reviewers
aaron.ballman
rnk
Summary

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.

Diff Detail

Event Timeline

thakis updated this revision to Diff 71048.Sep 12 2016, 1:34 PM
thakis updated this revision to Diff 71049.
thakis retitled this revision from to [clang-cl] Diagnose duplicate uuids..
thakis updated this object.
thakis added a reviewer: rnk.
thakis added subscribers: cfe-commits, aaron.ballman.

Remove local XXXs I've since addressed.

thakis updated this revision to Diff 71050.Sep 12 2016, 1:40 PM

On conflict, keep first uuid in ast instead of having different uuids on different redeclarations.

rnk accepted this revision.Sep 12 2016, 3:04 PM
rnk edited edge metadata.

lgtm

lib/Parse/ParseDecl.cpp
1456

mmm hand rolled singly linked list code. Feels like lisp.

This revision is now accepted and ready to land.Sep 12 2016, 3:04 PM
aaron.ballman added inline comments.Sep 12 2016, 3:10 PM
include/clang/Basic/DiagnosticSemaKinds.td
2258

uuid instead of uiid.

lib/Parse/ParseDecl.cpp
1476

Remove double space here.

lib/Sema/SemaDecl.cpp
2255

Thank you for the improved comments as a drive-by.

lib/Sema/SemaDeclAttr.cpp
4609

Can use const auto * here.

Also, don't you need to iterate over all of the UuidAttr objects attached to the declaration to see if any of them match, rather than just the first?

Does uuidof walk bases to find [uuid] in cl.exe? They walk bases for the declspec spelling.

thakis marked 2 inline comments as done.Sep 13 2016, 9:01 AM

Does uuidof walk bases to find [uuid] in cl.exe? They walk bases for the declspec spelling.

As far as I can tell, they don't for either:

C:\src\chrome\src>type atltest.cc
#include <guiddef.h>

class __declspec(uuid("86759049-8B8E-47F4-81F1-AE07D3F876C8")) Foo {};
class Bar : public Foo {};

[uuid("06759049-8B8E-47F4-81F1-AE07D3F876C7")] class Foo2 {};
class Bar2 : public Foo2 {};

void f() {

__uuidof(Bar);
__uuidof(Bar2);

}

C:\src\chrome\src>cl /c atltest.cc /nologo
atltest.cc
atltest.cc(6): warning C4467: usage of ATL attributes is deprecated
atltest.cc(10): error C2787: 'Bar': no GUID has been associated with this object
atltest.cc(11): error C2787: 'Bar2': no GUID has been associated with this object

lib/Parse/ParseDecl.cpp
1476

ack '\. ' lib

lib/Sema/SemaDeclAttr.cpp
4609

From what I understand, every time a new declaration is created, it copies attributes from the previous decl (see mergeDeclAttribute() in SemaDecl.cpp), so checking the latest should be enough. I added a test case for this.

thakis updated this revision to Diff 71181.Sep 13 2016, 9:01 AM
thakis edited edge metadata.

comments

aaron.ballman accepted this revision.Sep 13 2016, 11:20 AM
aaron.ballman added a reviewer: aaron.ballman.

LGTM!

lib/Sema/SemaDeclAttr.cpp
4609

I didn't pick up on the fact that there shouldn't be multiple UUID attributes associated with a single decl anyway. So this code is fine (with the auto nit fixed).

thakis closed this revision.Sep 13 2016, 12:04 PM

r281367, thanks!