r326062 - [www] Update link to analyzer's "Building a Checker in 24 hours" video

2018-02-25 Thread Devin Coughlin via cfe-commits
Author: dcoughlin
Date: Sun Feb 25 16:39:25 2018
New Revision: 326062

URL: http://llvm.org/viewvc/llvm-project?rev=326062=rev
Log:
[www] Update link to analyzer's "Building a Checker in 24 hours" video

The video is now uploaded to YouTube.

Modified:
cfe/trunk/www/analyzer/alpha_checks.html
cfe/trunk/www/analyzer/checker_dev_manual.html
cfe/trunk/www/analyzer/open_projects.html

Modified: cfe/trunk/www/analyzer/alpha_checks.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/www/analyzer/alpha_checks.html?rev=326062=326061=326062=diff
==
--- cfe/trunk/www/analyzer/alpha_checks.html (original)
+++ cfe/trunk/www/analyzer/alpha_checks.html Sun Feb 25 16:39:25 2018
@@ -800,7 +800,7 @@ Check for misuses of stream APIs:
 fclose(demo checker, the subject of the demo
 (http://llvm.org/devmtg/2012-11/Zaks-Rose-Checker24Hours.pdf;>Slides
-,http://llvm.org/devmtg/2012-11/videos/Zaks-Rose-Checker24Hours.mp4;>Video)
 
+,https://youtu.be/kdxlsP5QVPw;>Video)
 by Anna Zaks and Jordan Rose presented at the http://llvm.org/devmtg/2012-11/;>
 2012 LLVM Developers' Meeting).
 

Modified: cfe/trunk/www/analyzer/checker_dev_manual.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/www/analyzer/checker_dev_manual.html?rev=326062=326061=326062=diff
==
--- cfe/trunk/www/analyzer/checker_dev_manual.html (original)
+++ cfe/trunk/www/analyzer/checker_dev_manual.html Sun Feb 25 16:39:25 2018
@@ -23,7 +23,7 @@ relies on a set of checkers to implement
 constructing specific bug reports. Anyone who is interested in implementing 
their own 
 checker, should check out the Building a Checker in 24 Hours talk 
 (http://llvm.org/devmtg/2012-11/Zaks-Rose-Checker24Hours.pdf;>slides
- http://llvm.org/devmtg/2012-11/videos/Zaks-Rose-Checker24Hours.mp4;>video)
 
+ https://youtu.be/kdxlsP5QVPw;>video)
 and refer to this page for additional information on writing a checker. The 
static analyzer is a 
 part of the Clang project, so consult http://clang.llvm.org/hacking.html;>Hacking on Clang 
 and http://llvm.org/docs/ProgrammersManual.html;>LLVM Programmer's 
Manual 
@@ -696,7 +696,7 @@ href="http://llvm.org/devmtg/2012-11;>No
 meeting. Describes the construction of SimpleStreamChecker. http://llvm.org/devmtg/2012-11/Zaks-Rose-Checker24Hours.pdf;>Slides
 and http://llvm.org/devmtg/2012-11/videos/Zaks-Rose-Checker24Hours.mp4;>video
+href="https://youtu.be/kdxlsP5QVPw;>video
 are available.
 
 

Modified: cfe/trunk/www/analyzer/open_projects.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/www/analyzer/open_projects.html?rev=326062=326061=326062=diff
==
--- cfe/trunk/www/analyzer/open_projects.html (original)
+++ cfe/trunk/www/analyzer/open_projects.html Sun Feb 25 16:39:25 2018
@@ -147,7 +147,7 @@ mailing list to notify other members
 A SimpleStreamChecker has been presented in the Building a Checker in 
24 
 Hours talk 
 (http://llvm.org/devmtg/2012-11/Zaks-Rose-Checker24Hours.pdf;>slides
-http://llvm.org/devmtg/2012-11/videos/Zaks-Rose-Checker24Hours.mp4;>video).
 
+https://youtu.be/kdxlsP5QVPw;>video).
 We need to implement a production version of the checker with richer set 
of 
 APIs and evaluate it by running on real codebases. 
 (Difficulty: Easy)


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


[PATCH] D42644: [asan] Intercept std::rethrow_exception indirectly.

2018-02-25 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added inline comments.
This revision is now accepted and ready to land.



Comment at: test/asan/TestCases/intercept-rethrow-exception.cc:48
+  // memcpy is intercepted by asan which performs checks on src and dst
+  using T = int[1000];
+  T x {};

You can include #include 
and use __asan_region_is_poisoned


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D42644



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


[PATCH] D43606: [Driver] Add SafeStack to a map of incompatible sanitizers

2018-02-25 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Driver/SanitizerArgs.cpp:384
+KernelAddress | Efficiency),
+  std::make_pair(SafeStack, Address | HWAddress | Leak | Thread | Memory |
+KernelAddress | Efficiency)};

I guess we check only one direction.
E.g. we have std::make_pair(Address, Thread but no std::make_pair(Thread, 
Address

So either this line or changes above are not needed.



Repository:
  rC Clang

https://reviews.llvm.org/D43606



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-02-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

(Review is incomplete, but here are some initial comments.)




Comment at: include/clang/AST/Attr.h:210-212
+  unsigned Idx;
+  bool HasThis;
+  bool IsValid;

I think it might be best to mash these together using bit-fields:
```
unsigned Idx : 30;
unsigned HasThis : 1;
unsigned IsValid : 1;
```



Comment at: include/clang/AST/Attr.h:218
+  ParamIdx() : Idx(0), HasThis(false), IsValid(false) {}
+  /// \param Idx is the parameter index as it is normally specified in
+  /// attributes in the source: one-origin including any C++ implicit this

Add some newlines between the various declarations in the class -- everything 
is condensed a bit too much without it.



Comment at: include/clang/AST/Attr.h:225
+  ParamIdx(unsigned Idx, const Decl *D) : Idx(Idx), IsValid(true) {
+if (const FunctionDecl *FD = dyn_cast(D))
+  HasThis = FD->isCXXInstanceMember();

`const auto *`



Comment at: include/clang/AST/Attr.h:227-228
+  HasThis = FD->isCXXInstanceMember();
+else
+  HasThis = false;
+  }

Might as well move this into the member initializer.



Comment at: include/clang/AST/Attr.h:238-243
+  ParamIdx =(const ParamIdx ) {
+Idx = I.Idx;
+HasThis = I.HasThis;
+IsValid = I.IsValid;
+return *this;
+  }

Is this necessary? There should be an implicit copy assignment operator for 
this class, and it's a bit strange to have a copy assignment but no copy 
constructor.



Comment at: include/clang/AST/Attr.h:264
+  /// constructing new attributes from a source-like specification.
+  unsigned atSrc() const {
+assert(isValid() && "ParamIdx must be valid");

I'd prefer more clear names, like "getSourceIndex()" and "getASTIndex()".



Comment at: include/clang/AST/Attr.h:282
+  /// This is the encoding primarily used in CodeGen.
+  unsigned atLLVM() const {
+assert(isValid() && "ParamIdx must be valid");

Perhaps `getLLVMIndex()` for this one.



Comment at: include/clang/AST/Attr.h:291-292
+template 
+class ParamIdxItrBase : public std::iterator {
+  DerivedT () { return *static_cast(this); }

`std::iterator` was deprecated in C++17, so you should manually expose these 
fields.


https://reviews.llvm.org/D43248



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


[PATCH] D43749: [Attr] Fix alloc_size's diags to report arg idx not value

2018-02-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Committed (with whitespace fix for the test case) in r326058, thanks for the 
patch!


https://reviews.llvm.org/D43749



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


r326058 - When diagnosing the arguments to alloc_size, report the failing argument using a 1-based index instead of a 0-based index for consistency.

2018-02-25 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sun Feb 25 12:40:06 2018
New Revision: 326058

URL: http://llvm.org/viewvc/llvm-project?rev=326058=rev
Log:
When diagnosing the arguments to alloc_size, report the failing argument using 
a 1-based index instead of a 0-based index for consistency.

Patch by Joel Denny.

Modified:
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/Sema/alloc-size.c

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=326058=326057=326058=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Sun Feb 25 12:40:06 2018
@@ -765,19 +765,19 @@ static void handleAssertExclusiveLockAtt
   AL.getAttributeSpellingListIndex()));
 }
 
-/// \brief Checks to be sure that the given parameter number is in bounds, and 
is
-/// an integral type. Will emit appropriate diagnostics if this returns
+/// \brief Checks to be sure that the given parameter number is in bounds, and
+/// is an integral type. Will emit appropriate diagnostics if this returns
 /// false.
 ///
-/// FuncParamNo is expected to be from the user, so is base-1. AttrArgNo is 
used
-/// to actually retrieve the argument, so it's base-0.
+/// AttrArgNo is used to actually retrieve the argument, so it's base-0.
 template 
 static bool checkParamIsIntegerType(Sema , const FunctionDecl *FD,
-const AttrInfo , Expr *AttrArg,
-unsigned FuncParamNo, unsigned AttrArgNo,
+const AttrInfo , unsigned AttrArgNo,
 bool AllowDependentType = false) {
+  assert(AI.isArgExpr(AttrArgNo) && "Expected expression argument");
+  Expr *AttrArg = AI.getArgAsExpr(AttrArgNo);
   uint64_t Idx;
-  if (!checkFunctionOrMethodParameterIndex(S, FD, AI, FuncParamNo, AttrArg,
+  if (!checkFunctionOrMethodParameterIndex(S, FD, AI, AttrArgNo + 1, AttrArg,
Idx))
 return false;
 
@@ -793,20 +793,6 @@ static bool checkParamIsIntegerType(Sema
   return true;
 }
 
-/// \brief Checks to be sure that the given parameter number is in bounds, and 
is
-/// an integral type. Will emit appropriate diagnostics if this returns false.
-///
-/// FuncParamNo is expected to be from the user, so is base-1. AttrArgNo is 
used
-/// to actually retrieve the argument, so it's base-0.
-static bool checkParamIsIntegerType(Sema , const FunctionDecl *FD,
-const AttributeList ,
-unsigned FuncParamNo, unsigned AttrArgNo,
-bool AllowDependentType = false) {
-  assert(AL.isArgExpr(AttrArgNo) && "Expected expression argument");
-  return checkParamIsIntegerType(S, FD, AL, AL.getArgAsExpr(AttrArgNo),
- FuncParamNo, AttrArgNo, AllowDependentType);
-}
-
 static void handleAllocSizeAttr(Sema , Decl *D, const AttributeList ) {
   if (!checkAttributeAtLeastNumArgs(S, AL, 1) ||
   !checkAttributeAtMostNumArgs(S, AL, 2))
@@ -825,7 +811,7 @@ static void handleAllocSizeAttr(Sema ,
   if (!checkPositiveIntArgument(S, AL, SizeExpr, SizeArgNo, /*Index=*/1))
 return;
 
-  if (!checkParamIsIntegerType(S, FD, AL, SizeArgNo, /*AttrArgNo=*/0))
+  if (!checkParamIsIntegerType(S, FD, AL, /*AttrArgNo=*/0))
 return;
 
   // Args are 1-indexed, so 0 implies that the arg was not present
@@ -837,7 +823,7 @@ static void handleAllocSizeAttr(Sema ,
   /*Index=*/2))
   return;
 
-if (!checkParamIsIntegerType(S, FD, AL, NumberArgNo, /*AttrArgNo=*/1))
+if (!checkParamIsIntegerType(S, FD, AL, /*AttrArgNo=*/1))
   return;
   }
 

Modified: cfe/trunk/test/Sema/alloc-size.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/alloc-size.c?rev=326058=326057=326058=diff
==
--- cfe/trunk/test/Sema/alloc-size.c (original)
+++ cfe/trunk/test/Sema/alloc-size.c Sun Feb 25 12:40:06 2018
@@ -3,14 +3,14 @@
 void *fail1(int a) __attribute__((alloc_size)); //expected-error{{'alloc_size' 
attribute takes at least 1 argument}}
 void *fail2(int a) __attribute__((alloc_size())); 
//expected-error{{'alloc_size' attribute takes at least 1 argument}}
 
-void *fail3(int a) __attribute__((alloc_size(0))); 
//expected-error{{'alloc_size' attribute parameter 0 is out of bounds}}
-void *fail4(int a) __attribute__((alloc_size(2))); 
//expected-error{{'alloc_size' attribute parameter 2 is out of bounds}}
+void *fail3(int a) __attribute__((alloc_size(0))); 
//expected-error{{'alloc_size' attribute parameter 1 is out of bounds}}
+void *fail4(int a) __attribute__((alloc_size(2))); 
//expected-error{{'alloc_size' attribute parameter 1 is out of bounds}}
 
-void *fail5(int a, int b) __attribute__((alloc_size(0, 

[PATCH] D43747: [Attr] Fix pointer_with_type_tag assert fail for variadic

2018-02-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

Committed in r326057.

If you're not already on IRC, I would recommend joining the #llvm channel on 
OFTC so that you can watch for build break notifications from the build bots.


https://reviews.llvm.org/D43747



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


r326057 - Fix a failing assertion with the pointer_with_type_tag attribute when the function the attribute appertains to is variadic.

2018-02-25 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sun Feb 25 12:28:10 2018
New Revision: 326057

URL: http://llvm.org/viewvc/llvm-project?rev=326057=rev
Log:
Fix a failing assertion with the pointer_with_type_tag attribute when the 
function the attribute appertains to is variadic.

Patch by Joel Denny.

Modified:
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/Sema/warn-type-safety.c

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=326057=326056=326057=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Sun Feb 25 12:28:10 2018
@@ -4567,11 +4567,10 @@ static void handleArgumentWithTypeTagAtt
   bool IsPointer = AL.getName()->getName() == "pointer_with_type_tag";
   if (IsPointer) {
 // Ensure that buffer has a pointer type.
-QualType BufferTy = getFunctionOrMethodParamType(D, ArgumentIdx);
-if (!BufferTy->isPointerType()) {
+if (ArgumentIdx >= getFunctionOrMethodNumParams(D) ||
+!getFunctionOrMethodParamType(D, ArgumentIdx)->isPointerType())
   S.Diag(AL.getLoc(), diag::err_attribute_pointers_only)
-<< AL.getName() << 0;
-}
+  << AL.getName() << 0;
   }
 
   D->addAttr(::new (S.Context) ArgumentWithTypeTagAttr(

Modified: cfe/trunk/test/Sema/warn-type-safety.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-type-safety.c?rev=326057=326056=326057=diff
==
--- cfe/trunk/test/Sema/warn-type-safety.c (original)
+++ cfe/trunk/test/Sema/warn-type-safety.c Sun Feb 25 12:28:10 2018
@@ -37,6 +37,10 @@ int wrong9 __attribute__(( pointer_with_
 int wrong10(double buf, MPI_Datatype type)
 __attribute__(( pointer_with_type_tag(mpi,1,2) )); // expected-error 
{{'pointer_with_type_tag' attribute only applies to pointer arguments}}
 
+int ok11(void *, ...)
+__attribute__(( pointer_with_type_tag(mpi,1,2) ));
+int wrong11(void *, ...)
+__attribute__(( pointer_with_type_tag(mpi,2,3) )); // expected-error 
{{'pointer_with_type_tag' attribute only applies to pointer arguments}}
 
 extern struct A datatype_wrong1
 __attribute__(( type_tag_for_datatype )); // expected-error 
{{'type_tag_for_datatype' attribute requires parameter 1 to be an identifier}}


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


[PATCH] D43750: Allow writing calling convention attributes on function types

2018-02-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added a reviewer: rsmith.

Calling convention attributes notionally appertain to the function type -- they 
modify the mangling of the function, change the behavior of assignment 
operations, etc. However, they're not currently allowed to be written in the 
type position within a function declaration. This patch allows the calling 
convention attributes to be written in the type position as well as the 
declaration position. This also adds a new diagnostic to diagnose this as being 
incompatible with GCC despite the attribute being in the `gnu` namespace. I do 
not think this incompatibility is sufficient to warrant adding a `clang` 
namespace for the attributes, but that is another option available to us if 
there is concern over the incompatibility.

Eventually, I would like to extend this to other attributes that really should 
be type attributes, such as enable_if. The calling convention attributes just 
happen to be the lowest hanging fruit.


https://reviews.llvm.org/D43750

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaType.cpp
  test/SemaCXX/cxx11-gnu-attrs.cpp
  test/SemaCXX/type-attrs.cpp
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -2068,7 +2068,8 @@
 bool Inheritable = false;
 for (const auto  : llvm::reverse(Supers)) {
   const Record *R = Super.first;
-  if (R->getName() != "TargetSpecificAttr" && SuperName.empty())
+  if (R->getName() != "TargetSpecificAttr" &&
+  R->getName() != "DeclOrTypeAttr" && SuperName.empty())
 SuperName = R->getName();
   if (R->getName() == "InheritableAttr")
 Inheritable = true;
@@ -3437,7 +3438,9 @@
 emitArgInfo(*I->second, SS);
 SS << ", " << I->second->getValueAsBit("HasCustomParsing");
 SS << ", " << I->second->isSubClassOf("TargetSpecificAttr");
-SS << ", " << I->second->isSubClassOf("TypeAttr");
+SS << ", "
+   << (I->second->isSubClassOf("TypeAttr") ||
+   I->second->isSubClassOf("DeclOrTypeAttr"));
 SS << ", " << I->second->isSubClassOf("StmtAttr");
 SS << ", " << IsKnownToGCC(*I->second);
 SS << ", " << PragmaAttributeSupport.isAttributedSupported(*I->second);
Index: test/SemaCXX/type-attrs.cpp
===
--- test/SemaCXX/type-attrs.cpp
+++ test/SemaCXX/type-attrs.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -triple x86_64-pc-win32 -Wgcc-compat -std=c++11 -verify %s
+
+void f() [[gnu::cdecl]] {}  // expected-warning {{GCC does not allow the 'cdecl' attribute to be written on a type}}
+void g() [[gnu::stdcall]] {}  // expected-warning {{GCC does not allow the 'stdcall' attribute to be written on a type}}
+void i() [[gnu::fastcall]] {}  // expected-warning {{GCC does not allow the 'fastcall' attribute to be written on a type}}
Index: test/SemaCXX/cxx11-gnu-attrs.cpp
===
--- test/SemaCXX/cxx11-gnu-attrs.cpp
+++ test/SemaCXX/cxx11-gnu-attrs.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++11 -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++11 -Wno-gcc-compat -verify %s
 
 // Error cases.
 
@@ -18,8 +18,7 @@
 // expected-warning@-2 {{calling convention '__stdcall' ignored for this target}}
 [[gnu::fastcall]] void pr17424_4() [[gnu::stdcall]];
 // expected-warning@-1 {{calling convention 'fastcall' ignored for this target}}
-// expected-warning@-2 {{attribute 'stdcall' ignored, because it cannot be applied to a type}}
-// expected-warning@-3 {{calling convention 'stdcall' ignored for this target}}
+// expected-warning@-2 {{calling convention 'stdcall' ignored for this target}}
 void pr17424_5 [[gnu::fastcall]]();
 // expected-warning@-1 {{calling convention 'fastcall' ignored for this target}}
 
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -7142,14 +7142,19 @@
 
 if (attr.isCXX11Attribute()) {
   // [[gnu::...]] attributes are treated as declaration attributes, so may
-  // not appertain to a DeclaratorChunk, even if we handle them as type
-  // attributes.
+  // not appertain to a DeclaratorChunk. If we handle them as type
+  // attributes, accept them in that position and diagnose the GCC
+  // incompatibility.
   if (attr.getScopeName() && attr.getScopeName()->isStr("gnu")) {
+bool IsTypeAttr = attr.isTypeAttr();
 if (TAL == TAL_DeclChunk) {
   state.getSema().Diag(attr.getLoc(),
-   diag::warn_cxx11_gnu_attribute_on_type)
+   IsTypeAttr
+   ? 

[PATCH] D43748: [Attr] Fix paren, comma, and omitted arg printing in some cases

2018-02-25 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added inline comments.



Comment at: test/Misc/ast-print-objectivec.m:52
 // CHECK: @class C1;
-// CHECK: struct __attribute__((objc_bridge_related(C1, , ))) S1;
+// CHECK: struct __attribute__((objc_bridge_related(C1))) S1;

aaron.ballman wrote:
> This fix is incorrect in this case -- the attribute doesn't parse without the 
> extra commas.
> 
> https://godbolt.org/g/Ze69HD
Sorry, I should have researched that one.

It is straight-forward to make it treat an argument as provided based on its 
argument type.  Will look into it soon.


https://reviews.llvm.org/D43748



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


[PATCH] D43749: [Attr] Fix alloc_size's diags to report arg idx not value

2018-02-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D43749#1018825, @jdenny wrote:

> In https://reviews.llvm.org/D43749#1018818, @aaron.ballman wrote:
>
> > Aside from a minor testcase nit, this LGTM. Why is this dependent on 
> > https://reviews.llvm.org/D43248?
>
>
> The dependency goes the other way.  Did I get it wrong?


Ugh, no, I misunderstood what Phab was trying to tell me. This makes 
considerably more sense. :-)


https://reviews.llvm.org/D43749



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


[PATCH] D43747: [Attr] Fix pointer_with_type_tag assert fail for variadic

2018-02-25 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D43747#1018824, @aaron.ballman wrote:

> In https://reviews.llvm.org/D43747#1018814, @jdenny wrote:
>
> > Hi Aaron. Thanks for accepting. I do not have commit privileges. Would
> >  you please commit this (and any other patches you accept) for me?
>
>
> I'm happy to do so. Just to double-check though, there's nothing about this 
> patch that actually relies on functionality in 
> https://reviews.llvm.org/D43248, correct?


Right.  The dependency is in the other direction.


https://reviews.llvm.org/D43747



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


[PATCH] D43749: [Attr] Fix alloc_size's diags to report arg idx not value

2018-02-25 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D43749#1018818, @aaron.ballman wrote:

> Aside from a minor testcase nit, this LGTM. Why is this dependent on 
> https://reviews.llvm.org/D43248?


The dependency goes the other way.  Did I get it wrong?




Comment at: test/Sema/alloc-size.c:3
 
-void *fail1(int a) __attribute__((alloc_size)); //expected-error{{'alloc_size' 
attribute takes at least 1 argument}}
+void *fail1(int a) __attribute__((alloc_size));   
//expected-error{{'alloc_size' attribute takes at least 1 argument}}
 void *fail2(int a) __attribute__((alloc_size())); 
//expected-error{{'alloc_size' attribute takes at least 1 argument}}

aaron.ballman wrote:
> This looks like a whitespace-only change?
clang-format-diff.py suggested that.  Should I drop that?


https://reviews.llvm.org/D43749



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


[PATCH] D43749: [Attr] Fix alloc_size's diags to report arg idx not value

2018-02-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

Aside from a minor testcase nit, this LGTM. Why is this dependent on 
https://reviews.llvm.org/D43248?




Comment at: test/Sema/alloc-size.c:3
 
-void *fail1(int a) __attribute__((alloc_size)); //expected-error{{'alloc_size' 
attribute takes at least 1 argument}}
+void *fail1(int a) __attribute__((alloc_size));   
//expected-error{{'alloc_size' attribute takes at least 1 argument}}
 void *fail2(int a) __attribute__((alloc_size())); 
//expected-error{{'alloc_size' attribute takes at least 1 argument}}

This looks like a whitespace-only change?


https://reviews.llvm.org/D43749



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


[PATCH] D43747: [Attr] Fix pointer_with_type_tag assert fail for variadic

2018-02-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D43747#1018814, @jdenny wrote:

> Hi Aaron. Thanks for accepting. I do not have commit privileges. Would
>  you please commit this (and any other patches you accept) for me?


I'm happy to do so. Just to double-check though, there's nothing about this 
patch that actually relies on functionality in https://reviews.llvm.org/D43248, 
correct?


https://reviews.llvm.org/D43747



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


[PATCH] D43747: [Attr] Fix pointer_with_type_tag assert fail for variadic

2018-02-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Why is this dependent on https://reviews.llvm.org/D43248?


https://reviews.llvm.org/D43747



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


[PATCH] D43747: [Attr] Fix pointer_with_type_tag assert fail for variadic

2018-02-25 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

Hi Aaron. Thanks for accepting. I do not have commit privileges. Would
you please commit this (and any other patches you accept) for me?


https://reviews.llvm.org/D43747



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


[PATCH] D43748: [Attr] Fix paren, comma, and omitted arg printing in some cases

2018-02-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In general, I think the idea is reasonable, but in practice I'm worried about 
the attributes with custom parsing. Sometimes the parsing requires those extra 
bits and I'm not certain of how best to address that.




Comment at: test/Misc/ast-print-objectivec.m:52
 // CHECK: @class C1;
-// CHECK: struct __attribute__((objc_bridge_related(C1, , ))) S1;
+// CHECK: struct __attribute__((objc_bridge_related(C1))) S1;

This fix is incorrect in this case -- the attribute doesn't parse without the 
extra commas.

https://godbolt.org/g/Ze69HD


https://reviews.llvm.org/D43748



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-02-25 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 135839.
jdenny retitled this revision from "[Attr] Fix printing of parameter indices in 
attributes" to "[Attr] Fix parameter indexing for attributes".
jdenny edited the summary of this revision.
jdenny added a comment.
Herald added a subscriber: kristof.beyls.

After several attempts at strategies Aaron and I discussed, I ended up going a 
different way.  See the new summary for details.  I believe this version 
addresses all the issues Aaron raised so far.


https://reviews.llvm.org/D43248

Files:
  include/clang/AST/Attr.h
  include/clang/Basic/Attr.td
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGCall.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
  test/CodeGenCXX/alloc-size.cpp
  test/Misc/ast-dump-attr.cpp
  test/Sema/attr-ownership.cpp
  test/Sema/attr-print.cpp
  test/Sema/error-type-safety.cpp
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -306,9 +306,6 @@
 return "!get" + getUpperName().str() + "()";
   if (type == "TypeSourceInfo *")
 return "false";
-  // FIXME: Do this declaratively in Attr.td.
-  if (getAttrName() == "AllocSize")
-return "0 == get" + getUpperName().str() + "()";
   return "false";
 }
 
@@ -749,6 +746,192 @@
 }
   };
 
+  class VariadicParamIdxArgument : public Argument {
+std::string IdxBeginName, SizeName;
+bool AllowsThis;
+
+  public:
+VariadicParamIdxArgument(const Record , StringRef Attr)
+: Argument(Arg, Attr), IdxBeginName(getUpperName().str() + "_begin"),
+  SizeName(getUpperName().str() + "_size"),
+  AllowsThis(Arg.getValueAsBit("AllowsThis")) {}
+
+bool isVariadic() const override { return true; }
+
+void writeDeclarations(raw_ostream ) const override {
+  OS << "  ParamIdxItr " << IdxBeginName << ";\n";
+  OS << "  unsigned " << SizeName << ";\n";
+}
+
+  public:
+void writeAccessors(raw_ostream ) const override {
+  OS << "\n"
+ << "  static bool " << getLowerName() << "_allowsThis() {"
+ << " return " << AllowsThis << "; }\n";
+  OS << "  unsigned " << getLowerName() << "_size() const {"
+ << " return " << SizeName << "; }\n";
+  OS << "  ParamIdxItr " << getLowerName() << "_begin() const { return "
+ << IdxBeginName << "; }\n"
+ << "  ParamIdxItr " << getLowerName() << "_end() const { return "
+ << IdxBeginName << " + " << SizeName << "; }\n"
+ << "  llvm::iterator_range " << getLowerName()
+ << "() const { return llvm::make_range(" << getLowerName()
+ << "_begin(), " << getLowerName() << "_end()); }\n";
+}
+
+void writeCtorParameters(raw_ostream ) const override {
+  OS << "ParamIdxItr " << IdxBeginName << ", "
+ << "unsigned " << SizeName;
+}
+
+void writeCloneArgs(raw_ostream ) const override {
+  OS << IdxBeginName << ", " << SizeName;
+}
+
+void writeTemplateInstantiationArgs(raw_ostream ) const override {
+  // This isn't elegant, but we have to go through public methods...
+  OS << "A->" << getLowerName() << "_begin(), "
+ << "A->" << getLowerName() << "_size()";
+}
+
+void writeImplicitCtorArgs(raw_ostream ) const override {
+  OS << IdxBeginName << ", " << SizeName;
+}
+
+void writeCtorInitializers(raw_ostream ) const override {
+  OS << IdxBeginName << "(), ";
+  OS << SizeName << "(" << SizeName << ")";
+}
+
+void writeCtorDefaultInitializers(raw_ostream ) const override {
+  OS << IdxBeginName << "(), " << SizeName << "(0)";
+}
+
+void writeCtorBody(raw_ostream ) const override {
+  OS << "unsigned *" << getUpperName()
+ << "_array = new (Ctx, 16) unsigned[" << SizeName << "];\n";
+  OS << "std::copy((ParamIdxAtSrcItr)" << IdxBeginName
+ << ", (ParamIdxAtSrcItr)" << IdxBeginName << " + " << SizeName << ", "
+ << getUpperName() << "_array);\n";
+  OS << "this->" << IdxBeginName << " = ParamIdxItr(" << getUpperName()
+ << "_array, " << IdxBeginName << ".hasThis());\n";
+}
+
+void writePCHReadDecls(raw_ostream ) const override {
+  OS << "unsigned " << SizeName << " = Record.readInt();\n";
+  OS << "SmallVector " << getUpperName() << "_vec;\n"
+ << "" << getUpperName() << "_vec.reserve(" << SizeName << ");\n"
+ << "for (unsigned i = 0; i != " << SizeName << "; ++i)\n"
+ << "  " << getUpperName() << "_vec.push_back(Record.readInt());\n";
+  OS << "bool " << getUpperName() << "HasThis = Record.readInt();\n";
+  OS << "

[PATCH] D43747: [Attr] Fix pointer_with_type_tag assert fail for variadic

2018-02-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, thank you for the fix!


https://reviews.llvm.org/D43747



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


[PATCH] D43749: [Attr] Fix alloc_size's diags to report arg idx not value

2018-02-25 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added a reviewer: aaron.ballman.

For consistency with other attributes, fix alloc_size's diagnostics to
report the attribute's argument index for a function parameter index
rather than the actual function parameter index specified in the
source.


https://reviews.llvm.org/D43749

Files:
  lib/Sema/SemaDeclAttr.cpp
  test/Sema/alloc-size.c


Index: test/Sema/alloc-size.c
===
--- test/Sema/alloc-size.c
+++ test/Sema/alloc-size.c
@@ -1,16 +1,16 @@
 // RUN: %clang_cc1 %s -verify
 
-void *fail1(int a) __attribute__((alloc_size)); //expected-error{{'alloc_size' 
attribute takes at least 1 argument}}
+void *fail1(int a) __attribute__((alloc_size));   
//expected-error{{'alloc_size' attribute takes at least 1 argument}}
 void *fail2(int a) __attribute__((alloc_size())); 
//expected-error{{'alloc_size' attribute takes at least 1 argument}}
 
-void *fail3(int a) __attribute__((alloc_size(0))); 
//expected-error{{'alloc_size' attribute parameter 0 is out of bounds}}
-void *fail4(int a) __attribute__((alloc_size(2))); 
//expected-error{{'alloc_size' attribute parameter 2 is out of bounds}}
+void *fail3(int a) __attribute__((alloc_size(0))); 
//expected-error{{'alloc_size' attribute parameter 1 is out of bounds}}
+void *fail4(int a) __attribute__((alloc_size(2))); 
//expected-error{{'alloc_size' attribute parameter 1 is out of bounds}}
 
-void *fail5(int a, int b) __attribute__((alloc_size(0, 1))); 
//expected-error{{'alloc_size' attribute parameter 0 is out of bounds}}
-void *fail6(int a, int b) __attribute__((alloc_size(3, 1))); 
//expected-error{{'alloc_size' attribute parameter 3 is out of bounds}}
+void *fail5(int a, int b) __attribute__((alloc_size(0, 1))); 
//expected-error{{'alloc_size' attribute parameter 1 is out of bounds}}
+void *fail6(int a, int b) __attribute__((alloc_size(3, 1))); 
//expected-error{{'alloc_size' attribute parameter 1 is out of bounds}}
 
-void *fail7(int a, int b) __attribute__((alloc_size(1, 0))); 
//expected-error{{'alloc_size' attribute parameter 0 is out of bounds}}
-void *fail8(int a, int b) __attribute__((alloc_size(1, 3))); 
//expected-error{{'alloc_size' attribute parameter 3 is out of bounds}}
+void *fail7(int a, int b) __attribute__((alloc_size(1, 0))); 
//expected-error{{'alloc_size' attribute parameter 2 is out of bounds}}
+void *fail8(int a, int b) __attribute__((alloc_size(1, 3))); 
//expected-error{{'alloc_size' attribute parameter 2 is out of bounds}}
 
 int fail9(int a) __attribute__((alloc_size(1))); 
//expected-warning{{'alloc_size' attribute only applies to return values that 
are pointers}}
 
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -765,19 +765,19 @@
   AL.getAttributeSpellingListIndex()));
 }
 
-/// \brief Checks to be sure that the given parameter number is in bounds, and 
is
-/// an integral type. Will emit appropriate diagnostics if this returns
+/// \brief Checks to be sure that the given parameter number is in bounds, and
+/// is an integral type. Will emit appropriate diagnostics if this returns
 /// false.
 ///
-/// FuncParamNo is expected to be from the user, so is base-1. AttrArgNo is 
used
-/// to actually retrieve the argument, so it's base-0.
+/// AttrArgNo is used to actually retrieve the argument, so it's base-0.
 template 
 static bool checkParamIsIntegerType(Sema , const FunctionDecl *FD,
-const AttrInfo , Expr *AttrArg,
-unsigned FuncParamNo, unsigned AttrArgNo,
+const AttrInfo , unsigned AttrArgNo,
 bool AllowDependentType = false) {
+  assert(AI.isArgExpr(AttrArgNo) && "Expected expression argument");
+  Expr *AttrArg = AI.getArgAsExpr(AttrArgNo);
   uint64_t Idx;
-  if (!checkFunctionOrMethodParameterIndex(S, FD, AI, FuncParamNo, AttrArg,
+  if (!checkFunctionOrMethodParameterIndex(S, FD, AI, AttrArgNo + 1, AttrArg,
Idx))
 return false;
 
@@ -793,20 +793,6 @@
   return true;
 }
 
-/// \brief Checks to be sure that the given parameter number is in bounds, and 
is
-/// an integral type. Will emit appropriate diagnostics if this returns false.
-///
-/// FuncParamNo is expected to be from the user, so is base-1. AttrArgNo is 
used
-/// to actually retrieve the argument, so it's base-0.
-static bool checkParamIsIntegerType(Sema , const FunctionDecl *FD,
-const AttributeList ,
-unsigned FuncParamNo, unsigned AttrArgNo,
-bool AllowDependentType = false) {
-  assert(AL.isArgExpr(AttrArgNo) && "Expected expression argument");
-  return checkParamIsIntegerType(S, FD, AL, AL.getArgAsExpr(AttrArgNo),
- 

[PATCH] D43747: [Attr] Fix pointer_with_type_tag assert fail for variadic

2018-02-25 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added a reviewer: aaron.ballman.

https://reviews.llvm.org/D43747

Files:
  lib/Sema/SemaDeclAttr.cpp
  test/Sema/warn-type-safety.c


Index: test/Sema/warn-type-safety.c
===
--- test/Sema/warn-type-safety.c
+++ test/Sema/warn-type-safety.c
@@ -37,6 +37,10 @@
 int wrong10(double buf, MPI_Datatype type)
 __attribute__(( pointer_with_type_tag(mpi,1,2) )); // expected-error 
{{'pointer_with_type_tag' attribute only applies to pointer arguments}}
 
+int ok11(void *, ...)
+__attribute__(( pointer_with_type_tag(mpi,1,2) ));
+int wrong11(void *, ...)
+__attribute__(( pointer_with_type_tag(mpi,2,3) )); // expected-error 
{{'pointer_with_type_tag' attribute only applies to pointer arguments}}
 
 extern struct A datatype_wrong1
 __attribute__(( type_tag_for_datatype )); // expected-error 
{{'type_tag_for_datatype' attribute requires parameter 1 to be an identifier}}
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -4567,11 +4567,10 @@
   bool IsPointer = AL.getName()->getName() == "pointer_with_type_tag";
   if (IsPointer) {
 // Ensure that buffer has a pointer type.
-QualType BufferTy = getFunctionOrMethodParamType(D, ArgumentIdx);
-if (!BufferTy->isPointerType()) {
+if (ArgumentIdx >= getFunctionOrMethodNumParams(D) ||
+!getFunctionOrMethodParamType(D, ArgumentIdx)->isPointerType())
   S.Diag(AL.getLoc(), diag::err_attribute_pointers_only)
-<< AL.getName() << 0;
-}
+  << AL.getName() << 0;
   }
 
   D->addAttr(::new (S.Context) ArgumentWithTypeTagAttr(


Index: test/Sema/warn-type-safety.c
===
--- test/Sema/warn-type-safety.c
+++ test/Sema/warn-type-safety.c
@@ -37,6 +37,10 @@
 int wrong10(double buf, MPI_Datatype type)
 __attribute__(( pointer_with_type_tag(mpi,1,2) )); // expected-error {{'pointer_with_type_tag' attribute only applies to pointer arguments}}
 
+int ok11(void *, ...)
+__attribute__(( pointer_with_type_tag(mpi,1,2) ));
+int wrong11(void *, ...)
+__attribute__(( pointer_with_type_tag(mpi,2,3) )); // expected-error {{'pointer_with_type_tag' attribute only applies to pointer arguments}}
 
 extern struct A datatype_wrong1
 __attribute__(( type_tag_for_datatype )); // expected-error {{'type_tag_for_datatype' attribute requires parameter 1 to be an identifier}}
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -4567,11 +4567,10 @@
   bool IsPointer = AL.getName()->getName() == "pointer_with_type_tag";
   if (IsPointer) {
 // Ensure that buffer has a pointer type.
-QualType BufferTy = getFunctionOrMethodParamType(D, ArgumentIdx);
-if (!BufferTy->isPointerType()) {
+if (ArgumentIdx >= getFunctionOrMethodNumParams(D) ||
+!getFunctionOrMethodParamType(D, ArgumentIdx)->isPointerType())
   S.Diag(AL.getLoc(), diag::err_attribute_pointers_only)
-<< AL.getName() << 0;
-}
+  << AL.getName() << 0;
   }
 
   D->addAttr(::new (S.Context) ArgumentWithTypeTagAttr(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43748: [Attr] Fix paren, comma, and omitted arg printing in some cases

2018-02-25 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added a reviewer: aaron.ballman.

The first FIXME introduced here will be addressed in another patch
soon.


https://reviews.llvm.org/D43748

Files:
  test/Misc/ast-print-objectivec.m
  test/Sema/attr-print.c
  test/Sema/attr-print.cpp
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -231,6 +231,7 @@
 virtual void writePCHReadArgs(raw_ostream ) const = 0;
 virtual void writePCHReadDecls(raw_ostream ) const = 0;
 virtual void writePCHWrite(raw_ostream ) const = 0;
+virtual std::string getIsOmitted() const { return "false"; }
 virtual void writeValue(raw_ostream ) const = 0;
 virtual void writeDump(raw_ostream ) const = 0;
 virtual void writeDumpChildren(raw_ostream ) const {}
@@ -298,23 +299,30 @@
std::string(getUpperName()) + "()");
 }
 
+std::string getIsOmitted() const override {
+  if (type == "FunctionDecl *")
+return "false";
+  if (type == "IdentifierInfo *")
+return "!get" + getUpperName().str() + "()";
+  if (type == "TypeSourceInfo *")
+return "false";
+  // FIXME: Do this declaratively in Attr.td.
+  if (getAttrName() == "AllocSize")
+return "0 == get" + getUpperName().str() + "()";
+  return "false";
+}
+
 void writeValue(raw_ostream ) const override {
-  if (type == "FunctionDecl *") {
-OS << "\" << get" << getUpperName()
-   << "()->getNameInfo().getAsString() << \"";
-  } else if (type == "IdentifierInfo *") {
-OS << "\";\n";
-if (isOptional())
-  OS << "if (get" << getUpperName() << "()) ";
-else
-  OS << "";
-OS << "OS << get" << getUpperName() << "()->getName();\n";
-OS << "OS << \"";
-  } else if (type == "TypeSourceInfo *") {
-OS << "\" << get" << getUpperName() << "().getAsString() << \"";
-  } else {
-OS << "\" << get" << getUpperName() << "() << \"";
-  }
+  StringRef Val;
+  if (type == "FunctionDecl *")
+Val = "->getNameInfo().getAsString()";
+  else if (type == "IdentifierInfo *")
+Val = "->getName()";
+  else if (type == "TypeSourceInfo *")
+Val = ".getAsString()";
+  else
+Val = "";
+  OS << "\" << get" << getUpperName() << "()" << Val << " << \"";
 }
 
 void writeDump(raw_ostream ) const override {
@@ -576,12 +584,15 @@
  << "Type());\n";
 }
 
+std::string getIsOmitted() const override {
+  return "!is" + getLowerName().str() + "Expr || !" + getLowerName().str()
+ + "Expr";
+}
+
 void writeValue(raw_ostream ) const override {
   OS << "\";\n";
-  // The aligned attribute argument expression is optional.
-  OS << "if (is" << getLowerName() << "Expr && "
- << getLowerName() << "Expr)\n";
-  OS << "  " << getLowerName() << "Expr->printPretty(OS, nullptr, Policy);\n";
+  OS << "" << getLowerName()
+ << "Expr->printPretty(OS, nullptr, Policy);\n";
   OS << "OS << \"";
 }
 
@@ -1376,33 +1387,83 @@
   continue;
 }
 
-// Fake arguments aren't part of the parsed form and should not be
-// pretty-printed.
-bool hasNonFakeArgs = llvm::any_of(
-Args, [](const std::unique_ptr ) { return !A->isFake(); });
-
-// FIXME: always printing the parenthesis isn't the correct behavior for
-// attributes which have optional arguments that were not provided. For
-// instance: __attribute__((aligned)) will be pretty printed as
-// __attribute__((aligned())). The logic should check whether there is only
-// a single argument, and if it is optional, whether it has been provided.
-if (hasNonFakeArgs)
-  OS << "(";
 if (Spelling == "availability") {
+  OS << "(";
   writeAvailabilityValue(OS);
+  OS << ")";
 } else if (Spelling == "deprecated" || Spelling == "gnu::deprecated") {
-writeDeprecatedAttrValue(OS, Variety);
+  OS << "(";
+  writeDeprecatedAttrValue(OS, Variety);
+  OS << ")";
 } else {
-  unsigned index = 0;
+  // To avoid printing parentheses around an empty argument list or
+  // printing spurious commas at the end of an argument list, we need to
+  // determine where the last provided non-fake argument is.
+  unsigned NonFakeArgs = 0;
+  unsigned TrailingOptArgs = 0;
+  bool FoundNonOptArg = false;
+  for (const auto  : llvm::reverse(Args)) {
+if (arg->isFake())
+  continue;
+++NonFakeArgs;
+if (FoundNonOptArg)
+  continue;
+// FIXME: arg->getIsOmitted() == "false" means we haven't implemented
+// any way to detect whether the argument was omitted.
+if 

[PATCH] D43745: Fix cppcoreguidelines-pro-bounds-pointer-arithmetic not working for functions with auto return specifier.

2018-02-25 Thread Alexandru Octavian Buțiu via Phabricator via cfe-commits
predator5047 created this revision.
predator5047 added reviewers: alexfh, alexfh_.
predator5047 added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, kbarton, nemanjai.

Fix bug #36489


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43745

Files:
  clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
  test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp


Index: test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
===
--- test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
+++ test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-pro-bounds-pointer-arithmetic %t
+// RUN: %check_clang_tidy %s cppcoreguidelines-pro-bounds-pointer-arithmetic 
%t -- -- -std=c++14
 
 enum E {
   ENUM_LITERAL = 1
@@ -9,7 +9,36 @@
 int *p = 0;
 int *q = 0;
 
+int* pointer() {
+  return nullptr;
+}
+
+auto pointerAuto() {
+  return (int*) nullptr;
+}
+
+auto pointerAutoTrailing() -> int* {
+  return (int*) nullptr;
+}
+
 void fail() {
+  auto x = (int*) nullptr;
+  p = x + 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not use pointer arithmetic
+  p = pointer() + 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not use pointer arithmetic
+  p = pointerAuto() + 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not use pointer arithmetic
+  p = pointerAutoTrailing() + 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not use pointer arithmetic
+
+  p = 1 + pointer();
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not use pointer arithmetic
+  p = 1 + pointerAuto();
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not use pointer arithmetic
+  p = 1 + pointerAutoTrailing();
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not use pointer arithmetic
+
   q = p + 4;
   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not use pointer arithmetic 
[cppcoreguidelines-pro-bounds-pointer-arithmetic]
   p = q + i;
Index: clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
===
--- clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
@@ -26,7 +26,7 @@
   binaryOperator(
   anyOf(hasOperatorName("+"), hasOperatorName("-"),
 hasOperatorName("+="), hasOperatorName("-=")),
-  hasType(pointerType()),
+  anyOf(hasType(pointerType()), 
hasType(autoType(hasDeducedType(pointerType(),
   unless(hasLHS(ignoringImpCasts(declRefExpr(to(isImplicit()))
   .bind("expr"),
   this);


Index: test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
===
--- test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
+++ test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-pro-bounds-pointer-arithmetic %t
+// RUN: %check_clang_tidy %s cppcoreguidelines-pro-bounds-pointer-arithmetic %t -- -- -std=c++14
 
 enum E {
   ENUM_LITERAL = 1
@@ -9,7 +9,36 @@
 int *p = 0;
 int *q = 0;
 
+int* pointer() {
+  return nullptr;
+}
+
+auto pointerAuto() {
+  return (int*) nullptr;
+}
+
+auto pointerAutoTrailing() -> int* {
+  return (int*) nullptr;
+}
+
 void fail() {
+  auto x = (int*) nullptr;
+  p = x + 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not use pointer arithmetic
+  p = pointer() + 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not use pointer arithmetic
+  p = pointerAuto() + 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not use pointer arithmetic
+  p = pointerAutoTrailing() + 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not use pointer arithmetic
+
+  p = 1 + pointer();
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not use pointer arithmetic
+  p = 1 + pointerAuto();
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not use pointer arithmetic
+  p = 1 + pointerAutoTrailing();
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not use pointer arithmetic
+
   q = p + 4;
   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
   p = q + i;
Index: clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
===
--- clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
@@ -26,7 +26,7 @@
   binaryOperator(
   anyOf(hasOperatorName("+"), hasOperatorName("-"),

[PATCH] D43737: Improve -Winfinite-recursion

2018-02-25 Thread Robert Widmann via Phabricator via cfe-commits
CodaFi updated this revision to Diff 135827.

https://reviews.llvm.org/D43737

Files:
  lib/Sema/AnalysisBasedWarnings.cpp
  test/SemaCXX/warn-infinite-recursion.cpp

Index: test/SemaCXX/warn-infinite-recursion.cpp
===
--- test/SemaCXX/warn-infinite-recursion.cpp
+++ test/SemaCXX/warn-infinite-recursion.cpp
@@ -29,8 +29,7 @@
 void e() { f(); }
 void f() { e(); }
 
-// Don't warn on infinite loops
-void g() {
+void g() {  // expected-warning{{call itself}}
   while (true)
 g();
 
@@ -54,6 +53,13 @@
   return 5 + j();
 }
 
+// Don't warn on infinite loops
+void k() {
+  while (true) {}
+
+  k();
+}
+
 class S {
   static void a();
   void b();
Index: lib/Sema/AnalysisBasedWarnings.cpp
===
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ lib/Sema/AnalysisBasedWarnings.cpp
@@ -200,60 +200,43 @@
   return false;
 }
 
-// All blocks are in one of three states.  States are ordered so that blocks
-// can only move to higher states.
-enum RecursiveState {
-  FoundNoPath,
-  FoundPath,
-  FoundPathWithNoRecursiveCall
-};
-
 // Returns true if there exists a path to the exit block and every path
 // to the exit block passes through a call to FD.
 static bool checkForRecursiveFunctionCall(const FunctionDecl *FD, CFG *cfg) {
+  llvm::SmallPtrSet Visited;
+  llvm::SmallVector WorkList;
+  // Keep track of whether we found at least one recursive path.
+  bool foundRecursion = false;
 
   const unsigned ExitID = cfg->getExit().getBlockID();
+  auto analyzeSuccessor = [&](CFGBlock *CurBlock) -> bool {
+if (!Visited.insert(CurBlock).second)
+  return false;
+
+// If the successor block contains a recursive call, end analysis there.
+if (!hasRecursiveCallInPath(FD, *CurBlock)) {
+  WorkList.push_back(CurBlock);
+  return false;
+}
+return true;
+  };
 
-  // Mark all nodes as FoundNoPath, then set the status of the entry block.
-  SmallVector States(cfg->getNumBlockIDs(), FoundNoPath);
-  States[cfg->getEntry().getBlockID()] = FoundPathWithNoRecursiveCall;
-
-  // Make the processing stack and seed it with the entry block.
-  SmallVector Stack;
-  Stack.push_back(>getEntry());
-
-  while (!Stack.empty()) {
-CFGBlock *CurBlock = Stack.back();
-Stack.pop_back();
+  // Seed the work list with the entry block.
+  foundRecursion |= analyzeSuccessor(>getEntry());
 
+  while (!WorkList.empty()) {
+CFGBlock *CurBlock = WorkList.pop_back_val();
 unsigned ID = CurBlock->getBlockID();
-RecursiveState CurState = States[ID];
-
-if (CurState == FoundPathWithNoRecursiveCall) {
-  // Found a path to the exit node without a recursive call.
-  if (ExitID == ID)
-return false;
 
-  // Only change state if the block has a recursive call.
-  if (hasRecursiveCallInPath(FD, *CurBlock))
-CurState = FoundPath;
-}
+// Found a path to the exit node without a recursive call.
+if (ExitID == ID)
+  return false;
 
-// Loop over successor blocks and add them to the Stack if their state
-// changes.
 for (auto I = CurBlock->succ_begin(), E = CurBlock->succ_end(); I != E; ++I)
-  if (*I) {
-unsigned next_ID = (*I)->getBlockID();
-if (States[next_ID] < CurState) {
-  States[next_ID] = CurState;
-  Stack.push_back(*I);
-}
-  }
+  if (*I)
+foundRecursion |= analyzeSuccessor(*I);
   }
-
-  // Return true if the exit node is reachable, and only reachable through
-  // a recursive call.
-  return States[ExitID] == FoundPath;
+  return foundRecursion;
 }
 
 static void checkRecursiveFunction(Sema , const FunctionDecl *FD,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r326055 - Switch the default behavior of the Clang<> spelling to opt-in to the C2x attribute spellings. NFC to the attribute spellings themselves.

2018-02-25 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sun Feb 25 07:34:17 2018
New Revision: 326055

URL: http://llvm.org/viewvc/llvm-project?rev=326055=rev
Log:
Switch the default behavior of the Clang<> spelling to opt-in to the C2x 
attribute spellings. NFC to the attribute spellings themselves.

The Clang<> spelling helper generates a spelling for C++11, GNU, and C2x 
attribute spellings. Previously, users had to manually opt in to the C2x 
spelling while we cautiously added attributes to that spelling. Now that 
majority of attributes are exposed in C2x, we can switch the default.

Modified:
cfe/trunk/include/clang/Basic/Attr.td

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=326055=326054=326055=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Sun Feb 25 07:34:17 2018
@@ -237,7 +237,7 @@ class GCC : Spelling, and optionally,
 // C2x<"clang", name>. This spelling should be used for any Clang-specific
 // attributes.
-class Clang : Spelling {
+class Clang : Spelling {
   bit AllowInC = allowInC;
 }
 
@@ -534,7 +534,7 @@ def AbiTag : Attr {
 }
 
 def AddressSpace : TypeAttr {
-  let Spellings = [Clang<"address_space", 1>];
+  let Spellings = [Clang<"address_space">];
   let Args = [IntArgument<"AddressSpace">];
   let Documentation = [Undocumented];
 }
@@ -598,18 +598,18 @@ def Artificial : InheritableAttr {
 }
 
 def XRayInstrument : InheritableAttr {
-  let Spellings = [Clang<"xray_always_instrument", 1>,
-   Clang<"xray_never_instrument", 1>];
+  let Spellings = [Clang<"xray_always_instrument">,
+   Clang<"xray_never_instrument">];
   let Subjects = SubjectList<[Function, ObjCMethod]>;
   let Accessors = [Accessor<"alwaysXRayInstrument",
- [Clang<"xray_always_instrument", 1>]>,
+ [Clang<"xray_always_instrument">]>,
Accessor<"neverXRayInstrument",
- [Clang<"xray_never_instrument", 1>]>];
+ [Clang<"xray_never_instrument">]>];
   let Documentation = [XRayDocs];
 }
 
 def XRayLogArgs : InheritableAttr {
-  let Spellings = [Clang<"xray_log_args", 1>];
+  let Spellings = [Clang<"xray_log_args">];
   let Subjects = SubjectList<[Function, ObjCMethod]>;
   let Args = [UnsignedArgument<"ArgumentCount">];
   let Documentation = [XRayDocs];
@@ -631,7 +631,7 @@ def AnalyzerNoReturn : InheritableAttr {
 }
 
 def Annotate : InheritableParamAttr {
-  let Spellings = [Clang<"annotate", 1>];
+  let Spellings = [Clang<"annotate">];
   let Args = [StringArgument<"Annotation">];
   // Ensure that the annotate attribute can be used with
   // '#pragma clang attribute' even though it has no subject list.
@@ -673,7 +673,7 @@ def AsmLabel : InheritableAttr {
 }
 
 def Availability : InheritableAttr {
-  let Spellings = [Clang<"availability", 1>];
+  let Spellings = [Clang<"availability">];
   let Args = [IdentifierArgument<"platform">, VersionArgument<"introduced">,
   VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
   BoolArgument<"unavailable">, StringArgument<"message">,
@@ -723,7 +723,7 @@ static llvm::StringRef canonicalizePlatf
 }
 
 def ExternalSourceSymbol : InheritableAttr {
-  let Spellings = [Clang<"external_source_symbol", 1>];
+  let Spellings = [Clang<"external_source_symbol">];
   let Args = [StringArgument<"language", 1>,
   StringArgument<"definedIn", 1>,
   BoolArgument<"generatedDeclaration", 1>];
@@ -733,7 +733,7 @@ def ExternalSourceSymbol : InheritableAt
 }
 
 def Blocks : InheritableAttr {
-  let Spellings = [Clang<"blocks", 1>];
+  let Spellings = [Clang<"blocks">];
   let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
   let Documentation = [Undocumented];
 }
@@ -761,7 +761,7 @@ def CDecl : InheritableAttr {
 // cf_returns_retained attributes.  It is generally applied by
 // '#pragma clang arc_cf_code_audited' rather than explicitly.
 def CFAuditedTransfer : InheritableAttr {
-  let Spellings = [Clang<"cf_audited_transfer", 1>];
+  let Spellings = [Clang<"cf_audited_transfer">];
   let Subjects = SubjectList<[Function], ErrorDiag>;
   let Documentation = [Undocumented];
 }
@@ -770,25 +770,25 @@ def CFAuditedTransfer : InheritableAttr
 // It indicates that the function has unknown or unautomatable
 // transfer semantics.
 def CFUnknownTransfer : InheritableAttr {
-  let Spellings = [Clang<"cf_unknown_transfer", 1>];
+  let Spellings = [Clang<"cf_unknown_transfer">];
   let Subjects = SubjectList<[Function], ErrorDiag>;
   let Documentation = [Undocumented];
 }
 
 def CFReturnsRetained : InheritableAttr {
-  let Spellings = [Clang<"cf_returns_retained", 1>];
+  let Spellings = [Clang<"cf_returns_retained">];
 //  

r326054 - Document why the consumed attributes (consumable, callable_when, et al) are not exposed with a C2x spelling. NFC.

2018-02-25 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sun Feb 25 06:54:25 2018
New Revision: 326054

URL: http://llvm.org/viewvc/llvm-project?rev=326054=rev
Log:
Document why the consumed attributes (consumable, callable_when, et al) are not 
exposed with a C2x spelling. NFC.

Modified:
cfe/trunk/include/clang/Basic/Attr.td

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=326054=326053=326054=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Sun Feb 25 06:54:25 2018
@@ -2390,6 +2390,9 @@ def LocksExcluded : InheritableAttr {
 // C/C++ consumed attributes.
 
 def Consumable : InheritableAttr {
+  // This attribute does not have a C [[]] spelling because it only appertains
+  // to C++ struct/class/union.
+  // FIXME: should this attribute have a CPlusPlus language option?
   let Spellings = [Clang<"consumable">];
   let Subjects = SubjectList<[CXXRecord]>;
   let Args = [EnumArgument<"DefaultState", "ConsumedState",
@@ -2399,18 +2402,27 @@ def Consumable : InheritableAttr {
 }
 
 def ConsumableAutoCast : InheritableAttr {
+  // This attribute does not have a C [[]] spelling because it only appertains
+  // to C++ struct/class/union.
+  // FIXME: should this attribute have a CPlusPlus language option?
   let Spellings = [Clang<"consumable_auto_cast_state">];
   let Subjects = SubjectList<[CXXRecord]>;
   let Documentation = [Undocumented];
 }
 
 def ConsumableSetOnRead : InheritableAttr {
+  // This attribute does not have a C [[]] spelling because it only appertains
+  // to C++ struct/class/union.
+  // FIXME: should this attribute have a CPlusPlus language option?
   let Spellings = [Clang<"consumable_set_state_on_read">];
   let Subjects = SubjectList<[CXXRecord]>;
   let Documentation = [Undocumented];
 }
 
 def CallableWhen : InheritableAttr {
+  // This attribute does not have a C [[]] spelling because it only appertains
+  // to C++ function (but doesn't require it to be a member function).
+  // FIXME: should this attribute have a CPlusPlus language option?
   let Spellings = [Clang<"callable_when">];
   let Subjects = SubjectList<[CXXMethod]>;
   let Args = [VariadicEnumArgument<"CallableStates", "ConsumedState",
@@ -2420,6 +2432,9 @@ def CallableWhen : InheritableAttr {
 }
 
 def ParamTypestate : InheritableAttr {
+  // This attribute does not have a C [[]] spelling because it only appertains
+  // to a parameter whose type is a consumable C++ class.
+  // FIXME: should this attribute have a CPlusPlus language option?
   let Spellings = [Clang<"param_typestate">];
   let Subjects = SubjectList<[ParmVar]>;
   let Args = [EnumArgument<"ParamState", "ConsumedState",
@@ -2429,6 +2444,9 @@ def ParamTypestate : InheritableAttr {
 }
 
 def ReturnTypestate : InheritableAttr {
+  // This attribute does not have a C [[]] spelling because it only appertains
+  // to a parameter or function return type that is a consumable C++ class.
+  // FIXME: should this attribute have a CPlusPlus language option?
   let Spellings = [Clang<"return_typestate">];
   let Subjects = SubjectList<[Function, ParmVar]>;
   let Args = [EnumArgument<"State", "ConsumedState",
@@ -2438,6 +2456,9 @@ def ReturnTypestate : InheritableAttr {
 }
 
 def SetTypestate : InheritableAttr {
+  // This attribute does not have a C [[]] spelling because it only appertains
+  // to C++ function (but doesn't require it to be a member function).
+  // FIXME: should this attribute have a CPlusPlus language option?
   let Spellings = [Clang<"set_typestate">];
   let Subjects = SubjectList<[CXXMethod]>;
   let Args = [EnumArgument<"NewState", "ConsumedState",
@@ -2447,6 +2468,9 @@ def SetTypestate : InheritableAttr {
 }
 
 def TestTypestate : InheritableAttr {
+  // This attribute does not have a C [[]] spelling because it only appertains
+  // to C++ function (but doesn't require it to be a member function).
+  // FIXME: should this attribute have a CPlusPlus language option?
   let Spellings = [Clang<"test_typestate">];
   let Subjects = SubjectList<[CXXMethod]>;
   let Args = [EnumArgument<"TestState", "ConsumedState",


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


r326053 - Add a C2x spelling for the external_source_symbol and internal_linkage attributes in the clang vendor namespace.

2018-02-25 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sun Feb 25 06:43:45 2018
New Revision: 326053

URL: http://llvm.org/viewvc/llvm-project?rev=326053=rev
Log:
Add a C2x spelling for the external_source_symbol and internal_linkage 
attributes in the clang vendor namespace.

Both of these attributes have existing meaning in C code, so there was no 
reason to exclude them from using the new spelling.

Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/test/Sema/attr-external-source-symbol.c
cfe/trunk/test/Sema/internal_linkage.c

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=326053=326052=326053=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Sun Feb 25 06:43:45 2018
@@ -723,7 +723,7 @@ static llvm::StringRef canonicalizePlatf
 }
 
 def ExternalSourceSymbol : InheritableAttr {
-  let Spellings = [Clang<"external_source_symbol">];
+  let Spellings = [Clang<"external_source_symbol", 1>];
   let Args = [StringArgument<"language", 1>,
   StringArgument<"definedIn", 1>,
   BoolArgument<"generatedDeclaration", 1>];
@@ -2817,7 +2817,7 @@ def OMPDeclareTargetDecl : Attr {
 }
 
 def InternalLinkage : InheritableAttr {
-  let Spellings = [Clang<"internal_linkage">];
+  let Spellings = [Clang<"internal_linkage", 1>];
   let Subjects = SubjectList<[Var, Function, CXXRecord]>;
   let Documentation = [InternalLinkageDocs];
 }

Modified: cfe/trunk/test/Sema/attr-external-source-symbol.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-external-source-symbol.c?rev=326053=326052=326053=diff
==
--- cfe/trunk/test/Sema/attr-external-source-symbol.c (original)
+++ cfe/trunk/test/Sema/attr-external-source-symbol.c Sun Feb 25 06:43:45 2018
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -fblocks -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fblocks -verify 
-fdouble-square-bracket-attributes %s
 
 void threeClauses() __attribute__((external_source_symbol(language="Swift", 
defined_in="module", generated_declaration)));
 
@@ -17,3 +17,15 @@ void namedDeclsOnly() {
   return 1;
   };
 }
+
+void threeClauses2() [[clang::external_source_symbol(language="Swift", 
defined_in="module", generated_declaration)]];
+
+void twoClauses2() [[clang::external_source_symbol(language="Swift", 
defined_in="module")]];
+
+void fourClauses2()
+[[clang::external_source_symbol(language="Swift", defined_in="module", 
generated_declaration, generated_declaration)]]; // expected-error {{duplicate 
'generated_declaration' clause in an 'external_source_symbol' attribute}}
+
+void oneClause2() [[clang::external_source_symbol(generated_declaration)]];
+
+void noArguments2()
+[[clang::external_source_symbol]]; // expected-error 
{{'external_source_symbol' attribute takes at least 1 argument}}

Modified: cfe/trunk/test/Sema/internal_linkage.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/internal_linkage.c?rev=326053=326052=326053=diff
==
--- cfe/trunk/test/Sema/internal_linkage.c (original)
+++ cfe/trunk/test/Sema/internal_linkage.c Sun Feb 25 06:43:45 2018
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fdouble-square-bracket-attributes %s
 
 int var __attribute__((internal_linkage));
 int var2 __attribute__((internal_linkage,common)); // 
expected-error{{'internal_linkage' and 'common' attributes are not compatible}} 
\
@@ -19,3 +19,9 @@ struct __attribute__((internal_linkage))
 };
 
 __attribute__((internal_linkage("foo"))) int g() {} // 
expected-error{{'internal_linkage' attribute takes no arguments}}
+
+int var6 [[clang::internal_linkage]];
+int var7 [[clang::internal_linkage]] __attribute__((common)); // 
expected-error{{'internal_linkage' and 'common' attributes are not compatible}} 
\
+   // 
expected-note{{conflicting attribute is here}}
+__attribute__((common)) int var8 [[clang::internal_linkage]]; // 
expected-error{{'internal_linkage' and 'common' attributes are not compatible}} 
\
+   // 
expected-note{{conflicting attribute is here}}


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


[PATCH] D43741: [Analyzer] More accurate modeling about the increment operator of the operand with type bool.

2018-02-25 Thread Henry Wong via Phabricator via cfe-commits
MTC created this revision.
MTC added reviewers: alexshap, NoQ, dcoughlin.
Herald added subscribers: cfe-commits, a.sidorin, szepet, xazax.hun.
Herald added a reviewer: george.karpenkov.

There is a problem with analyzer that a wrong value is given when modeling the 
increment operator of the operand with type bool. After `rL307604` is applied, 
a unsigned overflow may occur.

Example:

  void func() {
bool b = true;
// unsigned overflow occur, 2 -> 0 U1b
b++;
  }

The use of an operand of type bool with the ++ operators is deprecated but 
valid untill C++17. And if the operand of the increment operator is of type 
bool, it is set to true.

This patch includes two parts:

- If the operand of the increment operator is of type bool, set to true.
- Modify `BasicValueFactory::getTruthValue()`, use `getIntWidth()` instead 
`getTypeSize()` and use `unsigned` instead `signed`.


Repository:
  rC Clang

https://reviews.llvm.org/D43741

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  lib/StaticAnalyzer/Core/ExprEngineC.cpp
  test/Analysis/bool.cpp

Index: test/Analysis/bool.cpp
===
--- /dev/null
+++ test/Analysis/bool.cpp
@@ -0,0 +1,84 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection -analyzer-store=region -verify -std=c++11 -Wno-deprecated %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection -analyzer-store=region -verify -std=c++14 -Wno-deprecated %s
+
+extern void clang_analyzer_eval(bool);
+extern void clang_analyzer_dump(bool);
+
+void test_bool_increment() {
+  {
+bool b = true;
+b++;
+clang_analyzer_eval(b); // expected-warning{{TRUE}}
+  }
+
+  {
+bool b = false;
+b++;
+clang_analyzer_eval(b); // expected-warning{{TRUE}}
+  }
+
+  {
+bool b = true;
+++b;
+clang_analyzer_eval(b); // expected-warning{{TRUE}}
+  }
+
+  {
+bool b = false;
+++b;
+clang_analyzer_eval(b); // expected-warning{{TRUE}}
+  }
+
+  {
+bool b = 0;
+++b;
+clang_analyzer_eval(b); // expected-warning{{TRUE}}
+  }
+
+  {
+bool b = 10;
+++b;
+++b;
+clang_analyzer_eval(b); // expected-warning{{TRUE}}
+  }
+
+  {
+bool b = -10;
+++b;
+clang_analyzer_eval(b); // expected-warning{{TRUE}}
+  }
+}
+
+void test_bool_value() {
+  {
+bool b = true;
+clang_analyzer_dump(b); // expected-warning{{1 U1b}}
+  }
+
+  {
+bool b = false;
+clang_analyzer_dump(b); // expected-warning{{0 U1b}}
+  }
+
+  {
+bool b = -10;
+clang_analyzer_dump(b); // expected-warning{{1 U1b}}
+  }
+
+  {
+bool b = 10;
+clang_analyzer_dump(b); // expected-warning{{1 U1b}}
+  }
+
+  {
+bool b = 10;
+b++;
+clang_analyzer_dump(b); // expected-warning{{1 U1b}}
+  }
+
+  {
+bool b = 0;
+b++;
+clang_analyzer_dump(b); // expected-warning{{1 U1b}}
+  }
+}
Index: lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -1066,15 +1066,23 @@
 // constant value. If the UnaryOperator has location type, create the
 // constant with int type and pointer width.
 SVal RHS;
+SVal Result;
 
 if (U->getType()->isAnyPointerType())
   RHS = svalBuilder.makeArrayIndex(1);
 else if (U->getType()->isIntegralOrEnumerationType())
   RHS = svalBuilder.makeIntVal(1, U->getType());
 else
   RHS = UnknownVal();
 
-SVal Result = evalBinOp(state, Op, V2, RHS, U->getType());
+// The use of an operand of type bool with the ++ operators is deprecated
+// but valid untill C++17. And if the operand of the increment operator is
+// of type bool, it is set to true untill C++17.
+if (U->getType()->isBooleanType() && U->isIncrementOp() &&
+AMgr.getLangOpts().CPlusPlus)
+  Result = svalBuilder.makeTruthVal(true, U->getType());
+else
+  Result = evalBinOp(state, Op, V2, RHS, U->getType());
 
 // Conjure a new symbol if necessary to recover precision.
 if (Result.isUnknown()){
@@ -1096,7 +1104,6 @@
   Constraint = svalBuilder.evalEQ(state, SymVal,
svalBuilder.makeZeroVal(U->getType()));
 
-
   state = state->assume(Constraint, false);
   assert(state);
 }
Index: include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -194,7 +194,7 @@
   }
 
   inline const llvm::APSInt& getTruthValue(bool b, QualType T) {
-return getValue(b ? 1 : 0, Ctx.getTypeSize(T), false);
+return getValue(b ? 1 : 0, Ctx.getIntWidth(T), true);
   }
 
   inline const llvm::APSInt& getTruthValue(bool b) {

r326052 - Add a C++11 and C2x spelling for the type safety attribute (argument_with_type_tag, pointer_with_type_tag, and type_tag_for_datatype) in the clang vendor namespace.

2018-02-25 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sun Feb 25 06:01:04 2018
New Revision: 326052

URL: http://llvm.org/viewvc/llvm-project?rev=326052=rev
Log:
Add a C++11 and C2x spelling for the type safety attribute 
(argument_with_type_tag, pointer_with_type_tag, and type_tag_for_datatype) in 
the clang vendor namespace.

The TypeTagForDatatype attribute had custom parsing rules that previously 
prevented it from being supported with square bracket notation. The 
ArgumentWithTypeTag attribute previously had unnecessary custom parsing that 
could be handled declaratively.

Added:
cfe/trunk/test/Sema/attr-type-safety.c
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/Sema/warn-type-safety.c

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=326052=326051=326052=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Sun Feb 25 06:01:04 2018
@@ -2458,18 +2458,18 @@ def TestTypestate : InheritableAttr {
 // Type safety attributes for `void *' pointers and type tags.
 
 def ArgumentWithTypeTag : InheritableAttr {
-  let Spellings = [GNU<"argument_with_type_tag">,
-   GNU<"pointer_with_type_tag">];
+  let Spellings = [Clang<"argument_with_type_tag", 1>,
+   Clang<"pointer_with_type_tag", 1>];
+  let Subjects = SubjectList<[HasFunctionProto], ErrorDiag>;
   let Args = [IdentifierArgument<"ArgumentKind">,
   UnsignedArgument<"ArgumentIdx">,
   UnsignedArgument<"TypeTagIdx">,
-  BoolArgument<"IsPointer">];
-  let HasCustomParsing = 1;
+  BoolArgument<"IsPointer", /*opt*/0, /*fake*/1>];
   let Documentation = [ArgumentWithTypeTagDocs, PointerWithTypeTagDocs];
 }
 
 def TypeTagForDatatype : InheritableAttr {
-  let Spellings = [GNU<"type_tag_for_datatype">];
+  let Spellings = [Clang<"type_tag_for_datatype", 1>];
   let Args = [IdentifierArgument<"ArgumentKind">,
   TypeArgument<"MatchingCType">,
   BoolArgument<"LayoutCompatible">,

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=326052=326051=326052=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Sun Feb 25 06:01:04 2018
@@ -420,6 +420,10 @@ unsigned Parser::ParseClangAttributeArgs
 ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
 ScopeName, ScopeLoc, Syntax);
 break;
+  case AttributeList::AT_TypeTagForDatatype:
+ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
+ ScopeName, ScopeLoc, Syntax);
+break;
   }
   return Attrs.getList() ? Attrs.getList()->getNumArgs() : 0;
 }

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=326052=326051=326052=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Sun Feb 25 06:01:04 2018
@@ -4554,17 +4554,6 @@ static void handleArgumentWithTypeTagAtt
 return;
   }
   
-  if (!checkAttributeNumArgs(S, AL, 3))
-return;
-
-  IdentifierInfo *ArgumentKind = AL.getArgAsIdent(0)->Ident;
-
-  if (!isFunctionOrMethod(D) || !hasFunctionProto(D)) {
-S.Diag(AL.getLoc(), diag::err_attribute_wrong_decl_type)
-  << AL.getName() << ExpectedFunctionOrMethod;
-return;
-  }
-
   uint64_t ArgumentIdx;
   if (!checkFunctionOrMethodParameterIndex(S, D, AL, 2, AL.getArgAsExpr(1),
ArgumentIdx))
@@ -4575,7 +4564,7 @@ static void handleArgumentWithTypeTagAtt
TypeTagIdx))
 return;
 
-  bool IsPointer = (AL.getName()->getName() == "pointer_with_type_tag");
+  bool IsPointer = AL.getName()->getName() == "pointer_with_type_tag";
   if (IsPointer) {
 // Ensure that buffer has a pointer type.
 QualType BufferTy = getFunctionOrMethodParamType(D, ArgumentIdx);
@@ -4585,10 +4574,9 @@ static void handleArgumentWithTypeTagAtt
 }
   }
 
-  D->addAttr(::new (S.Context)
- ArgumentWithTypeTagAttr(AL.getRange(), S.Context, ArgumentKind,
- ArgumentIdx, TypeTagIdx, IsPointer,
- AL.getAttributeSpellingListIndex()));
+  D->addAttr(::new (S.Context) ArgumentWithTypeTagAttr(
+  AL.getRange(), S.Context, AL.getArgAsIdent(0)->Ident, ArgumentIdx,
+  TypeTagIdx, IsPointer, AL.getAttributeSpellingListIndex()));
 }
 
 static void handleTypeTagForDatatypeAttr(Sema , 

[PATCH] D43737: Improve -Winfinite-recursion

2018-02-25 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Please upload patches with full diff (-U99)


Repository:
  rC Clang

https://reviews.llvm.org/D43737



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


[PATCH] D43281: [AMDGPU] fixes for lds f32 builtins

2018-02-25 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

Can’t you just change the description to be the LangAS value? I also thought 
these happened to be the same already


https://reviews.llvm.org/D43281



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