[PATCH] D45406: Document -std= values for different languages

2018-04-07 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

Well, my idea was to list the standards one per line (like on GCC manpage), and 
then the '(deprecated)' comments would probably stand out enough to apply to a 
single line. Also, FWICS the gcc manpage simply lists which aliases are 
deprecated in the description text. But skipping them entirely also works for 
me.


Repository:
  rC Clang

https://reviews.llvm.org/D45406



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45392: [clang-tidy] add new check to find out objc ivars which do not have prefix '_'

2018-04-07 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added a comment.

In https://reviews.llvm.org/D45392#1060854, @Eugene.Zelenko wrote:

> In https://reviews.llvm.org/D45392#1060845, @Wizard wrote:
>
> > In https://reviews.llvm.org/D45392#1060485, @Eugene.Zelenko wrote:
> >
> > > If this is Apple guideline, check name should reflect this. I think will 
> > > be good idea to have general check for Apple naming conventions instead 
> > > of separate checks for specific situations like //objc-ivar-declaration// 
> > > and //objc-property-declaration//.
> >
> >
> > Thanks for the suggestion. I understand your point that they are both 
> > naming convention, however, they are about different components and using 
> > totally different naming rules. PropertyDeclarationCheck is already a very 
> > complicated check (the most complicated one for ObjC), I would rather not 
> > make it more heavy and try my best to split independent logic to different 
> > checks.
>
>
> See readability-identifier-naming 
> 
>  as example of multiple rules in one check.


I took a look at IdentifierNamingCheck. Here's my thought:

1. IdentifierNamingCheck is trying to apply configurable naming convention to 
C++ identifiers, and all the identifiers will share the same style set. That is 
not the case of ObjC, where we follow Apple's programming guide, and different 
types of identifiers are using different style.
2. Such pattern can handle complicated requirements but to me it is not simple 
enough to read and maintain. I would rather keep things simple and clear as 
long as we have choice.

However, this check provides a good example of refactoring if in the future we 
have the needs of organizing complicated naming styles. Moving from simplicity 
to complexity is always easier. Thanks for pointing this out for us.




Comment at: docs/ReleaseNotes.rst:60
 
+- New :doc:`objc-ivar-declaration
+  ` check

Eugene.Zelenko wrote:
> Wizard wrote:
> > Eugene.Zelenko wrote:
> > > Please place in new check list in alphabetical order.
> > I did not see a "new check list" in alphabetical order in this file. I 
> > believe they are ordered by commit time.If you mean the list.rst, they are 
> > already ordered alphabetically.
> Please read starting words in list of changes.
Hmm line 96 is "- New :doc:`fuchsia-multiple-inheritance 
` check", while line 101 is "- 
New :doc:`abseil-string-find-startswith 
` check". And similar thing 
happened to line 138. I thought it wasn't alphabetical. But that's probably 
mistakes from others. I will fix this one.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45392



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r329521 - [Sema] Fix PR35832 - Ambiguity accessing anonymous struct/union with multiple bases.

2018-04-07 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Sat Apr  7 23:21:33 2018
New Revision: 329521

URL: http://llvm.org/viewvc/llvm-project?rev=329521&view=rev
Log:
[Sema] Fix PR35832 - Ambiguity accessing anonymous struct/union with multiple 
bases.

Summary:
Currently clang doesn't do qualified lookup when building indirect field decl 
references. This causes ambiguity when the field is in a base class to which 
there are multiple valid paths  even though a qualified name is used.

For example:
```
class B {
protected:
 int i;
 union { int j; };
};

class X : public B { };
class Y : public B { };

class Z : public X, public Y {
 int a() { return X::i; } // works
 int b() { return X::j; } // fails
};
```

Reviewers: rsmith, aaron.ballman, rjmccall

Reviewed By: rjmccall

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D45411

Added:
cfe/trunk/test/SemaCXX/PR35832.cpp
Modified:
cfe/trunk/lib/Sema/SemaExprMember.cpp
cfe/trunk/lib/Sema/TreeTransform.h

Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=329521&r1=329520&r2=329521&view=diff
==
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Sat Apr  7 23:21:33 2018
@@ -848,7 +848,7 @@ Sema::BuildAnonymousStructUnionMemberRef
 // Build the first member access in the chain with full information.
 result =
 BuildFieldReferenceExpr(result, baseObjectIsPointer, SourceLocation(),
-EmptySS, field, foundDecl, memberNameInfo)
+SS, field, foundDecl, memberNameInfo)
 .get();
 if (!result)
   return ExprError();

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=329521&r1=329520&r2=329521&view=diff
==
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Sat Apr  7 23:21:33 2018
@@ -2239,7 +2239,6 @@ public:
   // We have a reference to an unnamed field.  This is always the
   // base of an anonymous struct/union member access, i.e. the
   // field is always of record type.
-  assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
   assert(Member->getType()->isRecordType() &&
  "unnamed member not of record type?");
 

Added: cfe/trunk/test/SemaCXX/PR35832.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR35832.cpp?rev=329521&view=auto
==
--- cfe/trunk/test/SemaCXX/PR35832.cpp (added)
+++ cfe/trunk/test/SemaCXX/PR35832.cpp Sat Apr  7 23:21:33 2018
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+class B {
+public:
+ int i;
+ struct {  struct { union { int j; }; };  };
+ union { int k; };
+};
+
+class X : public B { };
+class Y : public B { };
+
+class Z : public X, public Y {
+public:
+ int a() { return X::i; }
+ int b() { return X::j; }
+ int c() { return X::k; }
+ int d() { return this->X::j; }
+};


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45411: [Sema] Fix PR35832 - Ambiguity accessing anonymous struct/union with multiple bases.

2018-04-07 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 141527.
EricWF added a comment.

I missed a test failure. Reuploading and recommiting latest diff to keep the 
history.


https://reviews.llvm.org/D45411

Files:
  lib/Sema/SemaExprMember.cpp
  lib/Sema/TreeTransform.h
  test/SemaCXX/PR35832.cpp


Index: test/SemaCXX/PR35832.cpp
===
--- /dev/null
+++ test/SemaCXX/PR35832.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+class B {
+public:
+ int i;
+ struct {  struct { union { int j; }; };  };
+ union { int k; };
+};
+
+class X : public B { };
+class Y : public B { };
+
+class Z : public X, public Y {
+public:
+ int a() { return X::i; }
+ int b() { return X::j; }
+ int c() { return X::k; }
+ int d() { return this->X::j; }
+};
Index: lib/Sema/TreeTransform.h
===
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -2239,7 +2239,6 @@
   // We have a reference to an unnamed field.  This is always the
   // base of an anonymous struct/union member access, i.e. the
   // field is always of record type.
-  assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
   assert(Member->getType()->isRecordType() &&
  "unnamed member not of record type?");
 
Index: lib/Sema/SemaExprMember.cpp
===
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -848,7 +848,7 @@
 // Build the first member access in the chain with full information.
 result =
 BuildFieldReferenceExpr(result, baseObjectIsPointer, SourceLocation(),
-EmptySS, field, foundDecl, memberNameInfo)
+SS, field, foundDecl, memberNameInfo)
 .get();
 if (!result)
   return ExprError();


Index: test/SemaCXX/PR35832.cpp
===
--- /dev/null
+++ test/SemaCXX/PR35832.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+class B {
+public:
+ int i;
+ struct {  struct { union { int j; }; };  };
+ union { int k; };
+};
+
+class X : public B { };
+class Y : public B { };
+
+class Z : public X, public Y {
+public:
+ int a() { return X::i; }
+ int b() { return X::j; }
+ int c() { return X::k; }
+ int d() { return this->X::j; }
+};
Index: lib/Sema/TreeTransform.h
===
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -2239,7 +2239,6 @@
   // We have a reference to an unnamed field.  This is always the
   // base of an anonymous struct/union member access, i.e. the
   // field is always of record type.
-  assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
   assert(Member->getType()->isRecordType() &&
  "unnamed member not of record type?");
 
Index: lib/Sema/SemaExprMember.cpp
===
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -848,7 +848,7 @@
 // Build the first member access in the chain with full information.
 result =
 BuildFieldReferenceExpr(result, baseObjectIsPointer, SourceLocation(),
-EmptySS, field, foundDecl, memberNameInfo)
+SS, field, foundDecl, memberNameInfo)
 .get();
 if (!result)
   return ExprError();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r329520 - Revert "[Sema] Fix PR35832 - Ambiguity accessing anonymous struct/union with multiple bases."

2018-04-07 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Sat Apr  7 23:05:33 2018
New Revision: 329520

URL: http://llvm.org/viewvc/llvm-project?rev=329520&view=rev
Log:
Revert "[Sema] Fix PR35832 - Ambiguity accessing anonymous struct/union with 
multiple bases."

This reverts commit r329519. There are some unaddressed test failures.

Removed:
cfe/trunk/test/SemaCXX/PR35832.cpp
Modified:
cfe/trunk/lib/Sema/SemaExprMember.cpp

Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=329520&r1=329519&r2=329520&view=diff
==
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Sat Apr  7 23:05:33 2018
@@ -848,7 +848,7 @@ Sema::BuildAnonymousStructUnionMemberRef
 // Build the first member access in the chain with full information.
 result =
 BuildFieldReferenceExpr(result, baseObjectIsPointer, SourceLocation(),
-SS, field, foundDecl, memberNameInfo)
+EmptySS, field, foundDecl, memberNameInfo)
 .get();
 if (!result)
   return ExprError();

Removed: cfe/trunk/test/SemaCXX/PR35832.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR35832.cpp?rev=329519&view=auto
==
--- cfe/trunk/test/SemaCXX/PR35832.cpp (original)
+++ cfe/trunk/test/SemaCXX/PR35832.cpp (removed)
@@ -1,19 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
-
-// expected-no-diagnostics
-
-class B {
-public:
- int i;
- struct {  struct { union { int j; }; };  };
-};
-
-class X : public B { };
-class Y : public B { };
-
-class Z : public X, Y {
-public:
- int a() { return X::i; }
- int b() { return X::j; }
- int c() { return this->X::j; }
-};


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45411: [Sema] Fix PR35832 - Ambiguity accessing anonymous struct/union with multiple bases.

2018-04-07 Thread Eric Fiselier via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC329519: [Sema] Fix PR35832 - Ambiguity accessing anonymous 
struct/union with multiple… (authored by EricWF, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D45411

Files:
  lib/Sema/SemaExprMember.cpp
  test/SemaCXX/PR35832.cpp


Index: test/SemaCXX/PR35832.cpp
===
--- test/SemaCXX/PR35832.cpp
+++ test/SemaCXX/PR35832.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+class B {
+public:
+ int i;
+ struct {  struct { union { int j; }; };  };
+};
+
+class X : public B { };
+class Y : public B { };
+
+class Z : public X, Y {
+public:
+ int a() { return X::i; }
+ int b() { return X::j; }
+ int c() { return this->X::j; }
+};
Index: lib/Sema/SemaExprMember.cpp
===
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -848,7 +848,7 @@
 // Build the first member access in the chain with full information.
 result =
 BuildFieldReferenceExpr(result, baseObjectIsPointer, SourceLocation(),
-EmptySS, field, foundDecl, memberNameInfo)
+SS, field, foundDecl, memberNameInfo)
 .get();
 if (!result)
   return ExprError();


Index: test/SemaCXX/PR35832.cpp
===
--- test/SemaCXX/PR35832.cpp
+++ test/SemaCXX/PR35832.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+class B {
+public:
+ int i;
+ struct {  struct { union { int j; }; };  };
+};
+
+class X : public B { };
+class Y : public B { };
+
+class Z : public X, Y {
+public:
+ int a() { return X::i; }
+ int b() { return X::j; }
+ int c() { return this->X::j; }
+};
Index: lib/Sema/SemaExprMember.cpp
===
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -848,7 +848,7 @@
 // Build the first member access in the chain with full information.
 result =
 BuildFieldReferenceExpr(result, baseObjectIsPointer, SourceLocation(),
-EmptySS, field, foundDecl, memberNameInfo)
+SS, field, foundDecl, memberNameInfo)
 .get();
 if (!result)
   return ExprError();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r329519 - [Sema] Fix PR35832 - Ambiguity accessing anonymous struct/union with multiple bases.

2018-04-07 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Sat Apr  7 22:50:01 2018
New Revision: 329519

URL: http://llvm.org/viewvc/llvm-project?rev=329519&view=rev
Log:
[Sema] Fix PR35832 - Ambiguity accessing anonymous struct/union with multiple 
bases.

Summary:
Currently clang doesn't do qualified lookup when building indirect field decl 
references. This causes ambiguity when the field is in a base class to which 
there are multiple valid paths  even though a qualified name is used.

For example:
```
class B {
protected:
 int i;
 union { int j; };
};

class X : public B { };
class Y : public B { };

class Z : public X, public Y {
 int a() { return X::i; } // works
 int b() { return X::j; } // fails
};
```

Reviewers: rsmith, aaron.ballman, rjmccall

Reviewed By: rjmccall

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D45411

Added:
cfe/trunk/test/SemaCXX/PR35832.cpp
Modified:
cfe/trunk/lib/Sema/SemaExprMember.cpp

Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=329519&r1=329518&r2=329519&view=diff
==
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Sat Apr  7 22:50:01 2018
@@ -848,7 +848,7 @@ Sema::BuildAnonymousStructUnionMemberRef
 // Build the first member access in the chain with full information.
 result =
 BuildFieldReferenceExpr(result, baseObjectIsPointer, SourceLocation(),
-EmptySS, field, foundDecl, memberNameInfo)
+SS, field, foundDecl, memberNameInfo)
 .get();
 if (!result)
   return ExprError();

Added: cfe/trunk/test/SemaCXX/PR35832.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR35832.cpp?rev=329519&view=auto
==
--- cfe/trunk/test/SemaCXX/PR35832.cpp (added)
+++ cfe/trunk/test/SemaCXX/PR35832.cpp Sat Apr  7 22:50:01 2018
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+class B {
+public:
+ int i;
+ struct {  struct { union { int j; }; };  };
+};
+
+class X : public B { };
+class Y : public B { };
+
+class Z : public X, Y {
+public:
+ int a() { return X::i; }
+ int b() { return X::j; }
+ int c() { return this->X::j; }
+};


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45410: [Sema] Remove dead code in BuildAnonymousStructUnionMemberReference. NFCI

2018-04-07 Thread Eric Fiselier via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL329518: [Sema] Remove dead code in 
BuildAnonymousStructUnionMemberReference. NFCI (authored by EricWF, committed 
by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D45410?vs=141516&id=141524#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45410

Files:
  cfe/trunk/lib/Sema/SemaExprMember.cpp

Index: cfe/trunk/lib/Sema/SemaExprMember.cpp
===
--- cfe/trunk/lib/Sema/SemaExprMember.cpp
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp
@@ -802,16 +802,13 @@
Expr *baseObjectExpr,
SourceLocation opLoc) {
   // First, build the expression that refers to the base object.
-  
-  bool baseObjectIsPointer = false;
-  Qualifiers baseQuals;
-  
+
   // Case 1:  the base of the indirect field is not a field.
   VarDecl *baseVariable = indirectField->getVarDecl();
   CXXScopeSpec EmptySS;
   if (baseVariable) {
 assert(baseVariable->getType()->isRecordType());
-
+
 // In principle we could have a member access expression that
 // accesses an anonymous struct/union that's a static member of
 // the base object's class.  However, under the current standard,
@@ -824,68 +821,37 @@
 ExprResult result 
   = BuildDeclarationNameExpr(EmptySS, baseNameInfo, baseVariable);
 if (result.isInvalid()) return ExprError();
-
-baseObjectExpr = result.get();
-baseObjectIsPointer = false;
-baseQuals = baseObjectExpr->getType().getQualifiers();
-
-// Case 2: the base of the indirect field is a field and the user
-// wrote a member expression.
-  } else if (baseObjectExpr) {
-// The caller provided the base object expression. Determine
-// whether its a pointer and whether it adds any qualifiers to the
-// anonymous struct/union fields we're looking into.
-QualType objectType = baseObjectExpr->getType();
-
-if (const PointerType *ptr = objectType->getAs()) {
-  baseObjectIsPointer = true;
-  objectType = ptr->getPointeeType();
-} else {
-  baseObjectIsPointer = false;
-}
-baseQuals = objectType.getQualifiers();
-
-// Case 3: the base of the indirect field is a field and we should
-// build an implicit member access.
-  } else {
-// We've found a member of an anonymous struct/union that is
-// inside a non-anonymous struct/union, so in a well-formed
-// program our base object expression is "this".
-QualType ThisTy = getCurrentThisType();
-if (ThisTy.isNull()) {
-  Diag(loc, diag::err_invalid_member_use_in_static_method)
-<< indirectField->getDeclName();
-  return ExprError();
-}
-
-// Our base object expression is "this".
-CheckCXXThisCapture(loc);
-baseObjectExpr 
-  = new (Context) CXXThisExpr(loc, ThisTy, /*isImplicit=*/ true);
-baseObjectIsPointer = true;
-baseQuals = ThisTy->castAs()->getPointeeType().getQualifiers();
+
+baseObjectExpr = result.get();
   }
-  
+
+  assert((baseVariable || baseObjectExpr) &&
+ "referencing anonymous struct/union without a base variable or "
+ "expression");
+
   // Build the implicit member references to the field of the
   // anonymous struct/union.
   Expr *result = baseObjectExpr;
   IndirectFieldDecl::chain_iterator
   FI = indirectField->chain_begin(), FEnd = indirectField->chain_end();
-  
-  // Build the first member access in the chain with full information.
+
+  // Case 2: the base of the indirect field is a field and the user
+  // wrote a member expression.
   if (!baseVariable) {
 FieldDecl *field = cast(*FI);
-
+
+bool baseObjectIsPointer = baseObjectExpr->getType()->isPointerType();
+
 // Make a nameInfo that properly uses the anonymous name.
 DeclarationNameInfo memberNameInfo(field->getDeclName(), loc);
 
-result = BuildFieldReferenceExpr(result, baseObjectIsPointer,
- SourceLocation(), EmptySS, field,
- foundDecl, memberNameInfo).get();
+// Build the first member access in the chain with full information.
+result =
+BuildFieldReferenceExpr(result, baseObjectIsPointer, SourceLocation(),
+EmptySS, field, foundDecl, memberNameInfo)
+.get();
 if (!result)
   return ExprError();
-
-// FIXME: check qualified member access
   }
   
   // In all cases, we should now skip the first declaration in the chain.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45412: [Sema] Fix PR22637 - IndirectFieldDecl's discard qualifiers during template instantiation.

2018-04-07 Thread Eric Fiselier via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC329517: [Sema] Fix PR22637 - IndirectFieldDecl's 
discard qualifiers during template… (authored by EricWF, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D45412?vs=141520&id=141523#toc

Repository:
  rC Clang

https://reviews.llvm.org/D45412

Files:
  lib/Sema/TreeTransform.h
  test/SemaCXX/PR22637.cpp
  test/SemaCXX/cxx0x-nontrivial-union.cpp


Index: lib/Sema/TreeTransform.h
===
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -2250,11 +2250,11 @@
   if (BaseResult.isInvalid())
 return ExprError();
   Base = BaseResult.get();
-  ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
-  MemberExpr *ME = new (getSema().Context)
-  MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
- cast(Member)->getType(), VK, OK_Ordinary);
-  return ME;
+
+  CXXScopeSpec EmptySS;
+  return getSema().BuildFieldReferenceExpr(
+  Base, isArrow, OpLoc, EmptySS, cast(Member),
+  DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), 
MemberNameInfo);
 }
 
 CXXScopeSpec SS;
Index: test/SemaCXX/PR22637.cpp
===
--- test/SemaCXX/PR22637.cpp
+++ test/SemaCXX/PR22637.cpp
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+void check(int&) = delete;
+void check(int const&) { }
+
+template 
+struct A {
+union {
+int b;
+};
+struct {
+  int c;
+};
+union {
+  struct {
+union {
+  struct {
+struct {
+  int d;
+};
+  };
+};
+  };
+};
+int e;
+void foo() const {
+  check(b);
+  check(c);
+  check(d);
+  check(d);
+  check(e);
+}
+};
+
+int main(){
+A a;
+a.foo();
+}
Index: test/SemaCXX/cxx0x-nontrivial-union.cpp
===
--- test/SemaCXX/cxx0x-nontrivial-union.cpp
+++ test/SemaCXX/cxx0x-nontrivial-union.cpp
@@ -110,7 +110,7 @@
 }
 
 explicit operator bool() const { return has; }
-T &operator*() const { return value; }
+T &operator*() { return value; }
   };
 
   optional o1;


Index: lib/Sema/TreeTransform.h
===
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -2250,11 +2250,11 @@
   if (BaseResult.isInvalid())
 return ExprError();
   Base = BaseResult.get();
-  ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
-  MemberExpr *ME = new (getSema().Context)
-  MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
- cast(Member)->getType(), VK, OK_Ordinary);
-  return ME;
+
+  CXXScopeSpec EmptySS;
+  return getSema().BuildFieldReferenceExpr(
+  Base, isArrow, OpLoc, EmptySS, cast(Member),
+  DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo);
 }
 
 CXXScopeSpec SS;
Index: test/SemaCXX/PR22637.cpp
===
--- test/SemaCXX/PR22637.cpp
+++ test/SemaCXX/PR22637.cpp
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+void check(int&) = delete;
+void check(int const&) { }
+
+template 
+struct A {
+union {
+int b;
+};
+struct {
+  int c;
+};
+union {
+  struct {
+union {
+  struct {
+struct {
+  int d;
+};
+  };
+};
+  };
+};
+int e;
+void foo() const {
+  check(b);
+  check(c);
+  check(d);
+  check(d);
+  check(e);
+}
+};
+
+int main(){
+A a;
+a.foo();
+}
Index: test/SemaCXX/cxx0x-nontrivial-union.cpp
===
--- test/SemaCXX/cxx0x-nontrivial-union.cpp
+++ test/SemaCXX/cxx0x-nontrivial-union.cpp
@@ -110,7 +110,7 @@
 }
 
 explicit operator bool() const { return has; }
-T &operator*() const { return value; }
+T &operator*() { return value; }
   };
 
   optional o1;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r329518 - [Sema] Remove dead code in BuildAnonymousStructUnionMemberReference. NFCI

2018-04-07 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Sat Apr  7 22:12:55 2018
New Revision: 329518

URL: http://llvm.org/viewvc/llvm-project?rev=329518&view=rev
Log:
[Sema] Remove dead code in BuildAnonymousStructUnionMemberReference. NFCI

Summary:
This patch cleans up a bunch of dead or unused code in 
BuildAnonymousStructUnionMemberReference.

The dead code was a branch that built a new CXXThisExpr when we weren't given a 
base object expression or base variable.
However, BuildAnonymousFoo has only two callers. One of which always builds a 
base object expression first, the second only calls when the IndirectFieldDecl 
is not a C++ class member. Even within C this branch seems entirely unused.

I tried diligently to write a test which hit it with no success. 

This patch removes the branch and replaces it with an assertion that we were 
given either a base object expression or a base variable.


Reviewers: rsmith, aaron.ballman, majnemer, rjmccall

Reviewed By: rjmccall

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D45410

Modified:
cfe/trunk/lib/Sema/SemaExprMember.cpp

Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=329518&r1=329517&r2=329518&view=diff
==
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Sat Apr  7 22:12:55 2018
@@ -802,16 +802,13 @@ Sema::BuildAnonymousStructUnionMemberRef
Expr *baseObjectExpr,
SourceLocation opLoc) {
   // First, build the expression that refers to the base object.
-  
-  bool baseObjectIsPointer = false;
-  Qualifiers baseQuals;
-  
+
   // Case 1:  the base of the indirect field is not a field.
   VarDecl *baseVariable = indirectField->getVarDecl();
   CXXScopeSpec EmptySS;
   if (baseVariable) {
 assert(baseVariable->getType()->isRecordType());
-
+
 // In principle we could have a member access expression that
 // accesses an anonymous struct/union that's a static member of
 // the base object's class.  However, under the current standard,
@@ -824,68 +821,37 @@ Sema::BuildAnonymousStructUnionMemberRef
 ExprResult result 
   = BuildDeclarationNameExpr(EmptySS, baseNameInfo, baseVariable);
 if (result.isInvalid()) return ExprError();
-
-baseObjectExpr = result.get();
-baseObjectIsPointer = false;
-baseQuals = baseObjectExpr->getType().getQualifiers();
-
-// Case 2: the base of the indirect field is a field and the user
-// wrote a member expression.
-  } else if (baseObjectExpr) {
-// The caller provided the base object expression. Determine
-// whether its a pointer and whether it adds any qualifiers to the
-// anonymous struct/union fields we're looking into.
-QualType objectType = baseObjectExpr->getType();
-
-if (const PointerType *ptr = objectType->getAs()) {
-  baseObjectIsPointer = true;
-  objectType = ptr->getPointeeType();
-} else {
-  baseObjectIsPointer = false;
-}
-baseQuals = objectType.getQualifiers();
-
-// Case 3: the base of the indirect field is a field and we should
-// build an implicit member access.
-  } else {
-// We've found a member of an anonymous struct/union that is
-// inside a non-anonymous struct/union, so in a well-formed
-// program our base object expression is "this".
-QualType ThisTy = getCurrentThisType();
-if (ThisTy.isNull()) {
-  Diag(loc, diag::err_invalid_member_use_in_static_method)
-<< indirectField->getDeclName();
-  return ExprError();
-}
-
-// Our base object expression is "this".
-CheckCXXThisCapture(loc);
-baseObjectExpr 
-  = new (Context) CXXThisExpr(loc, ThisTy, /*isImplicit=*/ true);
-baseObjectIsPointer = true;
-baseQuals = 
ThisTy->castAs()->getPointeeType().getQualifiers();
+
+baseObjectExpr = result.get();
   }
-  
+
+  assert((baseVariable || baseObjectExpr) &&
+ "referencing anonymous struct/union without a base variable or "
+ "expression");
+
   // Build the implicit member references to the field of the
   // anonymous struct/union.
   Expr *result = baseObjectExpr;
   IndirectFieldDecl::chain_iterator
   FI = indirectField->chain_begin(), FEnd = indirectField->chain_end();
-  
-  // Build the first member access in the chain with full information.
+
+  // Case 2: the base of the indirect field is a field and the user
+  // wrote a member expression.
   if (!baseVariable) {
 FieldDecl *field = cast(*FI);
-
+
+bool baseObjectIsPointer = baseObjectExpr->getType()->isPointerType();
+
 // Make a nameInfo that properly uses the anonymous name.
 DeclarationNameInfo memberNameInfo(field->getDeclName(), loc);
 
-result = BuildFieldReferenceExpr(result, baseObjectIsPointer,
- 

r329517 - [Sema] Fix PR22637 - IndirectFieldDecl's discard qualifiers during template instantiation.

2018-04-07 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Sat Apr  7 22:11:59 2018
New Revision: 329517

URL: http://llvm.org/viewvc/llvm-project?rev=329517&view=rev
Log:
[Sema] Fix PR22637 - IndirectFieldDecl's discard qualifiers during template 
instantiation.

Summary:
Currently Clang fails to propagate qualifiers from the `CXXThisExpr` to the 
rebuilt `FieldDecl` for IndirectFieldDecls. For example:

```
template  struct Foo {
  struct { int x; };
  int y;
  void foo() const { 
  static_assert(__is_same(int const&, decltype((y;
  static_assert(__is_same(int const&, decltype((x; // assertion fails
  }
};
template struct Foo;
```

The fix is to delegate rebuilding of the MemberExpr to 
`BuildFieldReferenceExpr` which correctly propagates the qualifiers.

Reviewers: rsmith, lebedev.ri, aaron.ballman, bkramer, rjmccall

Reviewed By: rjmccall

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D45412

Added:
cfe/trunk/test/SemaCXX/PR22637.cpp
Modified:
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/SemaCXX/cxx0x-nontrivial-union.cpp

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=329517&r1=329516&r2=329517&view=diff
==
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Sat Apr  7 22:11:59 2018
@@ -2250,11 +2250,11 @@ public:
   if (BaseResult.isInvalid())
 return ExprError();
   Base = BaseResult.get();
-  ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
-  MemberExpr *ME = new (getSema().Context)
-  MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
- cast(Member)->getType(), VK, OK_Ordinary);
-  return ME;
+
+  CXXScopeSpec EmptySS;
+  return getSema().BuildFieldReferenceExpr(
+  Base, isArrow, OpLoc, EmptySS, cast(Member),
+  DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), 
MemberNameInfo);
 }
 
 CXXScopeSpec SS;

Added: cfe/trunk/test/SemaCXX/PR22637.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR22637.cpp?rev=329517&view=auto
==
--- cfe/trunk/test/SemaCXX/PR22637.cpp (added)
+++ cfe/trunk/test/SemaCXX/PR22637.cpp Sat Apr  7 22:11:59 2018
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+void check(int&) = delete;
+void check(int const&) { }
+
+template 
+struct A {
+union {
+int b;
+};
+struct {
+  int c;
+};
+union {
+  struct {
+union {
+  struct {
+struct {
+  int d;
+};
+  };
+};
+  };
+};
+int e;
+void foo() const {
+  check(b);
+  check(c);
+  check(d);
+  check(d);
+  check(e);
+}
+};
+
+int main(){
+A a;
+a.foo();
+}

Modified: cfe/trunk/test/SemaCXX/cxx0x-nontrivial-union.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-nontrivial-union.cpp?rev=329517&r1=329516&r2=329517&view=diff
==
--- cfe/trunk/test/SemaCXX/cxx0x-nontrivial-union.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx0x-nontrivial-union.cpp Sat Apr  7 22:11:59 2018
@@ -110,7 +110,7 @@ namespace optional {
 }
 
 explicit operator bool() const { return has; }
-T &operator*() const { return value; }
+T &operator*() { return value; }
   };
 
   optional o1;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45410: [Sema] Remove dead code in BuildAnonymousStructUnionMemberReference. NFCI

2018-04-07 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

I think there was a point when we weren't always creating CXXThisExprs eagerly 
for these accesses.  Now that we are, yeah, this should be dead.


Repository:
  rC Clang

https://reviews.llvm.org/D45410



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45412: [Sema] Fix PR22637 - IndirectFieldDecl's discard qualifiers during template instantiation.

2018-04-07 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Okay, LGTM.


Repository:
  rC Clang

https://reviews.llvm.org/D45412



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45411: [Sema] Fix PR35832 - Ambiguity accessing anonymous struct/union with multiple bases.

2018-04-07 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Well, that is a really silly bug.  Fix LGTM.


https://reviews.llvm.org/D45411



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45411: [Sema] Fix PR35832 - Ambiguity accessing anonymous struct/union with multiple bases.

2018-04-07 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 141522.
EricWF added a comment.

- Upload with correct test.


https://reviews.llvm.org/D45411

Files:
  lib/Sema/SemaExprMember.cpp
  test/SemaCXX/PR35832.cpp


Index: test/SemaCXX/PR35832.cpp
===
--- /dev/null
+++ test/SemaCXX/PR35832.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+class B {
+public:
+ int i;
+ struct {  struct { union { int j; }; };  };
+};
+
+class X : public B { };
+class Y : public B { };
+
+class Z : public X, Y {
+public:
+ int a() { return X::i; }
+ int b() { return X::j; }
+ int c() { return this->X::j; }
+};
Index: lib/Sema/SemaExprMember.cpp
===
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -848,7 +848,7 @@
 // Build the first member access in the chain with full information.
 result =
 BuildFieldReferenceExpr(result, baseObjectIsPointer, SourceLocation(),
-EmptySS, field, foundDecl, memberNameInfo)
+SS, field, foundDecl, memberNameInfo)
 .get();
 if (!result)
   return ExprError();


Index: test/SemaCXX/PR35832.cpp
===
--- /dev/null
+++ test/SemaCXX/PR35832.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+class B {
+public:
+ int i;
+ struct {  struct { union { int j; }; };  };
+};
+
+class X : public B { };
+class Y : public B { };
+
+class Z : public X, Y {
+public:
+ int a() { return X::i; }
+ int b() { return X::j; }
+ int c() { return this->X::j; }
+};
Index: lib/Sema/SemaExprMember.cpp
===
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -848,7 +848,7 @@
 // Build the first member access in the chain with full information.
 result =
 BuildFieldReferenceExpr(result, baseObjectIsPointer, SourceLocation(),
-EmptySS, field, foundDecl, memberNameInfo)
+SS, field, foundDecl, memberNameInfo)
 .get();
 if (!result)
   return ExprError();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45412: [Sema] Fix PR22637 - IndirectFieldDecl's discard qualifiers during template instantiation.

2018-04-07 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF created this revision.
EricWF added reviewers: rsmith, lebedev.ri, aaron.ballman, bkramer, rjmccall.

Currently Clang fails to propagate qualifiers from the `CXXThisExpr` to the 
rebuilt `FieldDecl` for IndirectFieldDecls. For example:

  template  struct Foo {
struct { int x; };
int y;
void foo() const { 
static_assert(__is_same(int const&, decltype((y;
static_assert(__is_same(int const&, decltype((x; // assertion fails
}
  };
  template struct Foo;

The fix is to delegate rebuilding of the MemberExpr to 
`BuildFieldReferenceExpr` which correctly propagates the qualifiers.


Repository:
  rC Clang

https://reviews.llvm.org/D45412

Files:
  lib/Sema/TreeTransform.h
  test/SemaCXX/PR22637.cpp
  test/SemaCXX/cxx0x-nontrivial-union.cpp


Index: test/SemaCXX/cxx0x-nontrivial-union.cpp
===
--- test/SemaCXX/cxx0x-nontrivial-union.cpp
+++ test/SemaCXX/cxx0x-nontrivial-union.cpp
@@ -110,7 +110,7 @@
 }
 
 explicit operator bool() const { return has; }
-T &operator*() const { return value; }
+T &operator*() { return value; }
   };
 
   optional o1;
Index: test/SemaCXX/PR22637.cpp
===
--- /dev/null
+++ test/SemaCXX/PR22637.cpp
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+void check(int&) = delete;
+void check(int const&) { }
+
+template 
+struct A {
+union {
+int b;
+};
+struct {
+  int c;
+};
+union {
+  struct {
+union {
+  struct {
+struct {
+  int d;
+};
+  };
+};
+  };
+};
+int e;
+void foo() const {
+  check(b);
+  check(c);
+  check(d);
+  check(d);
+  check(e);
+}
+};
+
+int main(){
+A a;
+a.foo();
+}
Index: lib/Sema/TreeTransform.h
===
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -2249,12 +2249,11 @@
 FoundDecl, Member);
   if (BaseResult.isInvalid())
 return ExprError();
-  Base = BaseResult.get();
-  ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
-  MemberExpr *ME = new (getSema().Context)
-  MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
- cast(Member)->getType(), VK, OK_Ordinary);
-  return ME;
+
+  CXXScopeSpec EmptySS;
+  return getSema().BuildFieldReferenceExpr(
+  Base, isArrow, OpLoc, EmptySS, cast(Member),
+  DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), 
MemberNameInfo);
 }
 
 CXXScopeSpec SS;


Index: test/SemaCXX/cxx0x-nontrivial-union.cpp
===
--- test/SemaCXX/cxx0x-nontrivial-union.cpp
+++ test/SemaCXX/cxx0x-nontrivial-union.cpp
@@ -110,7 +110,7 @@
 }
 
 explicit operator bool() const { return has; }
-T &operator*() const { return value; }
+T &operator*() { return value; }
   };
 
   optional o1;
Index: test/SemaCXX/PR22637.cpp
===
--- /dev/null
+++ test/SemaCXX/PR22637.cpp
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+void check(int&) = delete;
+void check(int const&) { }
+
+template 
+struct A {
+union {
+int b;
+};
+struct {
+  int c;
+};
+union {
+  struct {
+union {
+  struct {
+struct {
+  int d;
+};
+  };
+};
+  };
+};
+int e;
+void foo() const {
+  check(b);
+  check(c);
+  check(d);
+  check(d);
+  check(e);
+}
+};
+
+int main(){
+A a;
+a.foo();
+}
Index: lib/Sema/TreeTransform.h
===
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -2249,12 +2249,11 @@
 FoundDecl, Member);
   if (BaseResult.isInvalid())
 return ExprError();
-  Base = BaseResult.get();
-  ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
-  MemberExpr *ME = new (getSema().Context)
-  MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
- cast(Member)->getType(), VK, OK_Ordinary);
-  return ME;
+
+  CXXScopeSpec EmptySS;
+  return getSema().BuildFieldReferenceExpr(
+  Base, isArrow, OpLoc, EmptySS, cast(Member),
+  DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo);
 }
 
 CXXScopeSpec SS;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45411: [Sema] Fix PR35832 - Ambiguity accessing anonymous struct/union with multiple bases.

2018-04-07 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF created this revision.
EricWF added reviewers: rsmith, aaron.ballman, rjmccall.
EricWF added a dependency: D45410: [Sema] Remove dead code in 
BuildAnonymousStructUnionMemberReference. NFCI.

Currently clang doesn't do qualified lookup when building indirect field decl 
references. This causes ambiguity when the field is in a base class to which 
there are multiple valid paths  even though a qualified name is used.

For example:

  class B {
  protected:
   int i;
   union { int j; };
  };
  
  class X : public B { };
  class Y : public B { };
  
  class Z : public X, public Y {
   int a() { return X::i; } // works
   int b() { return X::j; } // fails
  };


Repository:
  rC Clang

https://reviews.llvm.org/D45411

Files:
  lib/Sema/SemaExprMember.cpp
  test/SemaCXX/PR35832.cpp


Index: test/SemaCXX/PR35832.cpp
===
--- /dev/null
+++ test/SemaCXX/PR35832.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+class B {
+public:
+ int i;
+ struct {  struct { union { int j; }; };  };
+};
+
+auto ptr = &B::j;
+
+class X : public B { };
+class Y : public B { static B bb; };
+
+class Z : public X {
+public:
+ int a() { return X::i; }
+ int b() { return X::j; }
+ int c() { return this->X::j; }
+};
Index: lib/Sema/SemaExprMember.cpp
===
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -848,7 +848,7 @@
 // Build the first member access in the chain with full information.
 result =
 BuildFieldReferenceExpr(result, baseObjectIsPointer, SourceLocation(),
-EmptySS, field, foundDecl, memberNameInfo)
+SS, field, foundDecl, memberNameInfo)
 .get();
 if (!result)
   return ExprError();


Index: test/SemaCXX/PR35832.cpp
===
--- /dev/null
+++ test/SemaCXX/PR35832.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+class B {
+public:
+ int i;
+ struct {  struct { union { int j; }; };  };
+};
+
+auto ptr = &B::j;
+
+class X : public B { };
+class Y : public B { static B bb; };
+
+class Z : public X {
+public:
+ int a() { return X::i; }
+ int b() { return X::j; }
+ int c() { return this->X::j; }
+};
Index: lib/Sema/SemaExprMember.cpp
===
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -848,7 +848,7 @@
 // Build the first member access in the chain with full information.
 result =
 BuildFieldReferenceExpr(result, baseObjectIsPointer, SourceLocation(),
-EmptySS, field, foundDecl, memberNameInfo)
+SS, field, foundDecl, memberNameInfo)
 .get();
 if (!result)
   return ExprError();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45410: [Sema] Remove dead code in BuildAnonymousStructUnionMemberReference. NFCI

2018-04-07 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF created this revision.
EricWF added reviewers: rsmith, aaron.ballman, majnemer, rjmccall.

This patch cleans up a bunch of dead or unused code in 
BuildAnonymousStructUnionMemberReference.

The dead code was a branch that built a new CXXThisExpr when we weren't given a 
base object expression or base variable.
However, BuildAnonymousFoo has only two callers. One of which always builds a 
base object expression first, the second only calls when the IndirectFieldDecl 
is not a C++ class member. Even within C this branch seems entirely unused.

I tried diligently to write a test which hit it with no success.

This patch removes the branch and replaces it with an assertion that we were 
given either a base object expression or a base variable.


Repository:
  rC Clang

https://reviews.llvm.org/D45410

Files:
  lib/Sema/SemaExprMember.cpp

Index: lib/Sema/SemaExprMember.cpp
===
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -802,16 +802,13 @@
Expr *baseObjectExpr,
SourceLocation opLoc) {
   // First, build the expression that refers to the base object.
-  
-  bool baseObjectIsPointer = false;
-  Qualifiers baseQuals;
-  
+
   // Case 1:  the base of the indirect field is not a field.
   VarDecl *baseVariable = indirectField->getVarDecl();
   CXXScopeSpec EmptySS;
   if (baseVariable) {
 assert(baseVariable->getType()->isRecordType());
-
+
 // In principle we could have a member access expression that
 // accesses an anonymous struct/union that's a static member of
 // the base object's class.  However, under the current standard,
@@ -824,68 +821,37 @@
 ExprResult result 
   = BuildDeclarationNameExpr(EmptySS, baseNameInfo, baseVariable);
 if (result.isInvalid()) return ExprError();
-
-baseObjectExpr = result.get();
-baseObjectIsPointer = false;
-baseQuals = baseObjectExpr->getType().getQualifiers();
-
-// Case 2: the base of the indirect field is a field and the user
-// wrote a member expression.
-  } else if (baseObjectExpr) {
-// The caller provided the base object expression. Determine
-// whether its a pointer and whether it adds any qualifiers to the
-// anonymous struct/union fields we're looking into.
-QualType objectType = baseObjectExpr->getType();
-
-if (const PointerType *ptr = objectType->getAs()) {
-  baseObjectIsPointer = true;
-  objectType = ptr->getPointeeType();
-} else {
-  baseObjectIsPointer = false;
-}
-baseQuals = objectType.getQualifiers();
-
-// Case 3: the base of the indirect field is a field and we should
-// build an implicit member access.
-  } else {
-// We've found a member of an anonymous struct/union that is
-// inside a non-anonymous struct/union, so in a well-formed
-// program our base object expression is "this".
-QualType ThisTy = getCurrentThisType();
-if (ThisTy.isNull()) {
-  Diag(loc, diag::err_invalid_member_use_in_static_method)
-<< indirectField->getDeclName();
-  return ExprError();
-}
-
-// Our base object expression is "this".
-CheckCXXThisCapture(loc);
-baseObjectExpr 
-  = new (Context) CXXThisExpr(loc, ThisTy, /*isImplicit=*/ true);
-baseObjectIsPointer = true;
-baseQuals = ThisTy->castAs()->getPointeeType().getQualifiers();
+
+baseObjectExpr = result.get();
   }
-  
+
+  assert((baseVariable || baseObjectExpr) &&
+ "referencing anonymous struct/union without a base variable or "
+ "expression");
+
   // Build the implicit member references to the field of the
   // anonymous struct/union.
   Expr *result = baseObjectExpr;
   IndirectFieldDecl::chain_iterator
   FI = indirectField->chain_begin(), FEnd = indirectField->chain_end();
-  
-  // Build the first member access in the chain with full information.
+
+  // Case 2: the base of the indirect field is a field and the user
+  // wrote a member expression.
   if (!baseVariable) {
 FieldDecl *field = cast(*FI);
-
+
+bool baseObjectIsPointer = baseObjectExpr->getType()->isPointerType();
+
 // Make a nameInfo that properly uses the anonymous name.
 DeclarationNameInfo memberNameInfo(field->getDeclName(), loc);
 
-result = BuildFieldReferenceExpr(result, baseObjectIsPointer,
- SourceLocation(), EmptySS, field,
- foundDecl, memberNameInfo).get();
+// Build the first member access in the chain with full information.
+result =
+BuildFieldReferenceExpr(result, baseObjectIsPointer, SourceLocation(),
+EmptySS, field, foundDecl, memberNameInfo)
+.get();
 if (!result)
   return ExprError();
-
-// FIXME: check qualified member access
   }
   
   // In all cases, we

[PATCH] D45392: [clang-tidy] add new check to find out objc ivars which do not have prefix '_'

2018-04-07 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

In https://reviews.llvm.org/D45392#1060845, @Wizard wrote:

> In https://reviews.llvm.org/D45392#1060485, @Eugene.Zelenko wrote:
>
> > If this is Apple guideline, check name should reflect this. I think will be 
> > good idea to have general check for Apple naming conventions instead of 
> > separate checks for specific situations like //objc-ivar-declaration// and 
> > //objc-property-declaration//.
>
>
> Thanks for the suggestion. I understand your point that they are both naming 
> convention, however, they are about different components and using totally 
> different naming rules. PropertyDeclarationCheck is already a very 
> complicated check (the most complicated one for ObjC), I would rather not 
> make it more heavy and try my best to split independent logic to different 
> checks.


See readability-identifier-naming 

 as example of multiple rules in one check.




Comment at: docs/ReleaseNotes.rst:60
 
+- New :doc:`objc-ivar-declaration
+  ` check

Wizard wrote:
> Eugene.Zelenko wrote:
> > Please place in new check list in alphabetical order.
> I did not see a "new check list" in alphabetical order in this file. I 
> believe they are ordered by commit time.If you mean the list.rst, they are 
> already ordered alphabetically.
Please read starting words in list of changes.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45392



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45392: [clang-tidy] add new check to find out objc ivars which do not have prefix '_'

2018-04-07 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 141515.
Wizard edited the summary of this revision.
Wizard added a comment.

resolve comments


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45392

Files:
  clang-tidy/objc/CMakeLists.txt
  clang-tidy/objc/IvarDeclarationCheck.cpp
  clang-tidy/objc/IvarDeclarationCheck.h
  clang-tidy/objc/ObjCTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/objc-ivar-declaration.rst
  test/clang-tidy/objc-ivar-declaration.m

Index: test/clang-tidy/objc-ivar-declaration.m
===
--- /dev/null
+++ test/clang-tidy/objc-ivar-declaration.m
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s objc-ivar-declaration %t
+@interface Foo
+@end 
+
+@interface Foo () {
+int _bar;
+int barWithoutPrefix;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: instance variable 'barWithoutPrefix' not using '_' as prefix [objc-ivar-declaration]
+// CHECK-FIXES: int _barWithoutPrefix;
+}
+@end
Index: docs/clang-tidy/checks/objc-ivar-declaration.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/objc-ivar-declaration.rst
@@ -0,0 +1,22 @@
+.. title:: clang-tidy - objc-ivar-declaration
+
+objc-ivar-declaration
+=
+
+Finds Objective-C ivars that do not have a '_' prefix.
+According to Apple's programming guide, the ivar names should be 
+prefixed with '_'.
+
+For code of ivar declaration:
+
+.. code-block:: objc
+
+   int barWithoutPrefix;
+
+The fix will be:
+
+.. code-block:: objc
+
+   int _barWithoutPrefix;
+
+The corresponding style rule: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingIvarsAndTypes.html#//apple_ref/doc/uid/20001284-1001757
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -187,6 +187,7 @@
objc-avoid-nserror-init
objc-avoid-spinlock
objc-forbidden-subclassing
+   objc-ivar-declaration
objc-property-declaration
performance-faster-string-find
performance-for-range-copy
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New :doc:`objc-ivar-declaration
+  ` check
+
+  Finds Objective-C ivars that do not have a '_' prefix.
+
 - New module `abseil` for checks related to the `Abseil `_
   library.
 
Index: clang-tidy/objc/ObjCTidyModule.cpp
===
--- clang-tidy/objc/ObjCTidyModule.cpp
+++ clang-tidy/objc/ObjCTidyModule.cpp
@@ -13,6 +13,7 @@
 #include "AvoidNSErrorInitCheck.h"
 #include "AvoidSpinlockCheck.h"
 #include "ForbiddenSubclassingCheck.h"
+#include "IvarDeclarationCheck.h"
 #include "PropertyDeclarationCheck.h"
 
 using namespace clang::ast_matchers;
@@ -30,6 +31,8 @@
 "objc-avoid-spinlock");
 CheckFactories.registerCheck(
 "objc-forbidden-subclassing");
+CheckFactories.registerCheck(
+"objc-ivar-declaration");
 CheckFactories.registerCheck(
 "objc-property-declaration");
   }
Index: clang-tidy/objc/IvarDeclarationCheck.h
===
--- /dev/null
+++ clang-tidy/objc/IvarDeclarationCheck.h
@@ -0,0 +1,35 @@
+//===--- IvarDeclarationCheck.h - clang-tidy-*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_IVARDECLARATIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_IVARDECLARATIONCHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace objc {
+
+/// Finds Objective-C ivars which do not have '_' prefix.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/objc-ivar-declaration.html
+class IvarDeclarationCheck : public ClangTidyCheck {
+public:
+  IvarDeclarationCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace objc
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_IVARDECLARATIONCHECK_H
Index: clang-tidy/objc/IvarDeclarationCheck.cpp
===
--- /dev/null
+++ clang-tidy/objc/IvarDeclarationCheck.cpp
@@ -0,0 +1,52 @@
+//===--- Iva

[PATCH] D45392: [clang-tidy] add new check to find out objc ivars which do not have prefix '_'

2018-04-07 Thread Yan Zhang via Phabricator via cfe-commits
Wizard marked 4 inline comments as done.
Wizard added a comment.

In https://reviews.llvm.org/D45392#1060485, @Eugene.Zelenko wrote:

> If this is Apple guideline, check name should reflect this. I think will be 
> good idea to have general check for Apple naming conventions instead of 
> separate checks for specific situations like //objc-ivar-declaration// and 
> //objc-property-declaration//.


Thanks for the suggestion. I understand your point that they are both naming 
convention, however, they are about different components and using totally 
different naming rules. PropertyDeclarationCheck is already a very complicated 
check (the most complicated one for ObjC), I would rather not make it more 
heavy and try my best to split independent logic to different checks.




Comment at: clang-tidy/objc/IvarDeclarationCheck.cpp:23
+
+FixItHint generateFixItHint(const ObjCIvarDecl *Decl) {
+  auto IvarName = Decl->getName();

Eugene.Zelenko wrote:
> Please use static instead of anonymous namespace.
Using anonymous namespace was suggested by others for private methods that are 
only used within the check (e.g. ForbiddenSubclassingCheck, 
PropertyDeclarationCheck, etc). I would rather keep this pattern consistent 
with other checks.



Comment at: docs/ReleaseNotes.rst:60
 
+- New :doc:`objc-ivar-declaration
+  ` check

Eugene.Zelenko wrote:
> Please place in new check list in alphabetical order.
I did not see a "new check list" in alphabetical order in this file. I believe 
they are ordered by commit time.If you mean the list.rst, they are already 
ordered alphabetically.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45392



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45305: ObjCGNU: Fix empty v3 protocols being emitted two fields short

2018-04-07 Thread Dustin L. Howett via Phabricator via cfe-commits
DHowett-MSFT added a comment.

It seems more fragile to check the contents of the protocol rather than the 
invariant we care most about (its size).
I'm willing to do that, and am updating the patch accordingly, but I don't want 
to commit to a more fragile test than is necessary.
Illustratively, if the GNUstep runtime one day chooses to emit empty v3 
protocols as `{3, null, null, null, null, null, null, null}` (which it may want 
to do to avoid emitting empty method lists, and which seems to work at 
runtime), a test capturing the body of the protocol will fail.


Repository:
  rC Clang

https://reviews.llvm.org/D45305



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45407: [StaticAnalyzer] Added notes to the plist output

2018-04-07 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

The output looks reasonable to me, but we'll need to see if other consumers of 
the plist output (IDEs that supports the analyzer, such as Xcode) will be able 
to accept the modified output (at least, will be able to ignore it). I'll have 
a look.


Repository:
  rC Clang

https://reviews.llvm.org/D45407



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45406: Document -std= values for different languages

2018-04-07 Thread Dimitry Andric via Phabricator via cfe-commits
dim updated this revision to Diff 141513.
dim added a comment.

- Use "values" instead of "options"
- Remove deprecated standard values


Repository:
  rC Clang

https://reviews.llvm.org/D45406

Files:
  docs/CommandGuide/clang.rst


Index: docs/CommandGuide/clang.rst
===
--- docs/CommandGuide/clang.rst
+++ docs/CommandGuide/clang.rst
@@ -98,9 +98,55 @@
 
  Treat subsequent input files as having type language.
 
-.. option:: -std=
+.. option:: -std=
 
  Specify the language standard to compile for.
+
+ Supported values for the C language are:
+
+ - ``c89``, ``c90`` or ``iso9899:1990``: ISO C 1990
+ - ``iso9899:199409``: ISO C 1990 with amendment 1
+ - ``gnu89`` or ``gnu90``: ISO C 1990 with GNU extensions
+ - ``c99`` or ``iso9899:1999``: ISO C 1999
+ - ``gnu99``: ISO C 1999 with GNU extensions
+ - ``c11`` or ``iso9899:2011``: ISO C 2011
+ - ``gnu11``: ISO C 2011 with GNU extensions
+ - ``c17`` or ``iso9899:2017``: ISO C 2017
+ - ``gnu17``: ISO C 2017 with GNU extensions
+
+ The default C language standard is ``gnu11``, except on PS4, where it is
+ ``gnu99``.
+
+ Supported values for the C++ language are:
+
+ - ``c++98`` or ``c++03``: ISO C++ 1998 with amendments
+ - ``gnu++98`` or ``gnu++03``: ISO C++ 1998 with amendments and GNU extensions
+ - ``c++11``: ISO C++ 2011 with amendments
+ - ``gnu++11``: ISO C++ 2011 with amendments and
+   GNU extensions
+ - ``c++14``: ISO C++ 2014 with amendments
+ - ``gnu++14``: ISO C++ 2014 with amendments and
+   GNU extensions
+ - ``c++17``: ISO C++ 2017 with amendments
+ - ``gnu++17``: ISO C++ 2017 with amendments and
+   GNU extensions
+ - ``c++2a``: Working draft for ISO C++ 2020
+ - ``gnu++2a``: Working draft for ISO C++ 2020 with GNU extensions
+
+ The default C++ language standard is ``gnu++14``.
+
+ Supported values for the OpenCL language are:
+
+ - ``cl1.0``: OpenCL 1.0
+ - ``cl1.1``: OpenCL 1.1
+ - ``cl1.2``: OpenCL 1.2
+ - ``cl2.0``: OpenCL 2.0
+
+ The default OpenCL language standard is ``cl1.0``.
+
+ Supported values for the CUDA language are:
+
+ - ``cuda``: NVIDIA CUDA(tm)
 
 .. option:: -stdlib=
 


Index: docs/CommandGuide/clang.rst
===
--- docs/CommandGuide/clang.rst
+++ docs/CommandGuide/clang.rst
@@ -98,9 +98,55 @@
 
  Treat subsequent input files as having type language.
 
-.. option:: -std=
+.. option:: -std=
 
  Specify the language standard to compile for.
+
+ Supported values for the C language are:
+
+ - ``c89``, ``c90`` or ``iso9899:1990``: ISO C 1990
+ - ``iso9899:199409``: ISO C 1990 with amendment 1
+ - ``gnu89`` or ``gnu90``: ISO C 1990 with GNU extensions
+ - ``c99`` or ``iso9899:1999``: ISO C 1999
+ - ``gnu99``: ISO C 1999 with GNU extensions
+ - ``c11`` or ``iso9899:2011``: ISO C 2011
+ - ``gnu11``: ISO C 2011 with GNU extensions
+ - ``c17`` or ``iso9899:2017``: ISO C 2017
+ - ``gnu17``: ISO C 2017 with GNU extensions
+
+ The default C language standard is ``gnu11``, except on PS4, where it is
+ ``gnu99``.
+
+ Supported values for the C++ language are:
+
+ - ``c++98`` or ``c++03``: ISO C++ 1998 with amendments
+ - ``gnu++98`` or ``gnu++03``: ISO C++ 1998 with amendments and GNU extensions
+ - ``c++11``: ISO C++ 2011 with amendments
+ - ``gnu++11``: ISO C++ 2011 with amendments and
+   GNU extensions
+ - ``c++14``: ISO C++ 2014 with amendments
+ - ``gnu++14``: ISO C++ 2014 with amendments and
+   GNU extensions
+ - ``c++17``: ISO C++ 2017 with amendments
+ - ``gnu++17``: ISO C++ 2017 with amendments and
+   GNU extensions
+ - ``c++2a``: Working draft for ISO C++ 2020
+ - ``gnu++2a``: Working draft for ISO C++ 2020 with GNU extensions
+
+ The default C++ language standard is ``gnu++14``.
+
+ Supported values for the OpenCL language are:
+
+ - ``cl1.0``: OpenCL 1.0
+ - ``cl1.1``: OpenCL 1.1
+ - ``cl1.2``: OpenCL 1.2
+ - ``cl2.0``: OpenCL 2.0
+
+ The default OpenCL language standard is ``cl1.0``.
+
+ Supported values for the CUDA language are:
+
+ - ``cuda``: NVIDIA CUDA(tm)
 
 .. option:: -stdlib=
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45405: [clang-tidy] [modernize-use-auto] Add a threshold for minimal type name length to be replaced with 'auto'

2018-04-07 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added a comment.

Please add to release notes.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45405



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName

2018-04-07 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL329515: [libclang] Add clang_File_tryGetRealPathName 
(authored by MaskRay, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D42893?vs=141496&id=141511#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D42893

Files:
  cfe/trunk/include/clang-c/Index.h
  cfe/trunk/tools/libclang/CIndex.cpp
  cfe/trunk/tools/libclang/libclang.exports
  cfe/trunk/unittests/libclang/LibclangTest.cpp


Index: cfe/trunk/unittests/libclang/LibclangTest.cpp
===
--- cfe/trunk/unittests/libclang/LibclangTest.cpp
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp
@@ -482,6 +482,21 @@
   }
 };
 
+TEST_F(LibclangReparseTest, FileName) {
+  std::string CppName = "main.cpp";
+  WriteFile(CppName, "int main() {}");
+  ClangTU = clang_parseTranslationUnit(Index, CppName.c_str(), nullptr, 0,
+   nullptr, 0, TUFlags);
+  CXFile cxf = clang_getFile(ClangTU, CppName.c_str());
+
+  CXString cxname = clang_getFileName(cxf);
+  ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str()));
+  clang_disposeString(cxname);
+
+  cxname = clang_File_tryGetRealPathName(cxf);
+  ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str()));
+  clang_disposeString(cxname);
+}
 
 TEST_F(LibclangReparseTest, Reparse) {
   const char *HeaderTop = "#ifndef H\n#define H\nstruct Foo { int bar;";
Index: cfe/trunk/tools/libclang/CIndex.cpp
===
--- cfe/trunk/tools/libclang/CIndex.cpp
+++ cfe/trunk/tools/libclang/CIndex.cpp
@@ -4249,6 +4249,14 @@
   return FEnt1->getUniqueID() == FEnt2->getUniqueID();
 }
 
+CXString clang_File_tryGetRealPathName(CXFile SFile) {
+  if (!SFile)
+return cxstring::createNull();
+
+  FileEntry *FEnt = static_cast(SFile);
+  return cxstring::createRef(FEnt->tryGetRealPathName());
+}
+
 
//===--===//
 // CXCursor Operations.
 
//===--===//
Index: cfe/trunk/tools/libclang/libclang.exports
===
--- cfe/trunk/tools/libclang/libclang.exports
+++ cfe/trunk/tools/libclang/libclang.exports
@@ -46,6 +46,7 @@
 clang_Cursor_getModule
 clang_Cursor_getStorageClass
 clang_File_isEqual
+clang_File_tryGetRealPathName
 clang_Module_getASTFile
 clang_Module_getParent
 clang_Module_getName
Index: cfe/trunk/include/clang-c/Index.h
===
--- cfe/trunk/include/clang-c/Index.h
+++ cfe/trunk/include/clang-c/Index.h
@@ -425,6 +425,13 @@
 CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2);
 
 /**
+ * \brief Returns the real path name of \c file.
+ *
+ * An empty string may be returned. Use \c clang_getFileName() in that case.
+ */
+CINDEX_LINKAGE CXString clang_File_tryGetRealPathName(CXFile file);
+
+/**
  * @}
  */
 


Index: cfe/trunk/unittests/libclang/LibclangTest.cpp
===
--- cfe/trunk/unittests/libclang/LibclangTest.cpp
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp
@@ -482,6 +482,21 @@
   }
 };
 
+TEST_F(LibclangReparseTest, FileName) {
+  std::string CppName = "main.cpp";
+  WriteFile(CppName, "int main() {}");
+  ClangTU = clang_parseTranslationUnit(Index, CppName.c_str(), nullptr, 0,
+   nullptr, 0, TUFlags);
+  CXFile cxf = clang_getFile(ClangTU, CppName.c_str());
+
+  CXString cxname = clang_getFileName(cxf);
+  ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str()));
+  clang_disposeString(cxname);
+
+  cxname = clang_File_tryGetRealPathName(cxf);
+  ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str()));
+  clang_disposeString(cxname);
+}
 
 TEST_F(LibclangReparseTest, Reparse) {
   const char *HeaderTop = "#ifndef H\n#define H\nstruct Foo { int bar;";
Index: cfe/trunk/tools/libclang/CIndex.cpp
===
--- cfe/trunk/tools/libclang/CIndex.cpp
+++ cfe/trunk/tools/libclang/CIndex.cpp
@@ -4249,6 +4249,14 @@
   return FEnt1->getUniqueID() == FEnt2->getUniqueID();
 }
 
+CXString clang_File_tryGetRealPathName(CXFile SFile) {
+  if (!SFile)
+return cxstring::createNull();
+
+  FileEntry *FEnt = static_cast(SFile);
+  return cxstring::createRef(FEnt->tryGetRealPathName());
+}
+
 //===--===//
 // CXCursor Operations.
 //===--===//
Index: cfe/trunk/tools/libclang/libclang.exports
===
--- cfe/trunk/tools/libclang/libclang.exports
+++ cfe/trunk/tools/libclang/libclang.exports
@@ -46,6 +46,7 @@

[PATCH] D45409: [cmake] Include LLVMTestingSupport when doing stand-alone build

2018-04-07 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: simark, ilya-biryukov.
Herald added a subscriber: ioeric.

Explicitly include and build lib/Testing/Support from LLVM sources when
doing a stand-alone build. This is necessary since clangd tests started
to depend on LLVMTestingSupport library which is neither installed
by LLVM, nor built by clang itself.

Since completely separate build of clang-tools-extra is not supported,
this relies on variables set by clang CMakeLists.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45409

Files:
  unittests/CMakeLists.txt


Index: unittests/CMakeLists.txt
===
--- unittests/CMakeLists.txt
+++ unittests/CMakeLists.txt
@@ -5,6 +5,15 @@
   add_unittest(ExtraToolsUnitTests ${test_dirname} ${ARGN})
 endfunction()
 
+if(CLANG_BUILT_STANDALONE)
+  # LLVMTestingSupport library is needed for clangd tests.
+  if (EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Testing/Support
+  AND NOT TARGET LLVMTestingSupport)
+add_subdirectory(${LLVM_MAIN_SRC_DIR}/lib/Testing/Support
+  lib/Testing/Support)
+  endif()
+endif()
+
 add_subdirectory(change-namespace)
 add_subdirectory(clang-apply-replacements)
 add_subdirectory(clang-move)


Index: unittests/CMakeLists.txt
===
--- unittests/CMakeLists.txt
+++ unittests/CMakeLists.txt
@@ -5,6 +5,15 @@
   add_unittest(ExtraToolsUnitTests ${test_dirname} ${ARGN})
 endfunction()
 
+if(CLANG_BUILT_STANDALONE)
+  # LLVMTestingSupport library is needed for clangd tests.
+  if (EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Testing/Support
+  AND NOT TARGET LLVMTestingSupport)
+add_subdirectory(${LLVM_MAIN_SRC_DIR}/lib/Testing/Support
+  lib/Testing/Support)
+  endif()
+endif()
+
 add_subdirectory(change-namespace)
 add_subdirectory(clang-apply-replacements)
 add_subdirectory(clang-move)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45407: [StaticAnalyzer] Added notes to the plist output

2018-04-07 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: dergachev.a, xazax.hun.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, a.sidorin, rnkovacs, szepet, whisperity.
Herald added a reviewer: george.karpenkov.

Added notes to `-analyzer-output=plist`.


Repository:
  rC Clang

https://reviews.llvm.org/D45407

Files:
  lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  test/Analysis/copypaste/plist-diagnostics.cpp

Index: test/Analysis/copypaste/plist-diagnostics.cpp
===
--- test/Analysis/copypaste/plist-diagnostics.cpp
+++ test/Analysis/copypaste/plist-diagnostics.cpp
@@ -17,12 +17,39 @@
   return b;
 }
 
-// FIXME: This plist output doesn't include the extra note on line 13.
-// It should be updated once the format for extra notes in plists is defined.
-
 // CHECK:  diagnostics
 // CHECK-NEXT:  
 // CHECK-NEXT:   
+// CHECK-NEXT:notes
+// CHECK-NEXT:
+// CHECK-NEXT: 
+// CHECK-NEXT:  location
+// CHECK-NEXT:  
+// CHECK-NEXT:   line13
+// CHECK-NEXT:   col28
+// CHECK-NEXT:   file0
+// CHECK-NEXT:  
+// CHECK-NEXT:  ranges
+// CHECK-NEXT:  
+// CHECK-NEXT:
+// CHECK-NEXT: 
+// CHECK-NEXT:  line13
+// CHECK-NEXT:  col28
+// CHECK-NEXT:  file0
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT:  line18
+// CHECK-NEXT:  col1
+// CHECK-NEXT:  file0
+// CHECK-NEXT: 
+// CHECK-NEXT:
+// CHECK-NEXT:  
+// CHECK-NEXT:  extended_message
+// CHECK-NEXT:  Similar code here
+// CHECK-NEXT:  message
+// CHECK-NEXT:  Similar code here
+// CHECK-NEXT: 
+// CHECK-NEXT:
 // CHECK-NEXT:path
 // CHECK-NEXT:
 // CHECK-NEXT: 
Index: lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
===
--- lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -84,6 +84,41 @@
PP.getLangOpts(), true));
 }
 
+static void EmitRanges(raw_ostream &o,
+   const ArrayRef Ranges,
+   const FIDMap& FM,
+   const SourceManager &SM,
+   const LangOptions &LangOpts,
+   unsigned indent) {
+
+  if (Ranges.empty())
+return;
+
+  Indent(o, indent) << "ranges\n";
+  Indent(o, indent) << "\n";
+  ++indent;
+  for (auto &R : Ranges)
+EmitRange(o, SM,
+  Lexer::getAsCharRange(SM.getExpansionRange(R), SM, LangOpts),
+  FM, indent + 1);
+  --indent;
+  Indent(o, indent) << "\n";
+}
+
+static void EmitMessage(raw_ostream &o, StringRef Message, unsigned indent) {
+  // Output the text.
+  assert(!Message.empty());
+  Indent(o, indent) << "extended_message\n";
+  Indent(o, indent);
+  EmitString(o, Message) << '\n';
+
+  // Output the short text.
+  // FIXME: Really use a short string.
+  Indent(o, indent) << "message\n";
+  Indent(o, indent);
+  EmitString(o, Message) << '\n';
+}
+
 static void ReportControlFlow(raw_ostream &o,
   const PathDiagnosticControlFlowPiece& P,
   const FIDMap& FM,
@@ -138,7 +173,7 @@
   Indent(o, indent) << "\n";
 }
 
-static void ReportEvent(raw_ostream &o, const PathDiagnosticPiece& P,
+static void ReportEvent(raw_ostream &o, const PathDiagnosticEventPiece& P,
 const FIDMap& FM,
 const SourceManager &SM,
 const LangOptions &LangOpts,
@@ -163,34 +198,14 @@
 
   // Output the ranges (if any).
   ArrayRef Ranges = P.getRanges();
-
-  if (!Ranges.empty()) {
-Indent(o, indent) << "ranges\n";
-Indent(o, indent) << "\n";
-++indent;
-for (auto &R : Ranges)
-  EmitRange(o, SM,
-Lexer::getAsCharRange(SM.getExpansionRange(R), SM, LangOpts),
-FM, indent + 1);
---indent;
-Indent(o, indent) << "\n";
-  }
+  EmitRanges(o, Ranges, FM, SM, LangOpts, indent);
 
   // Output the call depth.
   Indent(o, indent) << "depth";
   EmitInteger(o, depth) << '\n';
 
   // Output the text.
-  assert(!P.getString().empty());
-  Indent(o, indent) << "extended_message\n";
-  Indent(o, indent);
-  EmitString(o, P.getString()) << '\n';
-
-  // Output the short text.
-  // FIXME: Really use a short string.
-  Indent(o, indent) << "message\n";
-  Indent(o, indent);
-  EmitString(o, P.getString()) << '\n';
+  EmitMessage(o, P.getString(), indent);
 
   // Finish up.
   --indent;
@@ -246,6 +261,34 @@
   }
 }
 
+static void ReportNote(raw_ostream &o, const PathDiagnosticNotePiece& P,
+const FIDMap& FM,
+const SourceManager &SM,
+const LangOptions &LangOpts,
+unsigned indent,
+unsigned depth) {
+
+  Indent(o, indent) << "\n";
+  ++indent;
+
+  

[PATCH] D45311: Introduce wbinvd intrinsic

2018-04-07 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rC Clang

https://reviews.llvm.org/D45311



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r329513 - Generalize the swiftcall API since being passed indirectly isn't

2018-04-07 Thread John McCall via cfe-commits
Author: rjmccall
Date: Sat Apr  7 13:16:47 2018
New Revision: 329513

URL: http://llvm.org/viewvc/llvm-project?rev=329513&view=rev
Log:
Generalize the swiftcall API since being passed indirectly isn't
C++-specific anymore.

Modified:
cfe/trunk/include/clang/CodeGen/SwiftCallingConv.h
cfe/trunk/lib/CodeGen/SwiftCallingConv.cpp

Modified: cfe/trunk/include/clang/CodeGen/SwiftCallingConv.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/CodeGen/SwiftCallingConv.h?rev=329513&r1=329512&r2=329513&view=diff
==
--- cfe/trunk/include/clang/CodeGen/SwiftCallingConv.h (original)
+++ cfe/trunk/include/clang/CodeGen/SwiftCallingConv.h Sat Apr  7 13:16:47 2018
@@ -152,9 +152,15 @@ void legalizeVectorType(CodeGenModule &C
 llvm::VectorType *vectorTy,
 llvm::SmallVectorImpl &types);
 
-/// Should a C++ record type be passed and returned indirectly?
-bool shouldPassCXXRecordIndirectly(CodeGenModule &CGM,
-   const CXXRecordDecl *record);
+/// Is the given record type required to be passed and returned indirectly
+/// because of language restrictions?
+///
+/// This considers *only* mandatory indirectness due to language restrictions,
+/// such as C++'s non-trivially-copyable types and Objective-C's __weak
+/// references.  A record for which this returns true may still be passed
+/// indirectly for other reasons, such as being too large to fit in a
+/// reasonable number of registers.
+bool mustPassRecordIndirectly(CodeGenModule &CGM, const RecordDecl *record);
 
 /// Classify the rules for how to return a particular type.
 ABIArgInfo classifyReturnType(CodeGenModule &CGM, CanQualType type);
@@ -166,7 +172,7 @@ ABIArgInfo classifyArgumentType(CodeGenM
 /// private interface for Clang.
 void computeABIInfo(CodeGenModule &CGM, CGFunctionInfo &FI);
 
-/// Is swifterror lowered to a register by the target ABI.
+/// Is swifterror lowered to a register by the target ABI?
 bool isSwiftErrorLoweredInRegister(CodeGenModule &CGM);
 
 } // end namespace swiftcall

Modified: cfe/trunk/lib/CodeGen/SwiftCallingConv.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/SwiftCallingConv.cpp?rev=329513&r1=329512&r2=329513&view=diff
==
--- cfe/trunk/lib/CodeGen/SwiftCallingConv.cpp (original)
+++ cfe/trunk/lib/CodeGen/SwiftCallingConv.cpp Sat Apr  7 13:16:47 2018
@@ -740,8 +740,8 @@ void swiftcall::legalizeVectorType(CodeG
   components.append(numElts, eltTy);
 }
 
-bool swiftcall::shouldPassCXXRecordIndirectly(CodeGenModule &CGM,
-  const CXXRecordDecl *record) {
+bool swiftcall::mustPassRecordIndirectly(CodeGenModule &CGM,
+ const RecordDecl *record) {
   // FIXME: should we not rely on the standard computation in Sema, just in
   // case we want to diverge from the platform ABI (e.g. on targets where
   // that uses the MSVC rule)?
@@ -767,10 +767,8 @@ static ABIArgInfo classifyType(CodeGenMo
 auto record = recordType->getDecl();
 auto &layout = CGM.getContext().getASTRecordLayout(record);
 
-if (auto cxxRecord = dyn_cast(record)) {
-  if (shouldPassCXXRecordIndirectly(CGM, cxxRecord))
-return ABIArgInfo::getIndirect(layout.getAlignment(), /*byval*/ false);
-}
+if (mustPassRecordIndirectly(CGM, record))
+  return ABIArgInfo::getIndirect(layout.getAlignment(), /*byval*/ false);
 
 SwiftAggLowering lowering(CGM);
 lowering.addTypedData(recordType->getDecl(), CharUnits::Zero(), layout);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45406: Document -std= values for different languages

2018-04-07 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In https://reviews.llvm.org/D45406#1060773, @dim wrote:

> In https://reviews.llvm.org/D45406#1060768, @mgorny wrote:
>
> > To be honest, I find those '(deprecated)' confusing — the user may 
> > mistakenly assume that it's about all values rather than the alias.
>
>
> Sure, what would you suggest as an alternative?  Not listing them, listing 
> them separately, using some sort of "*" suffix, or anything else?


I think not listing them is probably best. We don't want anyone to specify 
them, after all.


Repository:
  rC Clang

https://reviews.llvm.org/D45406



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-07 Thread Manoj Gupta via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC329512: [Driver] Update GCC libraries detection logic for 
Gentoo. (authored by manojgupta, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D45233?vs=141295&id=141501#toc

Repository:
  rC Clang

https://reviews.llvm.org/D45233

Files:
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/ToolChains/Gnu.h
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/etc/env.d/gcc/config-x86_64-pc-linux-gnu
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
  test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/etc/gentoo-release
  test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/include/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/x32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5.4.0/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/x32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/x86_64-pc-linux-gnu/lib/.keep
  test/Driver/linux-header-search.cpp

Index: lib/Driver/ToolChains/Gnu.cpp
===
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -1676,18 +1676,21 @@
   // in /usr. This avoids accidentally enforcing the system GCC version
   // when using a custom toolchain.
   if (GCCToolchainDir == "" || GCCToolchainDir == D.SysRoot + "/usr") {
-for (StringRef CandidateTriple : ExtraTripleAliases) {
-  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple))
-return;
-}
-for (StringRef CandidateTriple : CandidateTripleAliases) {
-  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple))
-return;
-}
-for (StringRef CandidateTriple : CandidateBiarchTripleAliases) {
-  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple, true))
-return;
-}
+SmallVector GentooTestTriples;
+// Try to match an exact triple as target triple first.
+// e.g. crossdev -S x86_64-gentoo-linux-gnu will install gcc libs for
+// x86_64-gentoo-linux-gnu. But "clang -target x86_64-gentoo-linux-gnu"
+// may pick the libraries for x86_64-pc-linux-gnu even when exact matching
+// triple x86_64-gentoo-linux-gnu is present.
+GentooTestTriples.push_back(TargetTriple.str());
+// Check rest of triples.
+GentooTestTriples.append(ExtraTripleAliases.begin(),
+ ExtraTripleAliases.end());
+GentooTestTriples.append(CandidateTripleAliases.begin(),
+ CandidateTripleAliases.end());
+if (ScanGentooConfigs(TargetTriple, Args, GentooTestTriples,
+  CandidateBiarchTripleAliases))
+  return;
   }
 
   // Loop over the various components which exist and select the best GCC
@@ -1700,6 +1703,9 @@
   const std::string LibDir = Prefix + Suffix.str();
   if (!D.getVFS().exists(LibDir))
 continue;
+  // Try to match the exact target triple first.
+  ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, TargetTriple.str());
+  // Try rest of possible triples.
   for (StringRef Candidate : ExtraTripleAliases) // Try these first.
 ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate);
   for (StringRef Candidate : CandidateTripleAliases)
@@ -2193,6 +2199,22 @@
   }
 }
 
+bool Generic_GCC::GCCInstallationDetector::ScanGentooConfigs(
+const llvm::Triple &TargetTriple, const ArgList &Args,
+const SmallVectorImpl &CandidateTriples,
+const SmallVectorImpl &CandidateBiarchTriples) {
+  for (StringRef CandidateTriple : CandidateTriples) {
+if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple))
+  return true;
+  }
+
+  for (StringRef CandidateTriple : CandidateBiarchTriples) {
+if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple, true))
+  return true;
+  }
+  return false;
+}
+
 bool Generic_GCC::GCCInstallationDetector::ScanGentooGccConfig(
 const llvm::Triple &TargetTriple, const ArgList &Args,
 StringRef CandidateTriple, bool NeedsBiarchSuffix) {
@@ -2205,23 +2227,53 @@
 for (StringRef Line : Lines) {
   Line = Line.trim();
   // CURRENT=triple-version
-  if (Line.consume_front("CURRENT=")) {
-const std::pair ActiveVersion =
-  Line.rsplit('-');
-//

r329512 - [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-07 Thread Manoj Gupta via cfe-commits
Author: manojgupta
Date: Sat Apr  7 12:59:58 2018
New Revision: 329512

URL: http://llvm.org/viewvc/llvm-project?rev=329512&view=rev
Log:
[Driver] Update GCC libraries detection logic for Gentoo.

Summary:
1. Find GCC's LDPATH from the actual GCC config file.
2. Avoid picking libraries from a similar named tuple if the exact
   tuple is installed.

Reviewers: mgorny, chandlerc, thakis, rnk

Reviewed By: mgorny, rnk

Subscribers: cfe-commits, mgorny

Differential Revision: https://reviews.llvm.org/D45233

Added:
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/etc/
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/etc/env.d/
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/etc/env.d/gcc/

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/etc/env.d/gcc/config-x86_64-pc-linux-gnu

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/etc/gentoo-release
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/include/
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/include/.keep
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/32/

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/32/crtbegin.o

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/crtbegin.o

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/.keep

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/x32/

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/x32/crtbegin.o

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/32/

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/32/crtbegin.o

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/crtbegin.o

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5.4.0/

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5.4.0/.keep

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/x32/

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/x32/crtbegin.o

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/x86_64-pc-linux-gnu/

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/x86_64-pc-linux-gnu/lib/

cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/x86_64-pc-linux-gnu/lib/.keep
Modified:
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
cfe/trunk/lib/Driver/ToolChains/Gnu.h
cfe/trunk/test/Driver/linux-header-search.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=329512&r1=329511&r2=329512&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Sat Apr  7 12:59:58 2018
@@ -1676,18 +1676,21 @@ void Generic_GCC::GCCInstallationDetecto
   // in /usr. This avoids accidentally enforcing the system GCC version
   // when using a custom toolchain.
   if (GCCToolchainDir == "" || GCCToolchainDir == D.SysRoot + "/usr") {
-for (StringRef CandidateTriple : ExtraTripleAliases) {
-  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple))
-return;
-}
-for (StringRef CandidateTriple : CandidateTripleAliases) {
-  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple))
-return;
-}
-for (StringRef CandidateTriple : CandidateBiarchTripleAliases) {
-  if (ScanGentooGccConfig

RE: r329465 - Recommit r329442: Generate Libclang invocation reproducers using a new

2018-04-07 Thread via cfe-commits
Hi Alex,

The two tests you added in this commit seem to be failing because of a crash on 
one of the Windows bots. Can you take a look?

http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/8912

FAIL: Clang :: Index/create-libclang-parsing-reproducer.c (7891 of 37034)
 TEST 'Clang :: Index/create-libclang-parsing-reproducer.c' 
FAILED 
Script:
--
rm -rf 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\tools\clang\test\Index\Output\create-libclang-parsing-reproducer.c.tmp
mkdir 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\tools\clang\test\Index\Output\create-libclang-parsing-reproducer.c.tmp
env 
CINDEXTEST_INVOCATION_EMISSION_PATH=C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\tools\clang\test\Index\Output\create-libclang-parsing-reproducer.c.tmp
 not 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\bin\c-index-test.EXE
 -test-load-source all 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Index\create-libclang-parsing-reproducer.c
c:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\bin\clang.EXE 
-cc1gen-reproducer 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\tools\clang\test\Index\Output\create-libclang-parsing-reproducer.c.tmp/libclang-*
 -v | 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\bin\FileCheck.EXE
 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Index\create-libclang-parsing-reproducer.c
ls 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\tools\clang\test\Index\Output\create-libclang-parsing-reproducer.c.tmp
 | 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\bin\count.EXE 0
rm -rf 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\tools\clang\test\Index\Output\create-libclang-parsing-reproducer.c.tmp
mkdir 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\tools\clang\test\Index\Output\create-libclang-parsing-reproducer.c.tmp
env 
CINDEXTEST_INVOCATION_EMISSION_PATH=C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\tools\clang\test\Index\Output\create-libclang-parsing-reproducer.c.tmp
 not 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\bin\c-index-test.EXE
 -test-load-source all 
"-remap-file=C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Index\create-libclang-parsing-reproducer.c,C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Index/Inputs/record-parsing-invocation-remap.c"
 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Index\create-libclang-parsing-reproducer.c
c:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\bin\clang.EXE 
-cc1gen-reproducer 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\tools\clang\test\Index\Output\create-libclang-parsing-reproducer.c.tmp/libclang-*
 -v | 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\bin\FileCheck.EXE
 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Index\create-libclang-parsing-reproducer.c
--
Exit Code: 2

Command Output (stdout):
--
$ "rm" "-rf" 
"C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\tools\clang\test\Index\Output\create-libclang-parsing-reproducer.c.tmp"
$ "mkdir" 
"C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\tools\clang\test\Index\Output\create-libclang-parsing-reproducer.c.tmp"
$ "not" 
"C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\bin\c-index-test.EXE"
 "-test-load-source" "all" 
"C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Index\create-libclang-parsing-reproducer.c"
# command stderr:
libclang: crash detected during parsing: {

  'source_filename' : '(null)'

  'command_line_args' : ['clang', 
'C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Index\create-libclang-parsing-reproducer.c'],

  'unsaved_files' : [],

  'options' : 1,

}

Unable to load translation unit!

Failure: libclang crashed


$ 
"c:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\bin\clang.EXE" 
"-cc1gen-reproducer" 
"C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\tools\clang\test\Index\Output\create-libclang-parsing-reproducer.c.tmp/libclang-*"
 "-v"
# command stderr:
YAML:1:366: error: Unrecognized escape code!

{"toolchain":"C:\\ps4-buildslave2\\llvm-clang-x86_64-expensive-checks-win\\build","libclang.operation":"parse","libclang.opts":1,"args":["clang","-fno-spell-checking","C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Index\create-libclang-parsing-reproducer.c","-Xclang","-detailed-preprocessing-record","-fallow-editor-placeholders"]}


 

[PATCH] D45406: Document -std= values for different languages

2018-04-07 Thread Dimitry Andric via Phabricator via cfe-commits
dim added a comment.

In https://reviews.llvm.org/D45406#1060768, @mgorny wrote:

> To be honest, I find those '(deprecated)' confusing — the user may mistakenly 
> assume that it's about all values rather than the alias.


Sure, what would you suggest as an alternative?  Not listing them, listing them 
separately, using some sort of "*" suffix, or anything else?


Repository:
  rC Clang

https://reviews.llvm.org/D45406



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45406: Document -std= values for different languages

2018-04-07 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

To be honest, I find those '(deprecated)' confusing — the user may mistakenly 
assume that it's about all values rather than the alias.




Comment at: docs/CommandGuide/clang.rst:105
+
+ Supported options for the C language are:
+

s/options/values/ I think.


Repository:
  rC Clang

https://reviews.llvm.org/D45406



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45406: Document -std= values for different languages

2018-04-07 Thread Dimitry Andric via Phabricator via cfe-commits
dim created this revision.
dim added reviewers: rsmith, dexonsmith, sylvestre.ledru, mgorny.
Herald added subscribers: krytarowski, fhahn.

After a remark on a FreeBSD mailing list that the clang man page did
not have any list of possible values for the `-std=` flag, I have now
attempted to exhaustively list those, for each available language.

This also includes a number of deprecated aliases, but since some of
those are still used, we might as well include them.  They are marked
with '(deprecated)`.

I also documented the default standard for each language, if there was
more than one choice.

Suggestions on how to make the values and descriptions line up more
nicely in RST are welcome.


Repository:
  rC Clang

https://reviews.llvm.org/D45406

Files:
  docs/CommandGuide/clang.rst


Index: docs/CommandGuide/clang.rst
===
--- docs/CommandGuide/clang.rst
+++ docs/CommandGuide/clang.rst
@@ -98,9 +98,57 @@
 
  Treat subsequent input files as having type language.
 
-.. option:: -std=
+.. option:: -std=
 
  Specify the language standard to compile for.
+
+ Supported options for the C language are:
+
+ - ``c89``, ``c90`` or ``iso9899:1990``: ISO C 1990
+ - ``iso9899:199409``: ISO C 1990 with amendment 1
+ - ``gnu89`` or ``gnu90``: ISO C 1990 with GNU extensions
+ - ``c99``, ``iso9899:1999``, ``c9x`` (deprecated) or ``iso9899:199x``
+   (deprecated): ISO C 1999
+ - ``gnu99`` or ``gnu9x`` (deprecated): ISO C 1999 with GNU extensions
+ - ``c11``, ``iso9899:2011``, ``c1x`` (deprecated) or ``iso9899:201x``
+   (deprecated): ISO C 2011
+ - ``gnu11`` or ``gnu1x`` (deprecated): ISO C 2011 with GNU extensions
+ - ``c17`` or ``iso9899:2017``: ISO C 2017
+ - ``gnu17``: ISO C 2017 with GNU extensions
+
+ The default C language standard is ``gnu11``, except on PS4, where it is
+ ``gnu99``.
+
+ Supported options for the C++ language are:
+
+ - ``c++98`` or ``c++03``: ISO C++ 1998 with amendments
+ - ``gnu++98`` or ``gnu++03``: ISO C++ 1998 with amendments and GNU extensions
+ - ``c++11`` or ``c++0x`` (deprecated): ISO C++ 2011 with amendments
+ - ``gnu++11`` or ``gnu++0x`` (deprecated): ISO C++ 2011 with amendments and
+   GNU extensions
+ - ``c++14`` or ``c++1y`` (deprecated): ISO C++ 2014 with amendments
+ - ``gnu++14`` or ``gnu++1y`` (deprecated): ISO C++ 2014 with amendments and
+   GNU extensions
+ - ``c++17`` or ``c++1z`` (deprecated): ISO C++ 2017 with amendments
+ - ``gnu++17`` or ``gnu++1z`` (deprecated): ISO C++ 2017 with amendments and
+   GNU extensions
+ - ``c++2a``: Working draft for ISO C++ 2020
+ - ``gnu++2a``: Working draft for ISO C++ 2020 with GNU extensions
+
+ The default C++ language standard is ``gnu++14``.
+
+ Supported options for the OpenCL language are:
+
+ - ``cl1.0`` or ``cl`` (deprecated): OpenCL 1.0
+ - ``cl1.1``: OpenCL 1.1
+ - ``cl1.2``: OpenCL 1.2
+ - ``cl2.0``: OpenCL 2.0
+
+ The default OpenCL language standard is ``cl1.0``.
+
+ Supported options for the CUDA language are:
+
+ - ``cuda``: NVIDIA CUDA(tm)
 
 .. option:: -stdlib=
 


Index: docs/CommandGuide/clang.rst
===
--- docs/CommandGuide/clang.rst
+++ docs/CommandGuide/clang.rst
@@ -98,9 +98,57 @@
 
  Treat subsequent input files as having type language.
 
-.. option:: -std=
+.. option:: -std=
 
  Specify the language standard to compile for.
+
+ Supported options for the C language are:
+
+ - ``c89``, ``c90`` or ``iso9899:1990``: ISO C 1990
+ - ``iso9899:199409``: ISO C 1990 with amendment 1
+ - ``gnu89`` or ``gnu90``: ISO C 1990 with GNU extensions
+ - ``c99``, ``iso9899:1999``, ``c9x`` (deprecated) or ``iso9899:199x``
+   (deprecated): ISO C 1999
+ - ``gnu99`` or ``gnu9x`` (deprecated): ISO C 1999 with GNU extensions
+ - ``c11``, ``iso9899:2011``, ``c1x`` (deprecated) or ``iso9899:201x``
+   (deprecated): ISO C 2011
+ - ``gnu11`` or ``gnu1x`` (deprecated): ISO C 2011 with GNU extensions
+ - ``c17`` or ``iso9899:2017``: ISO C 2017
+ - ``gnu17``: ISO C 2017 with GNU extensions
+
+ The default C language standard is ``gnu11``, except on PS4, where it is
+ ``gnu99``.
+
+ Supported options for the C++ language are:
+
+ - ``c++98`` or ``c++03``: ISO C++ 1998 with amendments
+ - ``gnu++98`` or ``gnu++03``: ISO C++ 1998 with amendments and GNU extensions
+ - ``c++11`` or ``c++0x`` (deprecated): ISO C++ 2011 with amendments
+ - ``gnu++11`` or ``gnu++0x`` (deprecated): ISO C++ 2011 with amendments and
+   GNU extensions
+ - ``c++14`` or ``c++1y`` (deprecated): ISO C++ 2014 with amendments
+ - ``gnu++14`` or ``gnu++1y`` (deprecated): ISO C++ 2014 with amendments and
+   GNU extensions
+ - ``c++17`` or ``c++1z`` (deprecated): ISO C++ 2017 with amendments
+ - ``gnu++17`` or ``gnu++1z`` (deprecated): ISO C++ 2017 with amendments and
+   GNU extensions
+ - ``c++2a``: Working draft for ISO C++ 2020
+ - ``gnu++2a``: Working draft for ISO C++ 2020 with GNU extensions
+
+ The default C++ language standard is ``gnu++14``.
+
+ 

[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-07 Thread Michał Górny via Phabricator via cfe-commits
mgorny accepted this revision.
mgorny added a comment.
This revision is now accepted and ready to land.

Works fine, thanks a lot! Note that I haven't tested crossdev or anything 
special, just regular multilib.


Repository:
  rC Clang

https://reviews.llvm.org/D45233



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName

2018-04-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Done.

  ninja -C ~/Dev/llvm/debug unittests/libclang/libclangTests
  ~/Dev/llvm/debug/tools/clang/unittests/libclang/libclangTests


Repository:
  rC Clang

https://reviews.llvm.org/D42893



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName

2018-04-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 141496.
MaskRay added a comment.

Add unittests/libclang/LibclangTest.cpp test


Repository:
  rC Clang

https://reviews.llvm.org/D42893

Files:
  include/clang-c/Index.h
  tools/libclang/CIndex.cpp
  tools/libclang/libclang.exports
  unittests/libclang/LibclangTest.cpp


Index: unittests/libclang/LibclangTest.cpp
===
--- unittests/libclang/LibclangTest.cpp
+++ unittests/libclang/LibclangTest.cpp
@@ -482,6 +482,21 @@
   }
 };
 
+TEST_F(LibclangReparseTest, FileName) {
+  std::string CppName = "main.cpp";
+  WriteFile(CppName, "int main() {}");
+  ClangTU = clang_parseTranslationUnit(Index, CppName.c_str(), nullptr, 0,
+   nullptr, 0, TUFlags);
+  CXFile cxf = clang_getFile(ClangTU, CppName.c_str());
+
+  CXString cxname = clang_getFileName(cxf);
+  ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str()));
+  clang_disposeString(cxname);
+
+  cxname = clang_File_tryGetRealPathName(cxf);
+  ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str()));
+  clang_disposeString(cxname);
+}
 
 TEST_F(LibclangReparseTest, Reparse) {
   const char *HeaderTop = "#ifndef H\n#define H\nstruct Foo { int bar;";
Index: tools/libclang/libclang.exports
===
--- tools/libclang/libclang.exports
+++ tools/libclang/libclang.exports
@@ -46,6 +46,7 @@
 clang_Cursor_getModule
 clang_Cursor_getStorageClass
 clang_File_isEqual
+clang_File_tryGetRealPathName
 clang_Module_getASTFile
 clang_Module_getParent
 clang_Module_getName
Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -4249,6 +4249,14 @@
   return FEnt1->getUniqueID() == FEnt2->getUniqueID();
 }
 
+CXString clang_File_tryGetRealPathName(CXFile SFile) {
+  if (!SFile)
+return cxstring::createNull();
+
+  FileEntry *FEnt = static_cast(SFile);
+  return cxstring::createRef(FEnt->tryGetRealPathName());
+}
+
 
//===--===//
 // CXCursor Operations.
 
//===--===//
Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -424,6 +424,13 @@
  */
 CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2);
 
+/**
+ * \brief Returns the real path name of \c file.
+ *
+ * An empty string may be returned. Use \c clang_getFileName() in that case.
+ */
+CINDEX_LINKAGE CXString clang_File_tryGetRealPathName(CXFile file);
+
 /**
  * @}
  */


Index: unittests/libclang/LibclangTest.cpp
===
--- unittests/libclang/LibclangTest.cpp
+++ unittests/libclang/LibclangTest.cpp
@@ -482,6 +482,21 @@
   }
 };
 
+TEST_F(LibclangReparseTest, FileName) {
+  std::string CppName = "main.cpp";
+  WriteFile(CppName, "int main() {}");
+  ClangTU = clang_parseTranslationUnit(Index, CppName.c_str(), nullptr, 0,
+   nullptr, 0, TUFlags);
+  CXFile cxf = clang_getFile(ClangTU, CppName.c_str());
+
+  CXString cxname = clang_getFileName(cxf);
+  ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str()));
+  clang_disposeString(cxname);
+
+  cxname = clang_File_tryGetRealPathName(cxf);
+  ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str()));
+  clang_disposeString(cxname);
+}
 
 TEST_F(LibclangReparseTest, Reparse) {
   const char *HeaderTop = "#ifndef H\n#define H\nstruct Foo { int bar;";
Index: tools/libclang/libclang.exports
===
--- tools/libclang/libclang.exports
+++ tools/libclang/libclang.exports
@@ -46,6 +46,7 @@
 clang_Cursor_getModule
 clang_Cursor_getStorageClass
 clang_File_isEqual
+clang_File_tryGetRealPathName
 clang_Module_getASTFile
 clang_Module_getParent
 clang_Module_getName
Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -4249,6 +4249,14 @@
   return FEnt1->getUniqueID() == FEnt2->getUniqueID();
 }
 
+CXString clang_File_tryGetRealPathName(CXFile SFile) {
+  if (!SFile)
+return cxstring::createNull();
+
+  FileEntry *FEnt = static_cast(SFile);
+  return cxstring::createRef(FEnt->tryGetRealPathName());
+}
+
 //===--===//
 // CXCursor Operations.
 //===--===//
Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -424,6 +424,13 @@
  */
 CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2);
 
+/**
+ * \

[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName

2018-04-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 141492.
MaskRay added a comment.

Rebase


Repository:
  rC Clang

https://reviews.llvm.org/D42893

Files:
  include/clang-c/Index.h
  tools/libclang/CIndex.cpp
  tools/libclang/libclang.exports


Index: tools/libclang/libclang.exports
===
--- tools/libclang/libclang.exports
+++ tools/libclang/libclang.exports
@@ -46,6 +46,7 @@
 clang_Cursor_getModule
 clang_Cursor_getStorageClass
 clang_File_isEqual
+clang_File_tryGetRealPathName
 clang_Module_getASTFile
 clang_Module_getParent
 clang_Module_getName
Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -4249,6 +4249,14 @@
   return FEnt1->getUniqueID() == FEnt2->getUniqueID();
 }
 
+CXString clang_File_tryGetRealPathName(CXFile SFile) {
+  if (!SFile)
+return cxstring::createNull();
+
+  FileEntry *FEnt = static_cast(SFile);
+  return cxstring::createRef(FEnt->tryGetRealPathName());
+}
+
 
//===--===//
 // CXCursor Operations.
 
//===--===//
Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -424,6 +424,13 @@
  */
 CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2);
 
+/**
+ * \brief Returns the real path name of \c file.
+ *
+ * An empty string may be returned. Use \c clang_getFileName() in that case.
+ */
+CINDEX_LINKAGE CXString clang_File_tryGetRealPathName(CXFile file);
+
 /**
  * @}
  */


Index: tools/libclang/libclang.exports
===
--- tools/libclang/libclang.exports
+++ tools/libclang/libclang.exports
@@ -46,6 +46,7 @@
 clang_Cursor_getModule
 clang_Cursor_getStorageClass
 clang_File_isEqual
+clang_File_tryGetRealPathName
 clang_Module_getASTFile
 clang_Module_getParent
 clang_Module_getName
Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -4249,6 +4249,14 @@
   return FEnt1->getUniqueID() == FEnt2->getUniqueID();
 }
 
+CXString clang_File_tryGetRealPathName(CXFile SFile) {
+  if (!SFile)
+return cxstring::createNull();
+
+  FileEntry *FEnt = static_cast(SFile);
+  return cxstring::createRef(FEnt->tryGetRealPathName());
+}
+
 //===--===//
 // CXCursor Operations.
 //===--===//
Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -424,6 +424,13 @@
  */
 CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2);
 
+/**
+ * \brief Returns the real path name of \c file.
+ *
+ * An empty string may be returned. Use \c clang_getFileName() in that case.
+ */
+CINDEX_LINKAGE CXString clang_File_tryGetRealPathName(CXFile file);
+
 /**
  * @}
  */
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45305: ObjCGNU: Fix empty v3 protocols being emitted two fields short

2018-04-07 Thread David Chisnall via Phabricator via cfe-commits
theraven added a comment.

Isn't it better to test for the correct structure existing in the IR?


Repository:
  rC Clang

https://reviews.llvm.org/D45305



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44580: Sema: allow comparison between blocks & block-compatible objc types

2018-04-07 Thread John McCall via Phabricator via cfe-commits
rjmccall closed this revision.
rjmccall added a comment.

Committed as r329508.


Repository:
  rC Clang

https://reviews.llvm.org/D44580



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r329508 - Allow equality comparisons between block pointers and

2018-04-07 Thread John McCall via cfe-commits
Author: rjmccall
Date: Sat Apr  7 10:42:06 2018
New Revision: 329508

URL: http://llvm.org/viewvc/llvm-project?rev=329508&view=rev
Log:
Allow equality comparisons between block pointers and
block-pointer-compatible ObjC object pointer types.

Patch by Dustin Howett!

Added:
cfe/trunk/test/SemaObjC/block-compare.mm
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=329508&r1=329507&r2=329508&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Apr  7 10:42:06 2018
@@ -10029,6 +10029,19 @@ QualType Sema::CheckCompareOperands(Expr
 RHS = ImpCastExprToType(RHS.get(), LHSType, CK_BitCast);
   return ResultTy;
 }
+
+if (!IsRelational && LHSType->isBlockPointerType() &&
+RHSType->isBlockCompatibleObjCPointerType(Context)) {
+  LHS = ImpCastExprToType(LHS.get(), RHSType,
+  CK_BlockPointerToObjCPointerCast);
+  return ResultTy;
+} else if (!IsRelational &&
+   LHSType->isBlockCompatibleObjCPointerType(Context) &&
+   RHSType->isBlockPointerType()) {
+  RHS = ImpCastExprToType(RHS.get(), LHSType,
+  CK_BlockPointerToObjCPointerCast);
+  return ResultTy;
+}
   }
   if ((LHSType->isAnyPointerType() && RHSType->isIntegerType()) ||
   (LHSType->isIntegerType() && RHSType->isAnyPointerType())) {

Added: cfe/trunk/test/SemaObjC/block-compare.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/block-compare.mm?rev=329508&view=auto
==
--- cfe/trunk/test/SemaObjC/block-compare.mm (added)
+++ cfe/trunk/test/SemaObjC/block-compare.mm Sat Apr  7 10:42:06 2018
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -S -o - -triple i686-windows -verify -fblocks \
+// RUN: -Wno-unused-comparison %s
+
+#pragma clang diagnostic ignored "-Wunused-comparison"
+
+#define nil ((id)nullptr)
+
+@protocol NSObject
+@end
+
+@protocol NSCopying
+@end
+
+@protocol OtherProtocol
+@end
+
+__attribute__((objc_root_class))
+@interface NSObject 
+@end
+
+__attribute__((objc_root_class))
+@interface Test
+@end
+
+int main() {
+  void (^block)() = ^{};
+  NSObject *object;
+  id qualifiedId;
+
+  id poorlyQualified1;
+  Test *objectOfWrongType;
+
+  block == nil;
+  block == object;
+  block == qualifiedId;
+
+  nil == block;
+  object == block;
+  qualifiedId == block;
+
+  // these are still not valid: blocks must be compared with id, NSObject*, or 
a protocol-qualified id
+  // conforming to NSCopying or NSObject.
+
+  block == poorlyQualified1; // expected-error {{invalid operands to binary 
expression ('void (^)()' and 'id')}}
+  block == objectOfWrongType; // expected-error {{invalid operands to binary 
expression ('void (^)()' and 'Test *')}}
+
+  poorlyQualified1 == block; // expected-error {{invalid operands to binary 
expression ('id' and 'void (^)()')}}
+  objectOfWrongType == block; // expected-error {{invalid operands to binary 
expression ('Test *' and 'void (^)()')}}
+
+  return 0;
+}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45305: ObjCGNU: Fix empty v3 protocols being emitted two fields short

2018-04-07 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.

Hmm.  Alright, I guess.


Repository:
  rC Clang

https://reviews.llvm.org/D45305



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45405: [clang-tidy] [modernize-use-auto] Add a threshold for minimal type name length to be replaced with 'auto'

2018-04-07 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis created this revision.
zinovy.nis added reviewers: angelgarcia, malcolm.parsons, alexfh.
zinovy.nis added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, xazax.hun.

The threshold option is 'MinTypeNameLength' with default value '0' which means 
'replace any lengths'.
With MinTypeNameLength = 5 'int'/'bool' and 'const int'/'const bool' will not 
be converted to 'auto',
while 'unsigned' and 'long long int' will be.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45405

Files:
  clang-tidy/modernize/UseAutoCheck.cpp
  clang-tidy/modernize/UseAutoCheck.h
  docs/clang-tidy/checks/modernize-use-auto.rst
  test/clang-tidy/modernize-use-auto-min-type-name-length.cpp

Index: test/clang-tidy/modernize-use-auto-min-type-name-length.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-auto-min-type-name-length.cpp
@@ -0,0 +1,30 @@
+// RUN: %check_clang_tidy %s modernize-use-auto %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-auto.MinTypeNameLength, value: '5'}]}" \
+// RUN:   -- -std=c++11 -frtti
+
+extern int foo();
+
+using VeryVeryVeryLongTypeName = int;
+
+int bar() {
+  int a = static_cast(foo());
+  // strlen('int') = 4 <  5, so skip it, 
+  // even strlen('VeryVeryVeryLongTypeName') > 5.
+
+  unsigned b = static_cast(foo());
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name [modernize-use-auto]
+  // CHECK-FIXES: auto b = static_cast(foo());
+
+  bool c = static_cast(foo());
+  // strlen('bool') = 4 <  5, so skip it.
+
+  const bool c1 = static_cast(foo());
+  // strlen('bool') = 4 <  5, so skip it, even there's a 'const'.
+
+  unsigned long long ull = static_cast(foo());
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name [modernize-use-auto]
+  // CHECK-FIXES: auto ull = static_cast(foo());
+
+  return 1;
+}
+
Index: docs/clang-tidy/checks/modernize-use-auto.rst
===
--- docs/clang-tidy/checks/modernize-use-auto.rst
+++ docs/clang-tidy/checks/modernize-use-auto.rst
@@ -194,3 +194,23 @@
   // RemoveStars = 1
 
   auto my_first_pointer = new TypeName, my_second_pointer = new TypeName;
+
+.. option:: MinTypeNameLength
+
+   If the option is set to any positive non-zero integer, the check will
+   neither warn nor fix type names having a length less than the option value.
+   The option affects expressions only, not iterators.
+
+.. code-block:: c++
+
+  // MinTypeNameLength = 0
+
+  int a = static_cast(foo());// ---> auto a = ...
+  bool b = new bool;  // ---> auto b = ...
+  unsigned c = static_cast(foo());  // ---> auto c = ...
+
+  // MinTypeNameLength = 8
+
+  int a = static_cast(foo());// ---> int  a = ...
+  bool b = new bool;  // ---> bool b = ...
+  unsigned c = static_cast(foo());  // ---> auto c = ...
Index: clang-tidy/modernize/UseAutoCheck.h
===
--- clang-tidy/modernize/UseAutoCheck.h
+++ clang-tidy/modernize/UseAutoCheck.h
@@ -29,6 +29,7 @@
llvm::function_ref GetType,
StringRef Message);
 
+  const unsigned int MinTypeNameLength;
   const bool RemoveStars;
 };
 
Index: clang-tidy/modernize/UseAutoCheck.cpp
===
--- clang-tidy/modernize/UseAutoCheck.cpp
+++ clang-tidy/modernize/UseAutoCheck.cpp
@@ -286,10 +286,11 @@
 } // namespace
 
 UseAutoCheck::UseAutoCheck(StringRef Name, ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context),
-  RemoveStars(Options.get("RemoveStars", 0)) {}
+: ClangTidyCheck(Name, Context), RemoveStars(Options.get("RemoveStars", 0)),
+  MinTypeNameLength(Options.get("MinTypeNameLength", 0)) {}
 
 void UseAutoCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "MinTypeNameLength", MinTypeNameLength);
   Options.store(Opts, "RemoveStars", RemoveStars ? 1 : 0);
 }
 
@@ -414,6 +415,13 @@
 Loc = Loc.getNextTypeLoc();
   }
   SourceRange Range(Loc.getSourceRange());
+
+  if (MinTypeNameLength != 0 &&
+  Lexer::getSourceText(CharSourceRange::getTokenRange(Range),
+   Context->getSourceManager(), Context->getLangOpts())
+  .size() < MinTypeNameLength)
+return;
+
   auto Diag = diag(Range.getBegin(), Message);
 
   // Space after 'auto' to handle cases where the '*' in the pointer type is
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName

2018-04-07 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe added a comment.

Tests for libclang are in clang/unittests/libclang/LibclangTest.cpp

Given the surgical nature of this change I hope it will be quick to add a test.


Repository:
  rC Clang

https://reviews.llvm.org/D42893



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r329495 - [clang-tidy] Fix compilation for MSVS@PSP4 for ParentVirtualCallCheck.cpp

2018-04-07 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Sat Apr  7 04:22:01 2018
New Revision: 329495

URL: http://llvm.org/viewvc/llvm-project?rev=329495&view=rev
Log:
[clang-tidy] Fix compilation for MSVS@PSP4 for ParentVirtualCallCheck.cpp

There's an error for PSP4 platform only: 
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\algorithm(95): 
error C2719: '_Pred': formal parameter with requested alignment of 8 won't be 
aligned


Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp?rev=329495&r1=329494&r2=329495&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp Sat 
Apr  7 04:22:01 2018
@@ -27,14 +27,13 @@ static bool isParentOf(const CXXRecordDe
const CXXRecordDecl &ThisClass) {
   if (Parent.getCanonicalDecl() == ThisClass.getCanonicalDecl())
 return true;
-  const auto ClassIter = std::find_if(
-  ThisClass.bases().begin(), ThisClass.bases().end(),
-  [=](const CXXBaseSpecifier &Base) {
-auto *BaseDecl = Base.getType()->getAsCXXRecordDecl();
-assert(BaseDecl);
-return Parent.getCanonicalDecl() == BaseDecl->getCanonicalDecl();
-  });
-  return ClassIter != ThisClass.bases_end();
+  for (const CXXBaseSpecifier &Base : ThisClass.bases()) {
+auto *BaseDecl = Base.getType()->getAsCXXRecordDecl();
+assert(BaseDecl);
+if (Parent.getCanonicalDecl() == BaseDecl->getCanonicalDecl())
+  return true;
+  }
+  return false;
 }
 
 static BasesVector getParentsByGrandParent(const CXXRecordDecl &GrandParent,


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45403: Make [[maybe_unused]] work with static data members

2018-04-07 Thread S. B. Tam via Phabricator via cfe-commits
cpplearner added inline comments.



Comment at: test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp:5
   int I [[maybe_unused]];
-  static int SI [[maybe_unused]]; // expected-warning {{'maybe_unused' 
attribute only applies to variables, functions, methods, types, enumerations, 
enumerators, labels, and non-static data members}}
+  static int SI [[maybe_unused]];
 };

lebedev.ri wrote:
> As the code comment noted, 
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf, page 199:
> ```
> 2 The attribute may be applied to the declaration of a class, a typedef-name, 
> a variable, a **non-static** data
> member, a function, an enumeration, or an enumerator.
> ```
That section says that [[maybe_unused]] can be applied to a non-static data 
member, which doesn't mean it can't be applied to a static data member.

And I'm arguing that since a static data member is a variable, 
[dcl.attr.unused]p2 actually allows [[maybe_unused]] to be applied to a static 
data member.


Repository:
  rC Clang

https://reviews.llvm.org/D45403



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-07 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

I'm sorry, I see the problem now — the diff generated by Phabricator does not 
include the empty files x_x (seriously, this thing keeps surprising me in how 
broken it could be). I'm going to try again with correct file set tonight or 
tomorrow. If you could send the complete patch (preferably -p1 if you have one) 
to mgorny AT gentoo.org, that would also be helpful.


Repository:
  rC Clang

https://reviews.llvm.org/D45233



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45403: Make [[maybe_unused]] work with static data members

2018-04-07 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp:5
   int I [[maybe_unused]];
-  static int SI [[maybe_unused]]; // expected-warning {{'maybe_unused' 
attribute only applies to variables, functions, methods, types, enumerations, 
enumerators, labels, and non-static data members}}
+  static int SI [[maybe_unused]];
 };

As the code comment noted, 
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf, page 199:
```
2 The attribute may be applied to the declaration of a class, a typedef-name, a 
variable, a **non-static** data
member, a function, an enumeration, or an enumerator.
```


Repository:
  rC Clang

https://reviews.llvm.org/D45403



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-04-07 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC329493: [Sema] Extend -Wself-assign and -Wself-assign-field 
to warn on overloaded self… (authored by lebedevri, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D44883

Files:
  docs/ReleaseNotes.rst
  lib/Sema/SemaExpr.cpp
  test/SemaCXX/member-init.cpp
  test/SemaCXX/warn-self-assign-builtin.cpp
  test/SemaCXX/warn-self-assign-field-builtin.cpp
  test/SemaCXX/warn-self-assign-field-overloaded.cpp
  test/SemaCXX/warn-self-assign-overloaded.cpp
  test/SemaCXX/warn-self-assign.cpp

Index: test/SemaCXX/warn-self-assign-builtin.cpp
===
--- test/SemaCXX/warn-self-assign-builtin.cpp
+++ test/SemaCXX/warn-self-assign-builtin.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign -verify %s
+
+void f() {
+  int a = 42, b = 42;
+  a = a; // expected-warning{{explicitly assigning}}
+  b = b; // expected-warning{{explicitly assigning}}
+  a = b;
+  b = a = b;
+  a = a = a; // expected-warning{{explicitly assigning}}
+  a = b = b = a;
+
+  a *= a;
+  a /= a;
+  a %= a;
+  a += a;
+  a -= a;
+  a <<= a;
+  a >>= a;
+  a &= a; // expected-warning {{explicitly assigning}}
+  a |= a; // expected-warning {{explicitly assigning}}
+  a ^= a;
+}
+
+// Dummy type.
+struct S {};
+
+void false_positives() {
+#define OP =
+#define LHS a
+#define RHS a
+  int a = 42;
+  // These shouldn't warn due to the use of the preprocessor.
+  a OP a;
+  LHS = a;
+  a = RHS;
+  LHS OP RHS;
+#undef OP
+#undef LHS
+#undef RHS
+
+  // A way to silence the warning.
+  a = (int &)a;
+
+  // Volatile stores aren't side-effect free.
+  volatile int vol_a;
+  vol_a = vol_a;
+  volatile int &vol_a_ref = vol_a;
+  vol_a_ref = vol_a_ref;
+}
+
+// Do not diagnose self-assigment in an unevaluated context
+void false_positives_unevaluated_ctx(int a) noexcept(noexcept(a = a)) // expected-warning {{expression with side effects has no effect in an unevaluated context}}
+{
+  decltype(a = a) b = a;  // expected-warning {{expression with side effects has no effect in an unevaluated context}}
+  static_assert(noexcept(a = a), ""); // expected-warning {{expression with side effects has no effect in an unevaluated context}}
+  static_assert(sizeof(a = a), "");   // expected-warning {{expression with side effects has no effect in an unevaluated context}}
+}
+
+template 
+void g() {
+  T a;
+  a = a; // expected-warning{{explicitly assigning}}
+}
+void instantiate() {
+  g();
+  g();
+}
Index: test/SemaCXX/warn-self-assign-field-overloaded.cpp
===
--- test/SemaCXX/warn-self-assign-field-overloaded.cpp
+++ test/SemaCXX/warn-self-assign-field-overloaded.cpp
@@ -0,0 +1,162 @@
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign-field -DDUMMY -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign-field -DV0 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign-field -DV1 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign-field -DV2 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign-field -DV3 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign-field -DV4 -verify %s
+
+#ifdef DUMMY
+struct S {};
+#else
+struct S {
+#if defined(V0)
+  S() = default;
+#elif defined(V1)
+  S &operator=(const S &) = default;
+#elif defined(V2)
+  S &operator=(S &) = default;
+#elif defined(V3)
+  S &operator=(const S &);
+#elif defined(V4)
+  S &operator=(S &);
+#else
+#error Define something!
+#endif
+  S &operator*=(const S &);
+  S &operator/=(const S &);
+  S &operator%=(const S &);
+  S &operator+=(const S &);
+  S &operator-=(const S &);
+  S &operator<<=(const S &);
+  S &operator>>=(const S &);
+  S &operator&=(const S &);
+  S &operator|=(const S &);
+  S &operator^=(const S &);
+  S &operator=(const volatile S &) volatile;
+};
+#endif
+struct C {
+  S a;
+  S b;
+
+  void f() {
+a = a; // expected-warning {{assigning field to itself}}
+b = b; // expected-warning {{assigning field to itself}}
+a = b;
+
+this->a = a;   // expected-warning {{assigning field to itself}}
+this->b = b;   // expected-warning {{assigning field to itself}}
+a = this->a;   // expected-warning {{assigning field to itself}}
+b = this->b;   // expected-warning {{assigning field to itself}}
+this->a = this->a; // expected-warning {{assigning field to itself}}
+this->b = this->b; // expected-warning {{assigning field to itself}}
+
+a = b;
+a = this->b;
+this->a = b;
+this->a = this->b;
+
+#ifndef DUMMY
+a *= a;
+a /= a; // expected-warning {{assigning field to itself}}
+a %= a; // expected-warning {{assigning field to itself}}
+a += a;
+a -= a; // expected-warning {{assigning field to itself}}
+a <<= a;
+a >>= a;
+a &= a; // expected-warning {{assigning field to itself}}
+a |= a; // expected-warning {{assigning field to its

[PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-04-07 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL329493: [Sema] Extend -Wself-assign and -Wself-assign-field 
to warn on overloaded self… (authored by lebedevri, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44883?vs=140787&id=141484#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44883

Files:
  cfe/trunk/docs/ReleaseNotes.rst
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/test/SemaCXX/member-init.cpp
  cfe/trunk/test/SemaCXX/warn-self-assign-builtin.cpp
  cfe/trunk/test/SemaCXX/warn-self-assign-field-builtin.cpp
  cfe/trunk/test/SemaCXX/warn-self-assign-field-overloaded.cpp
  cfe/trunk/test/SemaCXX/warn-self-assign-overloaded.cpp
  cfe/trunk/test/SemaCXX/warn-self-assign.cpp

Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -10701,12 +10701,34 @@
 static void CheckIdentityFieldAssignment(Expr *LHSExpr, Expr *RHSExpr,
  SourceLocation Loc,
  Sema &Sema) {
+  if (Sema.inTemplateInstantiation())
+return;
+  if (Sema.isUnevaluatedContext())
+return;
+  if (Loc.isInvalid() || Loc.isMacroID())
+return;
+  if (LHSExpr->getExprLoc().isMacroID() || RHSExpr->getExprLoc().isMacroID())
+return;
+
   // C / C++ fields
   MemberExpr *ML = dyn_cast(LHSExpr);
   MemberExpr *MR = dyn_cast(RHSExpr);
-  if (ML && MR && ML->getMemberDecl() == MR->getMemberDecl()) {
-if (isa(ML->getBase()) && isa(MR->getBase()))
-  Sema.Diag(Loc, diag::warn_identity_field_assign) << 0;
+  if (ML && MR) {
+if (!(isa(ML->getBase()) && isa(MR->getBase(
+  return;
+const ValueDecl *LHSDecl =
+cast(ML->getMemberDecl()->getCanonicalDecl());
+const ValueDecl *RHSDecl =
+cast(MR->getMemberDecl()->getCanonicalDecl());
+if (LHSDecl != RHSDecl)
+  return;
+if (LHSDecl->getType().isVolatileQualified())
+  return;
+if (const ReferenceType *RefTy = LHSDecl->getType()->getAs())
+  if (RefTy->getPointeeType().isVolatileQualified())
+return;
+
+Sema.Diag(Loc, diag::warn_identity_field_assign) << 0;
   }
 
   // Objective-C instance variables
@@ -11460,12 +11482,13 @@
 }
 
 /// DiagnoseSelfAssignment - Emits a warning if a value is assigned to itself.
-/// This warning is only emitted for builtin assignment operations. It is also
-/// suppressed in the event of macro expansions.
+/// This warning suppressed in the event of macro expansions.
 static void DiagnoseSelfAssignment(Sema &S, Expr *LHSExpr, Expr *RHSExpr,
SourceLocation OpLoc) {
   if (S.inTemplateInstantiation())
 return;
+  if (S.isUnevaluatedContext())
+return;
   if (OpLoc.isInvalid() || OpLoc.isMacroID())
 return;
   LHSExpr = LHSExpr->IgnoreParenImpCasts();
@@ -12080,6 +12103,21 @@
 static ExprResult BuildOverloadedBinOp(Sema &S, Scope *Sc, SourceLocation OpLoc,
BinaryOperatorKind Opc,
Expr *LHS, Expr *RHS) {
+  switch (Opc) {
+  case BO_Assign:
+  case BO_DivAssign:
+  case BO_RemAssign:
+  case BO_SubAssign:
+  case BO_AndAssign:
+  case BO_OrAssign:
+  case BO_XorAssign:
+DiagnoseSelfAssignment(S, LHS, RHS, OpLoc);
+CheckIdentityFieldAssignment(LHS, RHS, OpLoc, S);
+break;
+  default:
+break;
+  }
+
   // Find all of the overloaded operators visible from this
   // point. We perform both an operator-name lookup from the local
   // scope and an argument-dependent lookup based on the types of
Index: cfe/trunk/docs/ReleaseNotes.rst
===
--- cfe/trunk/docs/ReleaseNotes.rst
+++ cfe/trunk/docs/ReleaseNotes.rst
@@ -59,6 +59,12 @@
   ``-Wno-c++98-compat-extra-semi``, so if you want that diagnostic, you need
   to explicitly re-enable it (e.g. by appending ``-Wextra-semi``).
 
+- ``-Wself-assign`` and ``-Wself-assign-field`` were extended to diagnose
+  self-assignment operations using overloaded operators (i.e. classes).
+  If you are doing such an assignment intentionally, e.g. in a unit test for
+  a data structure, the warning can be suppressed by adding ``*&`` to the
+  right-hand side or casting it to the appropriate reference type.
+
 Non-comprehensive list of changes in this release
 -
 
Index: cfe/trunk/test/SemaCXX/warn-self-assign-builtin.cpp
===
--- cfe/trunk/test/SemaCXX/warn-self-assign-builtin.cpp
+++ cfe/trunk/test/SemaCXX/warn-self-assign-builtin.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign -verify %s
+
+void f() {
+  int a = 42, b = 42;
+  a = a; // expected-warning{{explicitly assigning}}
+  b = b; // expected-warning{{explicitly

[PATCH] D45403: Make [[maybe_unused]] work with static data members

2018-04-07 Thread S. B. Tam via Phabricator via cfe-commits
cpplearner created this revision.
cpplearner added reviewers: aaron.ballman, rsmith.
Herald added a subscriber: cfe-commits.

IIUC a static data member is a variable, so [[maybe_unused]] should be allowed 
to apply to a static data member.


Repository:
  rC Clang

https://reviews.llvm.org/D45403

Files:
  lib/Sema/SemaDeclAttr.cpp
  test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp


Index: test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp
===
--- test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp
+++ test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp
@@ -2,7 +2,7 @@
 
 struct [[maybe_unused]] S {
   int I [[maybe_unused]];
-  static int SI [[maybe_unused]]; // expected-warning {{'maybe_unused' 
attribute only applies to variables, functions, methods, types, enumerations, 
enumerators, labels, and non-static data members}}
+  static int SI [[maybe_unused]];
 };
 
 enum [[maybe_unused]] E1 {
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -2042,16 +2042,6 @@
 static void handleUnusedAttr(Sema &S, Decl *D, const AttributeList &AL) {
   bool IsCXX17Attr = AL.isCXX11Attribute() && !AL.getScopeName();
 
-  if (IsCXX17Attr && isa(D)) {
-// The C++17 spelling of this attribute cannot be applied to a static data
-// member per [dcl.attr.unused]p2.
-if (cast(D)->isStaticDataMember()) {
-  S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
-  << AL.getName() << ExpectedForMaybeUnused;
-  return;
-}
-  }
-
   // If this is spelled as the standard C++17 attribute, but not in C++17, warn
   // about using it as an extension.
   if (!S.getLangOpts().CPlusPlus17 && IsCXX17Attr)


Index: test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp
===
--- test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp
+++ test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp
@@ -2,7 +2,7 @@
 
 struct [[maybe_unused]] S {
   int I [[maybe_unused]];
-  static int SI [[maybe_unused]]; // expected-warning {{'maybe_unused' attribute only applies to variables, functions, methods, types, enumerations, enumerators, labels, and non-static data members}}
+  static int SI [[maybe_unused]];
 };
 
 enum [[maybe_unused]] E1 {
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -2042,16 +2042,6 @@
 static void handleUnusedAttr(Sema &S, Decl *D, const AttributeList &AL) {
   bool IsCXX17Attr = AL.isCXX11Attribute() && !AL.getScopeName();
 
-  if (IsCXX17Attr && isa(D)) {
-// The C++17 spelling of this attribute cannot be applied to a static data
-// member per [dcl.attr.unused]p2.
-if (cast(D)->isStaticDataMember()) {
-  S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
-  << AL.getName() << ExpectedForMaybeUnused;
-  return;
-}
-  }
-
   // If this is spelled as the standard C++17 attribute, but not in C++17, warn
   // about using it as an extension.
   if (!S.getLangOpts().CPlusPlus17 && IsCXX17Attr)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r329493 - [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-04-07 Thread Roman Lebedev via cfe-commits
Author: lebedevri
Date: Sat Apr  7 03:39:21 2018
New Revision: 329493

URL: http://llvm.org/viewvc/llvm-project?rev=329493&view=rev
Log:
[Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded 
self-assignment (classes)

Summary:
This has just bit me, so i though it would be nice to avoid that next time :)
Motivational case:
  https://godbolt.org/g/cq9UNk
Basically, it's likely to happen if you don't like shadowing issues,
and use `-Wshadow` and friends. And it won't be diagnosed by clang.

The reason is, these self-assign diagnostics only work for builtin assignment
operators. Which makes sense, one could have a very special operator=,
that does something unusual in case of self-assignment,
so it may make sense to not warn on that.

But while it may be intentional in some cases, it may be a bug in other cases,
so it would be really great to have some diagnostic about it...

Reviewers: aaron.ballman, rsmith, rtrieu, nikola, rjmccall, dblaikie

Reviewed By: rjmccall

Subscribers: EricWF, lebedev.ri, thakis, Quuxplusone, cfe-commits

Differential Revision: https://reviews.llvm.org/D44883

Added:
cfe/trunk/test/SemaCXX/warn-self-assign-builtin.cpp
cfe/trunk/test/SemaCXX/warn-self-assign-field-builtin.cpp
cfe/trunk/test/SemaCXX/warn-self-assign-field-overloaded.cpp
cfe/trunk/test/SemaCXX/warn-self-assign-overloaded.cpp
Removed:
cfe/trunk/test/SemaCXX/warn-self-assign.cpp
Modified:
cfe/trunk/docs/ReleaseNotes.rst
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaCXX/member-init.cpp

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=329493&r1=329492&r2=329493&view=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Sat Apr  7 03:39:21 2018
@@ -59,6 +59,12 @@ Improvements to Clang's diagnostics
   ``-Wno-c++98-compat-extra-semi``, so if you want that diagnostic, you need
   to explicitly re-enable it (e.g. by appending ``-Wextra-semi``).
 
+- ``-Wself-assign`` and ``-Wself-assign-field`` were extended to diagnose
+  self-assignment operations using overloaded operators (i.e. classes).
+  If you are doing such an assignment intentionally, e.g. in a unit test for
+  a data structure, the warning can be suppressed by adding ``*&`` to the
+  right-hand side or casting it to the appropriate reference type.
+
 Non-comprehensive list of changes in this release
 -
 

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=329493&r1=329492&r2=329493&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Apr  7 03:39:21 2018
@@ -10701,12 +10701,34 @@ static bool CheckForModifiableLvalue(Exp
 static void CheckIdentityFieldAssignment(Expr *LHSExpr, Expr *RHSExpr,
  SourceLocation Loc,
  Sema &Sema) {
+  if (Sema.inTemplateInstantiation())
+return;
+  if (Sema.isUnevaluatedContext())
+return;
+  if (Loc.isInvalid() || Loc.isMacroID())
+return;
+  if (LHSExpr->getExprLoc().isMacroID() || RHSExpr->getExprLoc().isMacroID())
+return;
+
   // C / C++ fields
   MemberExpr *ML = dyn_cast(LHSExpr);
   MemberExpr *MR = dyn_cast(RHSExpr);
-  if (ML && MR && ML->getMemberDecl() == MR->getMemberDecl()) {
-if (isa(ML->getBase()) && isa(MR->getBase()))
-  Sema.Diag(Loc, diag::warn_identity_field_assign) << 0;
+  if (ML && MR) {
+if (!(isa(ML->getBase()) && isa(MR->getBase(
+  return;
+const ValueDecl *LHSDecl =
+cast(ML->getMemberDecl()->getCanonicalDecl());
+const ValueDecl *RHSDecl =
+cast(MR->getMemberDecl()->getCanonicalDecl());
+if (LHSDecl != RHSDecl)
+  return;
+if (LHSDecl->getType().isVolatileQualified())
+  return;
+if (const ReferenceType *RefTy = 
LHSDecl->getType()->getAs())
+  if (RefTy->getPointeeType().isVolatileQualified())
+return;
+
+Sema.Diag(Loc, diag::warn_identity_field_assign) << 0;
   }
 
   // Objective-C instance variables
@@ -11460,12 +11482,13 @@ static inline UnaryOperatorKind ConvertT
 }
 
 /// DiagnoseSelfAssignment - Emits a warning if a value is assigned to itself.
-/// This warning is only emitted for builtin assignment operations. It is also
-/// suppressed in the event of macro expansions.
+/// This warning suppressed in the event of macro expansions.
 static void DiagnoseSelfAssignment(Sema &S, Expr *LHSExpr, Expr *RHSExpr,
SourceLocation OpLoc) {
   if (S.inTemplateInstantiation())
 return;
+  if (S.isUnevaluatedContext())
+return;
   if (OpLoc.isInvalid() || OpLoc.isMacroID())
 return;
   LHSExpr = LHSExpr->IgnoreParenIm

[PATCH] D45128: [libcxx][test] Silence -Wself-assign diagnostics

2018-04-07 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCXX329490: [libcxx][test] Silence -Wself-assign diagnostics 
(authored by lebedevri, committed by ).

Repository:
  rCXX libc++

https://reviews.llvm.org/D45128

Files:
  test/std/utilities/any/any.class/any.assign/copy.pass.cpp
  
test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp


Index: test/std/utilities/any/any.class/any.assign/copy.pass.cpp
===
--- test/std/utilities/any/any.class/any.assign/copy.pass.cpp
+++ test/std/utilities/any/any.class/any.assign/copy.pass.cpp
@@ -102,7 +102,7 @@
 // empty
 {
 any a;
-a = a;
+a = (any &)a;
 assertEmpty(a);
 assert(globalMemCounter.checkOutstandingNewEq(0));
 }
@@ -112,7 +112,7 @@
 any a((small(1)));
 assert(small::count == 1);
 
-a = a;
+a = (any &)a;
 
 assert(small::count == 1);
 assertContains(a, 1);
@@ -125,7 +125,7 @@
 any a(large(1));
 assert(large::count == 1);
 
-a = a;
+a = (any &)a;
 
 assert(large::count == 1);
 assertContains(a, 1);
Index: 
test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp
===
--- 
test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp
+++ 
test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp
@@ -92,28 +92,28 @@
   {
 typedef std::function Func;
 Func f = g0;
-Func& fr = (f = f);
+Func& fr = (f = (Func &)f);
 assert(&fr == &f);
 assert(*f.target() == g0);
   }
   {
 typedef std::function Func;
 Func f = g;
-Func& fr = (f = f);
+Func& fr = (f = (Func &)f);
 assert(&fr == &f);
 assert(*f.target() == g);
   }
   {
 typedef std::function Func;
 Func f = g2;
-Func& fr = (f = f);
+Func& fr = (f = (Func &)f);
 assert(&fr == &f);
 assert(*f.target() == g2);
   }
   {
 typedef std::function Func;
 Func f = g3;
-Func& fr = (f = f);
+Func& fr = (f = (Func &)f);
 assert(&fr == &f);
 assert(*f.target() == g3);
   }


Index: test/std/utilities/any/any.class/any.assign/copy.pass.cpp
===
--- test/std/utilities/any/any.class/any.assign/copy.pass.cpp
+++ test/std/utilities/any/any.class/any.assign/copy.pass.cpp
@@ -102,7 +102,7 @@
 // empty
 {
 any a;
-a = a;
+a = (any &)a;
 assertEmpty(a);
 assert(globalMemCounter.checkOutstandingNewEq(0));
 }
@@ -112,7 +112,7 @@
 any a((small(1)));
 assert(small::count == 1);
 
-a = a;
+a = (any &)a;
 
 assert(small::count == 1);
 assertContains(a, 1);
@@ -125,7 +125,7 @@
 any a(large(1));
 assert(large::count == 1);
 
-a = a;
+a = (any &)a;
 
 assert(large::count == 1);
 assertContains(a, 1);
Index: test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp
===
--- test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp
+++ test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp
@@ -92,28 +92,28 @@
   {
 typedef std::function Func;
 Func f = g0;
-Func& fr = (f = f);
+Func& fr = (f = (Func &)f);
 assert(&fr == &f);
 assert(*f.target() == g0);
   }
   {
 typedef std::function Func;
 Func f = g;
-Func& fr = (f = f);
+Func& fr = (f = (Func &)f);
 assert(&fr == &f);
 assert(*f.target() == g);
   }
   {
 typedef std::function Func;
 Func f = g2;
-Func& fr = (f = f);
+Func& fr = (f = (Func &)f);
 assert(&fr == &f);
 assert(*f.target() == g2);
   }
   {
 typedef std::function Func;
 Func f = g3;
-Func& fr = (f = f);
+Func& fr = (f = (Func &)f);
 assert(&fr == &f);
 assert(*f.target() == g3);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r329490 - [libcxx][test] Silence -Wself-assign diagnostics

2018-04-07 Thread Roman Lebedev via cfe-commits
Author: lebedevri
Date: Sat Apr  7 03:36:03 2018
New Revision: 329490

URL: http://llvm.org/viewvc/llvm-project?rev=329490&view=rev
Log:
[libcxx][test] Silence -Wself-assign diagnostics

Summary:
D44883 extends -Wself-assign to also work on C++ classes.
These new warnings pop up in the test suite, so they have to be silenced.

Please refer to the D45082 for disscussion on whether this is the right way to 
solve this.

Testing: `ninja check-libcxx check-libcxxabi` in stage-2 build.

Reviewers: mclow.lists, EricWF

Reviewed By: EricWF

Subscribers: Quuxplusone, cfe-commits

Differential Revision: https://reviews.llvm.org/D45128

Modified:
libcxx/trunk/test/std/utilities/any/any.class/any.assign/copy.pass.cpp

libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp

Modified: libcxx/trunk/test/std/utilities/any/any.class/any.assign/copy.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/any/any.class/any.assign/copy.pass.cpp?rev=329490&r1=329489&r2=329490&view=diff
==
--- libcxx/trunk/test/std/utilities/any/any.class/any.assign/copy.pass.cpp 
(original)
+++ libcxx/trunk/test/std/utilities/any/any.class/any.assign/copy.pass.cpp Sat 
Apr  7 03:36:03 2018
@@ -102,7 +102,7 @@ void test_copy_assign_self() {
 // empty
 {
 any a;
-a = a;
+a = (any &)a;
 assertEmpty(a);
 assert(globalMemCounter.checkOutstandingNewEq(0));
 }
@@ -112,7 +112,7 @@ void test_copy_assign_self() {
 any a((small(1)));
 assert(small::count == 1);
 
-a = a;
+a = (any &)a;
 
 assert(small::count == 1);
 assertContains(a, 1);
@@ -125,7 +125,7 @@ void test_copy_assign_self() {
 any a(large(1));
 assert(large::count == 1);
 
-a = a;
+a = (any &)a;
 
 assert(large::count == 1);
 assertContains(a, 1);

Modified: 
libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp?rev=329490&r1=329489&r2=329490&view=diff
==
--- 
libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp
 Sat Apr  7 03:36:03 2018
@@ -92,28 +92,28 @@ int main() {
   {
 typedef std::function Func;
 Func f = g0;
-Func& fr = (f = f);
+Func& fr = (f = (Func &)f);
 assert(&fr == &f);
 assert(*f.target() == g0);
   }
   {
 typedef std::function Func;
 Func f = g;
-Func& fr = (f = f);
+Func& fr = (f = (Func &)f);
 assert(&fr == &f);
 assert(*f.target() == g);
   }
   {
 typedef std::function Func;
 Func f = g2;
-Func& fr = (f = f);
+Func& fr = (f = (Func &)f);
 assert(&fr == &f);
 assert(*f.target() == g2);
   }
   {
 typedef std::function Func;
 Func f = g3;
-Func& fr = (f = f);
+Func& fr = (f = (Func &)f);
 assert(&fr == &f);
 assert(*f.target() == g3);
   }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45212: [HIP] Let CUDA toolchain support HIP language mode and amdgpu

2018-04-07 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

Can this revision be split further? The summary mentions many things that might 
make up multiple independent changes...




Comment at: lib/Driver/ToolChains/Cuda.cpp:263
+// HIP needs c++11.
+CC1Args.push_back("-std=c++11");
+// Skip CUDA includes for HIP.

Will this override the user's value, e.g. `-std=c++14`?


https://reviews.llvm.org/D45212



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45401: Fix 31480 - warn more aggressively when assignments get used as a boolean values

2018-04-07 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Test?


https://reviews.llvm.org/D45401



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName

2018-04-07 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe added a comment.

I’ll see if I can find a suitable location for a test.


Repository:
  rC Clang

https://reviews.llvm.org/D42893



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits