[PATCH] D28445: [Analyzer] Extend taint propagation and checking

2017-02-15 Thread Vlad Tsyrklevich via Phabricator via cfe-commits
vlad.tsyrklevich added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:442
+
+const RecordDecl *RD = RT->getDecl()->getDefinition();
+for (const auto *I : RD->fields()) {

a.sidorin wrote:
> vlad.tsyrklevich wrote:
> > a.sidorin wrote:
> > > NoQ wrote:
> > > > We need to be careful in the case when we don't have the definition in 
> > > > the current translation unit. In this case we may still have derived 
> > > > symbols by casting the pointer into some blindly guessed type, which 
> > > > may be primitive or having well-defined primitive fields.
> > > > 
> > > > By the way, in D26837 i'm suspecting that there are other errors of 
> > > > this kind in the checker, eg. when a function returns a void pointer, 
> > > > we put taint on symbols of type "void", which is weird.
> > > > 
> > > > Adding Alexey who may recall something on this topic.
> > > I will check the correctness of this code sample because I have some 
> > > doubts about it.
> > > The problem of casts is hard because of our approach to put taints on 0th 
> > > elements. We lose casts and may get some strange void symbols. However, I 
> > > guess this patch isn't related to this problem directly.
> > Not sure which form of correctness you're interested in here but I'll bring 
> > up one issue I'm aware of: currently this will create a new SymbolDerived 
> > for an LCV sub-region, but it won't be correctly matched against in 
> > `isTainted()` because subsequent references to the same region will have a 
> > different SymbolDerived. This is the FIXME I mentioned below in 
> > `taint-generic.c` I have some idea on how to fix this but I think it will 
> > probably require more back and forth, hence why I didn't include it in this 
> > change. As it stands now, the sub-region tainting could be removed without 
> > changing the functionality of the current patch.
> Checking a default binding symbol here works because we're in PostStmt of the 
> call that creates this default binding. I think this machinery deserves a 
> comment, it was not evident for me initially.
> However, I don't like to create a SymbolDerived manually. The first idea is 
> to just use getSVal(MemRegion*) which will return a SymbolDerived if it is. 
> The second is to create... SymbolMetadata that will carry a taint (if the 
> value is not a symbol, for example). Not sure if second idea is sane enough, 
> I need some comments on it. Artem, Anna?
> Also, instead of referring to the base region, we may need to walk parents 
> one-by-one.
I'd rather just get rid of the tainted SymbolDerived and re-introduce it for 
discussion in the follow-up change as it's currently not functional anyway and 
there is some room for debate on the correct way to make tainting of 
sub-regions of LCVs work correctly. 

As far as walking parents one-by-one, my current understanding of the 
RegionStoreManager led me to believe that that would be unnecessary. Currently, 
all bindings are made as offsets from a base region, reference the 
implementation of `RegionBindingsRef::addBinding`. Is there another reason to 
walk the parents that I'm missing?



Comment at: lib/StaticAnalyzer/Core/RegionStore.cpp:502
+RegionBindingsRef B = getRegionBindings(S);
+const MemRegion *MR  = L.getRegion()->getBaseRegion();
+if (Optional V = B.getDefaultBinding(MR))

vlad.tsyrklevich wrote:
> a.sidorin wrote:
> > We get the LazyCompoundVal for some region but return the symbol for its 
> > base. It means that at least method name is very confusing.
> I believe that default bindings are only on base regions, so if you pass a 
> reference to `outer_struct.inner_struct` the default binding for that LCV 
> will be over `outer_struct`. I'm basing this on other references to LCVs in 
> Core/RegionStore.cpp but I could be wrong. Either way, I'd be happy to change 
> the interface to have the caller pass the correct MemRegion here.
One change we could introduce to make getDefaultBinding() more explicit is to 
have the caller pass LCV.getRegion()->getBaseRegion() instead of just passing 
the LCV. However, this has the disadvantage of hardcoding an implementation 
detail of RegionStoreManager into users of the StoreManager interface. I think 
the correct way forward here might just be to add a comment that mentions that 
currently RegionStoreManagers bindings are only over base regions. What do you 
think?


https://reviews.llvm.org/D28445



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


r295156 - Add a definition for __STRUCT_PARM_ALIGN__ for elfv2 and 64-bit darwin platforms to match what other compilers produce.

2017-02-15 Thread Eric Christopher via cfe-commits
Author: echristo
Date: Wed Feb 15 01:50:11 2017
New Revision: 295156

URL: http://llvm.org/viewvc/llvm-project?rev=295156&view=rev
Log:
Add a definition for __STRUCT_PARM_ALIGN__ for elfv2 and 64-bit darwin 
platforms to match what other compilers produce.

Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/test/Preprocessor/init.c

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=295156&r1=295155&r2=295156&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Wed Feb 15 01:50:11 2017
@@ -1232,6 +1232,11 @@ void PPCTargetInfo::getTargetDefines(con
   if (LongDoubleWidth == 128)
 Builder.defineMacro("__LONG_DOUBLE_128__");
 
+  // Define this for elfv2 (64-bit only) or 64-bit darwin.
+  if (ABI == "elfv2" ||
+  (getTriple().getOS() == llvm::Triple::Darwin && PointerWidth == 64))
+Builder.defineMacro("__STRUCT_PARM_ALIGN__", "16");
+
   if (Opts.AltiVec) {
 Builder.defineMacro("__VEC__", "10206");
 Builder.defineMacro("__ALTIVEC__");

Modified: cfe/trunk/test/Preprocessor/init.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=295156&r1=295155&r2=295156&view=diff
==
--- cfe/trunk/test/Preprocessor/init.c (original)
+++ cfe/trunk/test/Preprocessor/init.c Wed Feb 15 01:50:11 2017
@@ -5635,6 +5635,7 @@
 // PPC64LE:#define __SIZE_MAX__ 18446744073709551615UL
 // PPC64LE:#define __SIZE_TYPE__ long unsigned int
 // PPC64LE:#define __SIZE_WIDTH__ 64
+// PPC64LE:#define __STRUCT_PARM_ALIGN__ 16
 // PPC64LE:#define __UINT16_C_SUFFIX__
 // PPC64LE:#define __UINT16_MAX__ 65535
 // PPC64LE:#define __UINT16_TYPE__ unsigned short


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


Re: r295156 - Add a definition for __STRUCT_PARM_ALIGN__ for elfv2 and 64-bit darwin platforms to match what other compilers produce.

2017-02-15 Thread Tim Shen via cfe-commits
On Wed, Feb 15, 2017, 00:01 Eric Christopher via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: echristo
> Date: Wed Feb 15 01:50:11 2017
> New Revision: 295156
>
> URL: http://llvm.org/viewvc/llvm-project?rev=295156&view=rev
> Log:
> Add a definition for __STRUCT_PARM_ALIGN__ for elfv2 and 64-bit darwin
> platforms to match what other compilers produce.
>
> Modified:
> cfe/trunk/lib/Basic/Targets.cpp
> cfe/trunk/test/Preprocessor/init.c
>
> Modified: cfe/trunk/lib/Basic/Targets.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=295156&r1=295155&r2=295156&view=diff
>
> ==
> --- cfe/trunk/lib/Basic/Targets.cpp (original)
> +++ cfe/trunk/lib/Basic/Targets.cpp Wed Feb 15 01:50:11 2017
> @@ -1232,6 +1232,11 @@ void PPCTargetInfo::getTargetDefines(con
>if (LongDoubleWidth == 128)
>  Builder.defineMacro("__LONG_DOUBLE_128__");
>
> +  // Define this for elfv2 (64-bit only) or 64-bit darwin.
> +  if (ABI == "elfv2" ||
> +  (getTriple().getOS() == llvm::Triple::Darwin && PointerWidth == 64))
>

I also see a "DarwinTargetInfo". Maybe this should be put there as well?

+Builder.defineMacro("__STRUCT_PARM_ALIGN__", "16");
> +
>if (Opts.AltiVec) {
>  Builder.defineMacro("__VEC__", "10206");
>  Builder.defineMacro("__ALTIVEC__");
>
> Modified: cfe/trunk/test/Preprocessor/init.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=295156&r1=295155&r2=295156&view=diff
>
> ==
> --- cfe/trunk/test/Preprocessor/init.c (original)
> +++ cfe/trunk/test/Preprocessor/init.c Wed Feb 15 01:50:11 2017
> @@ -5635,6 +5635,7 @@
>  // PPC64LE:#define __SIZE_MAX__ 18446744073709551615UL
>  // PPC64LE:#define __SIZE_TYPE__ long unsigned int
>  // PPC64LE:#define __SIZE_WIDTH__ 64
> +// PPC64LE:#define __STRUCT_PARM_ALIGN__ 16
>  // PPC64LE:#define __UINT16_C_SUFFIX__
>  // PPC64LE:#define __UINT16_MAX__ 65535
>  // PPC64LE:#define __UINT16_TYPE__ unsigned short
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r295156 - Add a definition for __STRUCT_PARM_ALIGN__ for elfv2 and 64-bit darwin platforms to match what other compilers produce.

2017-02-15 Thread Eric Christopher via cfe-commits
The PPC one should inherit from this. You're right I should have tested it
though. Mostly ppc Darwin isn't well supported.

On Wed, Feb 15, 2017, 12:06 AM Tim Shen  wrote:

> On Wed, Feb 15, 2017, 00:01 Eric Christopher via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
> Author: echristo
> Date: Wed Feb 15 01:50:11 2017
> New Revision: 295156
>
> URL: http://llvm.org/viewvc/llvm-project?rev=295156&view=rev
> Log:
> Add a definition for __STRUCT_PARM_ALIGN__ for elfv2 and 64-bit darwin
> platforms to match what other compilers produce.
>
> Modified:
> cfe/trunk/lib/Basic/Targets.cpp
> cfe/trunk/test/Preprocessor/init.c
>
> Modified: cfe/trunk/lib/Basic/Targets.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=295156&r1=295155&r2=295156&view=diff
>
> ==
> --- cfe/trunk/lib/Basic/Targets.cpp (original)
> +++ cfe/trunk/lib/Basic/Targets.cpp Wed Feb 15 01:50:11 2017
> @@ -1232,6 +1232,11 @@ void PPCTargetInfo::getTargetDefines(con
>if (LongDoubleWidth == 128)
>  Builder.defineMacro("__LONG_DOUBLE_128__");
>
> +  // Define this for elfv2 (64-bit only) or 64-bit darwin.
> +  if (ABI == "elfv2" ||
> +  (getTriple().getOS() == llvm::Triple::Darwin && PointerWidth == 64))
>
>
> I also see a "DarwinTargetInfo". Maybe this should be put there as well?
>
> +Builder.defineMacro("__STRUCT_PARM_ALIGN__", "16");
> +
>if (Opts.AltiVec) {
>  Builder.defineMacro("__VEC__", "10206");
>  Builder.defineMacro("__ALTIVEC__");
>
> Modified: cfe/trunk/test/Preprocessor/init.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=295156&r1=295155&r2=295156&view=diff
>
> ==
> --- cfe/trunk/test/Preprocessor/init.c (original)
> +++ cfe/trunk/test/Preprocessor/init.c Wed Feb 15 01:50:11 2017
> @@ -5635,6 +5635,7 @@
>  // PPC64LE:#define __SIZE_MAX__ 18446744073709551615UL
>  // PPC64LE:#define __SIZE_TYPE__ long unsigned int
>  // PPC64LE:#define __SIZE_WIDTH__ 64
> +// PPC64LE:#define __STRUCT_PARM_ALIGN__ 16
>  // PPC64LE:#define __UINT16_C_SUFFIX__
>  // PPC64LE:#define __UINT16_MAX__ 65535
>  // PPC64LE:#define __UINT16_TYPE__ unsigned short
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28445: [Analyzer] Extend taint propagation and checking

2017-02-15 Thread Vlad Tsyrklevich via Phabricator via cfe-commits
vlad.tsyrklevich updated this revision to Diff 88493.
vlad.tsyrklevich added a comment.

Remove an unnecessary call to `getBaseRegion()`, remove the logic to create a 
new SymbolDerived as it's currently unused, and add a comment to reflect that 
`getLCVSymbol()` is called in a PostStmt and a default binding should always be 
present.


https://reviews.llvm.org/D28445

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
  lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  lib/StaticAnalyzer/Core/RegionStore.cpp
  test/Analysis/taint-generic.c

Index: test/Analysis/taint-generic.c
===
--- test/Analysis/taint-generic.c
+++ test/Analysis/taint-generic.c
@@ -169,6 +169,43 @@
   sock = socket(AF_LOCAL, SOCK_STREAM, 0);
   read(sock, buffer, 100);
   execl(buffer, "filename", 0); // no-warning
+
+  sock = socket(AF_INET, SOCK_STREAM, 0);
+  // References to both buffer and &buffer as an argument should taint the argument
+  read(sock, &buffer, 100);
+  execl(buffer, "filename", 0); // expected-warning {{Untrusted data is passed to a system call}}
+}
+
+void testStruct() {
+  struct {
+char buf[16];
+int length;
+  } tainted;
+
+  char buffer[16];
+  int sock;
+
+  sock = socket(AF_INET, SOCK_STREAM, 0);
+  read(sock, &tainted, sizeof(tainted));
+  __builtin_memcpy(buffer, tainted.buf, tainted.length); // expected-warning {{Untrusted data is used to specify the buffer size}}
+}
+
+void testStructArray() {
+  struct {
+char buf[16];
+struct {
+  int length;
+} st[1];
+  } tainted;
+
+  char buffer[16];
+  int sock;
+
+  sock = socket(AF_INET, SOCK_STREAM, 0);
+  read(sock, &tainted.buf[0], sizeof(tainted.buf));
+  read(sock, &tainted.st[0], sizeof(tainted.st));
+  // FIXME: tainted.st[0].length should be marked tainted
+  __builtin_memcpy(buffer, tainted.buf, tainted.st[0].length); // no-warning
 }
 
 int testDivByZero() {
Index: lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- lib/StaticAnalyzer/Core/RegionStore.cpp
+++ lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -494,6 +494,17 @@
 return getBinding(getRegionBindings(S), L, T);
   }
 
+  SVal getDefaultBinding(Store S, nonloc::LazyCompoundVal L) override {
+if (!L.getRegion())
+  return UnknownVal();
+
+RegionBindingsRef B = getRegionBindings(S);
+if (Optional V = B.getDefaultBinding(L.getRegion()))
+  return *V;
+
+return UnknownVal();
+  }
+
   SVal getBinding(RegionBindingsConstRef B, Loc L, QualType T = QualType());
 
   SVal getBindingForElement(RegionBindingsConstRef B, const ElementRegion *R);
Index: lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
+++ lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
@@ -65,6 +65,10 @@
   /// and thus, is tainted.
   static bool isStdin(const Expr *E, CheckerContext &C);
 
+  /// \brief Get the symbol for the region underlying a LazyCompoundVal.
+  static SymbolRef getLCVSymbol(CheckerContext &C,
+nonloc::LazyCompoundVal &LCV);
+
   /// \brief Given a pointer argument, get the symbol of the value it contains
   /// (points to).
   static SymbolRef getPointedToSymbol(CheckerContext &C, const Expr *Arg);
@@ -423,6 +427,25 @@
   return false;
 }
 
+SymbolRef GenericTaintChecker::getLCVSymbol(CheckerContext &C,
+nonloc::LazyCompoundVal &LCV) {
+  StoreManager &StoreMgr = C.getStoreManager();
+
+  // getLCVSymbol() is reached in a PostStmt so we can always expect a default
+  // binding to exist if one is present.
+  SymbolRef Sym = StoreMgr.getDefaultBinding(LCV.getStore(), LCV).getAsSymbol();
+  if (!Sym)
+return nullptr;
+
+  // If the LCV covers an entire base region return the default conjured symbol.
+  if (LCV.getRegion() == LCV.getRegion()->getBaseRegion())
+return Sym;
+
+  // Otherwise, return a nullptr as there's not yet a functional way to taint
+  // sub-regions of LCVs.
+  return nullptr;
+}
+
 SymbolRef GenericTaintChecker::getPointedToSymbol(CheckerContext &C,
   const Expr* Arg) {
   ProgramStateRef State = C.getState();
@@ -438,6 +461,10 @@
 dyn_cast(Arg->getType().getCanonicalType().getTypePtr());
   SVal Val = State->getSVal(*AddrLoc,
 ArgTy ? ArgTy->getPointeeType(): QualType());
+
+  if (auto LCV = Val.getAs())
+return getLCVSymbol(C, *LCV);
+
   return Val.getAsSymbol();
 }
 
Index: include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
@@ -59,6 +59,12 @@
   /// \return The value bound to the location \c loc.
   virtual SVal getBinding(S

[PATCH] D28445: [Analyzer] Extend taint propagation and checking

2017-02-15 Thread Vlad Tsyrklevich via Phabricator via cfe-commits
vlad.tsyrklevich added inline comments.



Comment at: lib/StaticAnalyzer/Core/RegionStore.cpp:502
+RegionBindingsRef B = getRegionBindings(S);
+const MemRegion *MR  = L.getRegion()->getBaseRegion();
+if (Optional V = B.getDefaultBinding(MR))

vlad.tsyrklevich wrote:
> vlad.tsyrklevich wrote:
> > a.sidorin wrote:
> > > We get the LazyCompoundVal for some region but return the symbol for its 
> > > base. It means that at least method name is very confusing.
> > I believe that default bindings are only on base regions, so if you pass a 
> > reference to `outer_struct.inner_struct` the default binding for that LCV 
> > will be over `outer_struct`. I'm basing this on other references to LCVs in 
> > Core/RegionStore.cpp but I could be wrong. Either way, I'd be happy to 
> > change the interface to have the caller pass the correct MemRegion here.
> One change we could introduce to make getDefaultBinding() more explicit is to 
> have the caller pass LCV.getRegion()->getBaseRegion() instead of just passing 
> the LCV. However, this has the disadvantage of hardcoding an implementation 
> detail of RegionStoreManager into users of the StoreManager interface. I 
> think the correct way forward here might just be to add a comment that 
> mentions that currently RegionStoreManagers bindings are only over base 
> regions. What do you think?
I spoke too soon, after digging a little deeper I realized that lookups using 
`RegionBindingsRef ::getDefaultBinding` converts to a base region check anyway 
in `BindingKey::Make`. Therefore it'd be better to just completely hide that 
implementation detail to the RegionBindings than hard coding it here 
unnecessarily. The updated revision corrects this.


https://reviews.llvm.org/D28445



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


[PATCH] D29910: [OpenMP] Specialize default schedule on a worksharing loop on the NVPTX device.

2017-02-15 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In https://reviews.llvm.org/D29910#676777, @arpith-jacob wrote:

> Hi Alexey,
>
> Thank you for reviewing this patch.
>
> > I don't like the idea of adding some kind of default scheduling, that is 
> > not defined in standard in Sema
>
> Actually, "default scheduling" is defined in the OpenMP spec.  It is called 
> "def-sched-var" and controls the scheduling of loops.  It's value is 
> implementation (compiler) defined.  So why not allow the target device to 
> choose this value in the compiler?
>
>   http://www.openmp.org/wp-content/uploads/openmp-4.5.pdf
>  
>   Section 2.3.1: ICV Descriptions, pg 46:
>   def-sched-var - controls the implementation defined default scheduling of 
> loop regions. There is one copy of this ICV per device.
>  
>   Section 2.3.2: ICV Initialization, pg 47:
>   Table 2.1:
>   def-sched-var   No environment variable  Initial value is 
> implementation defined
>  
>   Section 2.7.1.1: Determining the Schedule of a Worksharing Loop
>   When execution encounters a loop directive, the schedule clause (if any) on 
> the directive, and the run-sched-var and def-sched-var ICVs are used to 
> determine how loop iterations are assigned to threads. See Section 2.3 on 
> page 36 for details of how the values of the ICVs are determined. If the loop 
> directive does not have a schedule clause then the current value of the 
> def-sched-var ICV determines the schedule.
>
>
> I've reworked the patch to handle the default scheduling in Sema and removed 
> the function from OpenMPKind.cpp.  Please let me know if this looks good.
>
> I can rewrite the patch as you suggested, involving NVPTX specific RT, but I 
> think the code will look quite ugly.


Arpith, yes, there is such variable. But also standard says, that it is device 
specific. My opinion, all device-specific things must be defined by runtime 
library or at least runtime-support class, not by Sema. Sema must be as much 
platform independent as possible


https://reviews.llvm.org/D29910



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


Re: r295114 - Improve diagnostic reporting when using __declspec without enabling __declspec as a keyword.

2017-02-15 Thread Mikael Holmén via cfe-commits

Hi,

Saw now that it's already been fixed. Sorry for the spam :/

Regards,
Mikael

On 02/15/2017 07:39 AM, Mikael Holmén wrote:

Hi Aaron,


On 02/14/2017 11:47 PM, Aaron Ballman via cfe-commits wrote:

Author: aaronballman
Date: Tue Feb 14 16:47:20 2017
New Revision: 295114

URL: http://llvm.org/viewvc/llvm-project?rev=295114&view=rev
Log:
Improve diagnostic reporting when using __declspec without enabling
__declspec as a keyword.

Fixes PR31936.

Added:
cfe/trunk/test/Parser/declspec-recovery.c
cfe/trunk/test/Parser/declspec-supported.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/lib/Parse/ParseDecl.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=295114&r1=295113&r2=295114&view=diff

==

--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Tue Feb 14
16:47:20 2017
@@ -176,6 +176,9 @@ def warn_gcc_attribute_location : Warnin
 def warn_attribute_no_decl : Warning<
   "attribute %0 ignored, because it is not attached to a declaration">,
   InGroup;
+def err_ms_attributes_not_enabled : Error<
+  "'__declspec' attributes are not enabled; use '-fdeclspec' or "
+  "'-fms-extensions' to enable support for __declspec attributes">;
 def err_expected_method_body : Error<"expected method body">;
 def err_declspec_after_virtspec : Error<
   "'%0' qualifier may not appear after the virtual specifier '%1'">;

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=295114&r1=295113&r2=295114&view=diff

==

--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Tue Feb 14 16:47:20 2017
@@ -2966,6 +2966,31 @@ void Parser::ParseDeclarationSpecifiers(
   if (DS.hasTypeSpecifier())
 goto DoneWithDeclSpec;

+  // If the token is an identifier named "__declspec" and Microsoft
+  // extensions are not enabled, it is likely that there will be
cascading
+  // parse errors if this really is a __declspec attribute.
Attempt to
+  // recognize that scenario and recover gracefully.
+  if (!getLangOpts().DeclSpecKeyword && Tok.is(tok::identifier) &&
+  Tok.getIdentifierInfo()->getName().equals("__declspec")) {
+Diag(Loc, diag::err_ms_attributes_not_enabled);
+
+// The next token should be an open paren. If it is, eat the
entire
+// attribute declaration and continue.
+if (NextToken().is(tok::l_paren)) {
+  // Consume the __declspec identifier.
+  SourceLocation Loc = ConsumeToken();


I get a warning about Loc not being used here:

../tools/clang/lib/Parse/ParseDecl.cpp:2981:26: error: unused variable
'Loc' [-Werror,-Wunused-variable]
  SourceLocation Loc = ConsumeToken();

Regards,
Mikael


+
+  // Eat the parens and everything between them.
+  BalancedDelimiterTracker T(*this, tok::l_paren);
+  if (T.consumeOpen()) {
+assert(false && "Not a left paren?");
+return;
+  }
+  T.skipToEnd();
+  continue;
+}
+  }
+
   // In C++, check to see if this is a scope specifier like
foo::bar::, if
   // so handle it as such.  This is important for ctor parsing.
   if (getLangOpts().CPlusPlus) {

Added: cfe/trunk/test/Parser/declspec-recovery.c
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/declspec-recovery.c?rev=295114&view=auto

==

--- cfe/trunk/test/Parser/declspec-recovery.c (added)
+++ cfe/trunk/test/Parser/declspec-recovery.c Tue Feb 14 16:47:20 2017
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -verify %s
+
+__declspec(naked) void f(void) {} // expected-error{{'__declspec'
attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to
enable support for __declspec attributes}}
+
+struct S {
+  __declspec(property(get=Getter, put=Setter)) int X; //
expected-error{{'__declspec' attributes are not enabled; use
'-fdeclspec' or '-fms-extensions' to enable support for __declspec
attributes}}
+  int Y;
+};

Added: cfe/trunk/test/Parser/declspec-supported.c
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/declspec-supported.c?rev=295114&view=auto

==

--- cfe/trunk/test/Parser/declspec-supported.c (added)
+++ cfe/trunk/test/Parser/declspec-supported.c Tue Feb 14 16:47:20 2017
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only
-fms-extensions -verify %s
+// RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -fdeclspec
-verify %s
+// expect

[PATCH] D28862: [compiler-rt] [test] Use approximate comparison on float types

2017-02-15 Thread Michał Górny via Phabricator via cfe-commits
mgorny abandoned this revision.
mgorny added a comment.

I've opened http://bugs.llvm.org/show_bug.cgi?id=31964 to track this further. I 
don't really have time to look into it in more detail at the moment.


Repository:
  rL LLVM

https://reviews.llvm.org/D28862



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


r295163 - [XRAY][MIPS] Add -fxray-instrument for mips/mipsel/mips64/mips64el

2017-02-15 Thread Sagar Thakur via cfe-commits
Author: slthakur
Date: Wed Feb 15 04:41:38 2017
New Revision: 295163

URL: http://llvm.org/viewvc/llvm-project?rev=295163&view=rev
Log:
[XRAY][MIPS] Add -fxray-instrument for mips/mipsel/mips64/mips64el

Summary: Adds xray instrument option for mips/mipsel/mips64/mips64el.

Reviewed by sdardis, dberris
Differential: D27698

Added:
cfe/trunk/test/CodeGen/xray-attributes-supported-mips.cpp
Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/XRay/xray-instrument-cpu.c

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=295163&r1=295162&r2=295163&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Feb 15 04:41:38 2017
@@ -5065,6 +5065,10 @@ void Clang::ConstructJob(Compilation &C,
   case llvm::Triple::arm:
   case llvm::Triple::aarch64:
   case llvm::Triple::ppc64le:
+  case llvm::Triple::mips:
+  case llvm::Triple::mipsel:
+  case llvm::Triple::mips64:
+  case llvm::Triple::mips64el:
 // Supported.
 break;
   default:

Added: cfe/trunk/test/CodeGen/xray-attributes-supported-mips.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/xray-attributes-supported-mips.cpp?rev=295163&view=auto
==
--- cfe/trunk/test/CodeGen/xray-attributes-supported-mips.cpp (added)
+++ cfe/trunk/test/CodeGen/xray-attributes-supported-mips.cpp Wed Feb 15 
04:41:38 2017
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -fxray-instrument -std=c++11 -x c++ -emit-llvm -o - 
-triple mips-unknown-linux-gnu | FileCheck %s
+// RUN: %clang_cc1 %s -fxray-instrument -std=c++11 -x c++ -emit-llvm -o - 
-triple mipsel-unknown-linux-gnu | FileCheck %s
+// RUN: %clang_cc1 %s -fxray-instrument -std=c++11 -x c++ -emit-llvm -o - 
-triple mips64-unknown-linux-gnu | FileCheck %s
+// RUN: %clang_cc1 %s -fxray-instrument -std=c++11 -x c++ -emit-llvm -o - 
-triple mips64el-unknown-linux-gnu | FileCheck %s
+
+// Make sure that the LLVM attribute for XRay-annotated functions do show up.
+[[clang::xray_always_instrument]] void foo() {
+// CHECK: define void @_Z3foov() #0
+};
+
+[[clang::xray_never_instrument]] void bar() {
+// CHECK: define void @_Z3barv() #1
+};
+
+// CHECK: #0 = {{.*}}"function-instrument"="xray-always"
+// CHECK: #1 = {{.*}}"function-instrument"="xray-never"

Modified: cfe/trunk/test/Driver/XRay/xray-instrument-cpu.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/XRay/xray-instrument-cpu.c?rev=295163&r1=295162&r2=295163&view=diff
==
--- cfe/trunk/test/Driver/XRay/xray-instrument-cpu.c (original)
+++ cfe/trunk/test/Driver/XRay/xray-instrument-cpu.c Wed Feb 15 04:41:38 2017
@@ -1,4 +1,4 @@
 // RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
-// XFAIL: amd64-, x86_64-, x86_64h-, arm, aarch64, arm64, powerpc64le-
+// XFAIL: amd64-, x86_64-, x86_64h-, arm, aarch64, arm64, powerpc64le-, mips, 
mipsel, mips64, mips64el
 // REQUIRES: linux
 typedef int a;


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


[PATCH] D28278: [StaticAnalyzer] dont show wrong 'garbage value' warning when there is array index out of bounds

2017-02-15 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki added a comment.

I am not against that the error is shown as long as it's not misleading/wrong. 
To avoid misleading, in my humble opinion the error message should say "array 
index out of bounds".


Repository:
  rL LLVM

https://reviews.llvm.org/D28278



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


[PATCH] D28297: [StaticAnalyzer] Fix crash in CastToStructChecker

2017-02-15 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki added a comment.

In https://reviews.llvm.org/D28297#642523, @NoQ wrote:

> Looks good. I assume the crash is in `getTypeInfo()`; do you have any idea 
> what are exact prerequisites for using this method? So that there were no 
> more crashes here.


Yes. The crash happens during the `getTypeInfo()` call. I don't know what 
prerequisites are interesting to check.

The Type pointer returned by getTypePtr() must be nonnull and valid. The method 
`clang::Type::getTypeClass()` is called using that type pointer. If that 
returns `Type::Record` then the Type pointer is casted to a RecordType. And  
`RecordType::getDecl()` is called. The RecordDecl that is returned by that call 
is passed to `getASTRecordLayout()` shown below.

The crash occurs on the first assert in this code:

  const ASTRecordLayout &
  ASTContext::getASTRecordLayout(const RecordDecl *D) const {
// These asserts test different things.  A record has a definition
// as soon as we begin to parse the definition.  That definition is
// not a complete definition (which is what isDefinition() tests)
// until we *finish* parsing the definition.
  
if (D->hasExternalLexicalStorage() && !D->getDefinition())
  getExternalSource()->CompleteType(const_cast(D));
  
D = D->getDefinition();
assert(D && "Cannot get layout of forward declarations!");
assert(!D->isInvalidDecl() && "Cannot get layout of invalid decl!");
assert(D->isCompleteDefinition() && "Cannot layout type before complete!");
  

I am not sure I can write testcases that prevent regressions but do you think I 
should add `isInvalidDecl()` and `isCompleteDefinition()` also?


Repository:
  rL LLVM

https://reviews.llvm.org/D28297



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


r295167 - Removed stale comment. NFC.

2017-02-15 Thread Serge Pavlov via cfe-commits
Author: sepavloff
Date: Wed Feb 15 05:34:11 2017
New Revision: 295167

URL: http://llvm.org/viewvc/llvm-project?rev=295167&view=rev
Log:
Removed stale comment. NFC.

The case of extern inline functions in GNU89 mode is now handled
in `canRedefineFunction`, which has appropriate comment.

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

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=295167&r1=295166&r2=295167&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Feb 15 05:34:11 2017
@@ -11692,8 +11692,6 @@ void
 Sema::CheckForFunctionRedefinition(FunctionDecl *FD,
const FunctionDecl *EffectiveDefinition,
SkipBodyInfo *SkipBody) {
-  // Don't complain if we're in GNU89 mode and the previous definition
-  // was an extern inline function.
   const FunctionDecl *Definition = EffectiveDefinition;
   if (!Definition)
 if (!FD->isDefined(Definition))


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


[PATCH] D13289: [libc++] Provide additional templates for valarray transcendentals that satisfy the standard synopsis

2017-02-15 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

I've raised PR31966 to poke this :)


https://reviews.llvm.org/D13289



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


[PATCH] D23421: [Clang-tidy] CERT-DCL58-CPP (checker for std namespace modification)

2017-02-15 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun updated this revision to Diff 88506.
xazax.hun marked 3 inline comments as done.
xazax.hun retitled this revision from "[Clang-tidy] CERT-MSC53-CPP (checker for 
std namespace modification)" to "[Clang-tidy] CERT-DCL58-CPP (checker for std 
namespace modification)".
xazax.hun edited the summary of this revision.
xazax.hun added a comment.

- Add a simulated system header for tests.
- Do not warn on explicit template specializations within std namespace.
- Do not warn when the namespace is empty (so no declaration is introduced 
within the namespace)
- Extended the test cases.
- Added a link to the documentation
- Updated the name of the checker in the description and title of this revision.


https://reviews.llvm.org/D23421

Files:
  clang-tidy/cert/CERTTidyModule.cpp
  clang-tidy/cert/CMakeLists.txt
  clang-tidy/cert/DontModifyStdNamespaceCheck.cpp
  clang-tidy/cert/DontModifyStdNamespaceCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cert-dcl58-cpp.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/Inputs/Headers/system.h
  test/clang-tidy/cert-dcl58-cpp.cpp

Index: test/clang-tidy/cert-dcl58-cpp.cpp
===
--- /dev/null
+++ test/clang-tidy/cert-dcl58-cpp.cpp
@@ -0,0 +1,64 @@
+// RUN: %check_clang_tidy %s cert-dcl58-cpp %t -- -- -std=c++1z -I %S/Inputs/Headers
+
+#include "system.h"
+
+namespace A {
+  namespace B {
+int b;
+  }
+}
+
+namespace A {
+  namespace B {
+int c;
+  }
+}
+
+namespace posix {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: modification of 'posix' namespace can result in undefined behavior [cert-dcl58-cpp]
+  namespace vmi {
+  }
+}
+
+namespace std {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: modification of 'std' namespace can
+  int stdInt;
+}
+
+namespace foobar {
+  namespace std {
+int bar;
+  }
+}
+
+namespace posix::a {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: modification of 'posix' namespace 
+}
+
+enum class MyError {
+  ErrorA,
+  ErrorB
+};
+
+namespace std {
+template <>
+struct is_error_code_enum : std::true_type {};
+}
+
+enum class MyError2 {
+  Error2A,
+  Error2B
+};
+
+namespace std {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: modification of 'std' namespace 
+template <>
+struct is_error_code_enum : std::true_type {};
+
+int foobar;
+}
+
+using namespace std;
+
+int x;
+
Index: test/clang-tidy/Inputs/Headers/system.h
===
--- /dev/null
+++ test/clang-tidy/Inputs/Headers/system.h
@@ -0,0 +1,21 @@
+#pragma clang system_header
+
+namespace std {
+
+template
+struct integral_constant {
+static constexpr T value = v;
+typedef T value_type;
+typedef integral_constant type;
+constexpr operator value_type() const noexcept { return value; }
+};
+
+template 
+using bool_constant = integral_constant;
+using true_type = bool_constant;
+using false_type = bool_constant;
+
+template
+struct is_error_code_enum : false_type {};
+}
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -8,6 +8,7 @@
cert-dcl03-c (redirects to misc-static-assert) 
cert-dcl50-cpp
cert-dcl54-cpp (redirects to misc-new-delete-overloads) 
+   cert-dcl58-cpp
cert-dcl59-cpp (redirects to google-build-namespaces) 
cert-env33-c
cert-err09-cpp (redirects to misc-throw-by-value-catch-by-reference) 
Index: docs/clang-tidy/checks/cert-dcl58-cpp.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cert-dcl58-cpp.rst
@@ -0,0 +1,21 @@
+.. title:: clang-tidy - cert-dcl58-cpp
+
+cert-dcl58-cpp
+==
+
+Modification of the ``std`` or ``posix`` namespace can result in undefined
+behavior.
+This check warns for such modifications.
+
+Examples:
+
+.. code-block:: c++
+
+  namespace std {
+int x; // May cause undefined behavior.
+  }
+
+
+This check corresponds to the CERT C++ Coding Standard rule
+`DCL58-CPP. Do not modify the standard namespaces
+`_.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New `cert-dcl58-cpp
+  `_ check
+
+  Finds modification of the ``std`` or ``posix`` namespace.
+
 - New `safety-no-assembler
   `_ check
 
Index: clang-tidy/cert/DontModifyStdNamespaceCheck.h
===
--- /dev/null
+++ clang-tidy/cert/DontModifyStdNamespaceCheck.h
@@ -0,0 +1,36 @@
+//===--- DontModifyStdNamespaceCheck.h - clang-tidy--

[PATCH] D29032: [mips] Define macros related to -mabicalls in the preprocessor

2017-02-15 Thread Simon Dardis via Phabricator via cfe-commits
sdardis added a comment.

@joerg ping?


https://reviews.llvm.org/D29032



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


r295172 - Use dedicated method instead of copying conditions. NFC.

2017-02-15 Thread Serge Pavlov via cfe-commits
Author: sepavloff
Date: Wed Feb 15 06:30:35 2017
New Revision: 295172

URL: http://llvm.org/viewvc/llvm-project?rev=295172&view=rev
Log:
Use dedicated method instead of copying conditions. NFC.

Modified:
cfe/trunk/lib/AST/Decl.cpp

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=295172&r1=295171&r2=295172&view=diff
==
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Wed Feb 15 06:30:35 2017
@@ -2503,7 +2503,7 @@ bool FunctionDecl::isVariadic() const {
 
 bool FunctionDecl::hasBody(const FunctionDecl *&Definition) const {
   for (auto I : redecls()) {
-if (I->Body || I->IsLateTemplateParsed) {
+if (I->doesThisDeclarationHaveABody()) {
   Definition = I;
   return true;
 }


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


[PATCH] D29957: [clang-tidy] Ignore instantiated functions and static data members of classes in misc-definitions-in-headers.

2017-02-15 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG


https://reviews.llvm.org/D29957



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


[PATCH] D28768: [clang-tidy] Add check 'modernize-return-braced-init-list'

2017-02-15 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LGTM. Please wait for Aaron as well.


Repository:
  rL LLVM

https://reviews.llvm.org/D28768



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


[PATCH] D29886: [clangd] Wire up ASTUnit and publish diagnostics with it.

2017-02-15 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer updated this revision to Diff 88515.
bkramer marked 16 inline comments as done.
bkramer added a comment.

- Address review comments.


https://reviews.llvm.org/D29886

Files:
  clangd/ASTManager.cpp
  clangd/ASTManager.h
  clangd/CMakeLists.txt
  clangd/ClangDMain.cpp
  clangd/DocumentStore.h
  test/clangd/diagnostics.test

Index: test/clangd/diagnostics.test
===
--- /dev/null
+++ test/clangd/diagnostics.test
@@ -0,0 +1,17 @@
+# RUN: clangd < %s | FileCheck %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+#
+Content-Length: 152
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///foo.c","languageId":"c","version":1,"text":"void main() {}"}}}
+#
+# CHECK: {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///foo.c","diagnostics":[{"range":{"start": {"line": 0, "character": 1}, "end": {"line": 0, "character": 1}},"severity":2,"message":"return type of 'main' is not 'int'"},{"range":{"start": {"line": 0, "character": 1}, "end": {"line": 0, "character": 1}},"severity":3,"message":"change return type to 'int'"}]}}
+#
+#
+Content-Length: 44
+
+{"jsonrpc":"2.0","id":5,"method":"shutdown"}
Index: clangd/DocumentStore.h
===
--- clangd/DocumentStore.h
+++ clangd/DocumentStore.h
@@ -12,27 +12,62 @@
 
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/StringMap.h"
+#include 
 #include 
 
 namespace clang {
 namespace clangd {
+class DocumentStore;
+
+struct DocumentStoreListener {
+  virtual ~DocumentStoreListener() = default;
+  virtual void onDocumentAdd(StringRef Uri) {}
+  virtual void onDocumentRemove(StringRef Uri) {}
+};
 
 /// A container for files opened in a workspace, addressed by URI. The contents
 /// are owned by the DocumentStore.
 class DocumentStore {
 public:
   /// Add a document to the store. Overwrites existing contents.
-  void addDocument(StringRef Uri, StringRef Text) { Docs[Uri] = Text; }
+  void addDocument(StringRef Uri, StringRef Text) {
+std::lock_guard Guard(DocsMutex);
+Docs[Uri] = Text;
+for (const auto &Listener : Listeners)
+  Listener->onDocumentAdd(Uri);
+  }
   /// Delete a document from the store.
-  void removeDocument(StringRef Uri) { Docs.erase(Uri); }
+  void removeDocument(StringRef Uri) { Docs.erase(Uri);
+std::lock_guard Guard(DocsMutex);
+for (const auto &Listener : Listeners)
+  Listener->onDocumentRemove(Uri);
+  }
   /// Retrieve a document from the store. Empty string if it's unknown.
-  StringRef getDocument(StringRef Uri) const {
-auto I = Docs.find(Uri);
-return I == Docs.end() ? StringRef("") : StringRef(I->second);
+  std::string getDocument(StringRef Uri) const {
+// FIXME: This could be a reader lock.
+std::lock_guard Guard(DocsMutex);
+return Docs.lookup(Uri);
+  }
+
+  /// Add a listener. Does not take ownership.
+  void addListener(DocumentStoreListener *DSL) {
+Listeners.push_back(DSL);
+  }
+
+  /// Get name and constents of all documents in this store.
+  std::vector> getAllDocuments() const {
+std::vector> AllDocs;
+std::lock_guard Guard(DocsMutex);
+for (const auto &P : Docs)
+  AllDocs.emplace_back(P.first(), P.second);
+return AllDocs;
   }
 
 private:
   llvm::StringMap Docs;
+  std::vector Listeners;
+
+  mutable std::mutex DocsMutex;
 };
 
 } // namespace clangd
Index: clangd/ClangDMain.cpp
===
--- clangd/ClangDMain.cpp
+++ clangd/ClangDMain.cpp
@@ -7,6 +7,7 @@
 //
 //===--===//
 
+#include "ASTManager.h"
 #include "DocumentStore.h"
 #include "JSONRPCDispatcher.h"
 #include "ProtocolHandlers.h"
@@ -27,6 +28,8 @@
   // Set up a document store and intialize all the method handlers for JSONRPC
   // dispatching.
   DocumentStore Store;
+  ASTManager AST(Out, Store);
+  Store.addListener(&AST);
   JSONRPCDispatcher Dispatcher(llvm::make_unique(Out));
   Dispatcher.registerHandler("initialize",
  llvm::make_unique(Out));
Index: clangd/CMakeLists.txt
===
--- clangd/CMakeLists.txt
+++ clangd/CMakeLists.txt
@@ -1,4 +1,5 @@
 add_clang_executable(clangd
+  ASTManager.cpp
   ClangDMain.cpp
   JSONRPCDispatcher.cpp
   Protocol.cpp
@@ -8,5 +9,7 @@
 target_link_libraries(clangd
   clangBasic
   clangFormat
+  clangFrontend
+  clangTooling
   LLVMSupport
   )
Index: clangd/ASTManager.h
===
--- /dev/null
+++ clangd/ASTManager.h
@@ -0,0 +1,77 @@
+//===--- ASTManager.h - Clang AST manager ---*- C++ -*-===//
+//
+//

[PATCH] D29886: [clangd] Wire up ASTUnit and publish diagnostics with it.

2017-02-15 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer added inline comments.



Comment at: clangd/ASTManager.cpp:21
+using namespace clang;
+using namespace clangd;
+

ioeric wrote:
> Any reason not to wrap code in namespaces instead?
I don't really have an opinion one way or the other, but this seems to be the 
preferred way of doing this in LLVM.



Comment at: clangd/ASTManager.cpp:70
+  if (!RequestIsPending && !Done)
+ClangRequestCV.wait(Lock);
+

klimek wrote:
> arphaman wrote:
> >  I believe `std::condition_variable` may also be unblocked spuriously when 
> > `wait` is called without a predicate, which would lead to an empty `File` 
> > down below.
> Yep, +1, the general pattern is to put while loops around.
> It might actually be simpler to write that with a queue from the start (note 
> that this would make the request queueing side somewhat less simple):
>   ... Lock(RequestLock);
>   while (Requests.empty() && !Done) {
> ClangRequestCV.wait(Lock);
>   }
>   if (Done) return;
>   File = Request.pop_front();
>   ClangRequestCV.notify_all();
>   ...
> 
>   the while loop  can be written somewhat simpler with the pred version:
>   ClangRequestCV.wait(Lock, [&] { return !Request.empty() || Done; });
> 
Added the lambda. The current state is pretty weird, but making it a queue just 
to drop random elements from that queue is even weirder :(



Comment at: clangd/ASTManager.cpp:148
+  std::string Error;
+  I = tooling::CompilationDatabase::autoDetectFromSource(Uri, Error);
+  return I.get();

krasimir wrote:
> Do you have an idea about a proper error handling if Error?
For now I'll send it to logs()



Comment at: clangd/ASTManager.h:34
+
+  void onDocumentAdd(StringRef Uri, const DocumentStore &Docs) override;
+  // FIXME: Implement onDocumentRemove

klimek wrote:
> At a first glance, it's weird that we have a global document store, but get a 
> document store for each notification. This at least needs documentation.
This is leftover from an earlier design. Removed.



Comment at: clangd/ASTManager.h:67
+  /// Setting Done to true will make the worker thread terminate.
+  std::atomic Done;
+};

klimek wrote:
> arphaman wrote:
> > It looks like `Done` is always accessed in a scope where `RequestLock` is 
> > locked, so `atomic` doesn't seem needed here.
> Yea, after only having read this header, it looks like we might want to pull 
> out a Request as an abstraction.
Wrapped all the guarded variables in a struct.



Comment at: clangd/ClangDMain.cpp:32
+  auto *AST = new ASTManager(Out, Store);
+  Store.addListener(std::unique_ptr(AST));
   JSONRPCDispatcher Dispatcher(llvm::make_unique(Out));

klimek wrote:
> krasimir wrote:
> > Why not directly `Store.addListener(llvm::make_unique(Out, 
> > Store));`?
> Why's the ASTManager not on the stack?
Fixed. Lifetime is no longer managed by the DocumentStore (that was a bit weird)



Comment at: clangd/DocumentStore.h:39
+for (const auto &Listener : Listeners)
+  Listener->onDocumentAdd(Uri, *this);
+  }

klimek wrote:
> krasimir wrote:
> > Is only the main thread supposed to addDocument-s? Otherwise the listener 
> > notifications might need to be guarded.
> It would always be the responsibility of the callee to guard.
Added guard for now.



Comment at: clangd/DocumentStore.h:42
   /// Delete a document from the store.
-  void removeDocument(StringRef Uri) { Docs.erase(Uri); }
+  void removeDocument(StringRef Uri) { Docs.erase(Uri);
+for (const auto &Listener : Listeners)

klimek wrote:
> krasimir wrote:
> > cierpuchaw wrote:
> > > cierpuchaw wrote:
> > > > Shouldn't this be called under a lock_guard?
> > > I should've reworded my comment before submitting it. By 'this' I'm 
> > > referring to the 'Docs.erase()' part, not the whole function.
> > > 
> > Even under a guard, it may potentially still be unsafe since workers may 
> > operate on erased/modified StringRef-s.
> That depends on the guarantees made, and when we create copies :)
Added guard.



Comment at: clangd/DocumentStore.h:51
 auto I = Docs.find(Uri);
 return I == Docs.end() ? StringRef("") : StringRef(I->second);
   }

krasimir wrote:
> StringRef doesn't own the underlying data, right? What if I erase it in the 
> meantime?
I guess it makes sense to create copies here. Somewhat sad but safe.



Comment at: clangd/DocumentStore.h:63
+  AllDocs.emplace_back(P.first(), P.second);
+return AllDocs;
+  }

krasimir wrote:
> Same thing, shouldn't these be strings?
Done.


https://reviews.llvm.org/D29886



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


[PATCH] D29986: Fix crash when an incorrect redeclaration only differs in __unaligned type-qualifier

2017-02-15 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 created this revision.

This patch fixes an assertion that is hit when a redeclaration with differing 
types only differs in the unaligned type-qualifier.


https://reviews.llvm.org/D29986

Files:
  lib/AST/ASTContext.cpp
  test/Sema/unaligned-qualifier.c


Index: test/Sema/unaligned-qualifier.c
===
--- /dev/null
+++ test/Sema/unaligned-qualifier.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-extensions
+
+int __unaligned * p1; // expected-note {{previous definition is here}}
+int * p1; // expected-error {{redefinition of 'p1' with a different type: 'int 
*' vs '__unaligned int *'}}
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -8077,7 +8077,8 @@
 // mismatch.
 if (LQuals.getCVRQualifiers() != RQuals.getCVRQualifiers() ||
 LQuals.getAddressSpace() != RQuals.getAddressSpace() ||
-LQuals.getObjCLifetime() != RQuals.getObjCLifetime())
+LQuals.getObjCLifetime() != RQuals.getObjCLifetime() ||
+LQuals.hasUnaligned() != RQuals.hasUnaligned())
   return QualType();
 
 // Exactly one GC qualifier difference is allowed: __strong is


Index: test/Sema/unaligned-qualifier.c
===
--- /dev/null
+++ test/Sema/unaligned-qualifier.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-extensions
+
+int __unaligned * p1; // expected-note {{previous definition is here}}
+int * p1; // expected-error {{redefinition of 'p1' with a different type: 'int *' vs '__unaligned int *'}}
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -8077,7 +8077,8 @@
 // mismatch.
 if (LQuals.getCVRQualifiers() != RQuals.getCVRQualifiers() ||
 LQuals.getAddressSpace() != RQuals.getAddressSpace() ||
-LQuals.getObjCLifetime() != RQuals.getObjCLifetime())
+LQuals.getObjCLifetime() != RQuals.getObjCLifetime() ||
+LQuals.hasUnaligned() != RQuals.hasUnaligned())
   return QualType();
 
 // Exactly one GC qualifier difference is allowed: __strong is
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D23421: [Clang-tidy] CERT-DCL58-CPP (checker for std namespace modification)

2017-02-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/cert/DontModifyStdNamespaceCheck.cpp:28
+  anyOf(hasName("std"), hasName("posix")),
+  has(decl(unless(cxxRecordDecl(isExplicitTemplateSpecialization())
+  .bind("nmspc"),

I think this is missing function declarations that are explicit template 
specializations as well (a common instance of this is specializing std::swap).



Comment at: test/clang-tidy/cert-dcl58-cpp.cpp:60
+}
+
+using namespace std;

I'd like to see a test where the user specializes a function template, like 
`swap()` to make sure we don't diagnose on that.


https://reviews.llvm.org/D23421



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


[libcxxabi] r295175 - Fix couple of test failures when using the LIBCXXABI_SILENT_TERMINATE mode.

2017-02-15 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Wed Feb 15 07:43:05 2017
New Revision: 295175

URL: http://llvm.org/viewvc/llvm-project?rev=295175&view=rev
Log:
Fix couple of test failures when using the LIBCXXABI_SILENT_TERMINATE mode.

When libcxxabi is built in LIBCXXABI_SILENT_TERMINATE mode, libcxx test suite 
reports
two failures:

  std/depr/exception.unexpected/set.unexpected/get_unexpected.pass.cpp
  std/depr/exception.unexpected/set.unexpected/set_unexpected.pass.cpp

This is because the default unexpected handler is set to std::abort instead of
std::terminate which these tests expect.

Modified:
libcxxabi/trunk/src/cxa_default_handlers.cpp

Modified: libcxxabi/trunk/src/cxa_default_handlers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_default_handlers.cpp?rev=295175&r1=295174&r2=295175&view=diff
==
--- libcxxabi/trunk/src/cxa_default_handlers.cpp (original)
+++ libcxxabi/trunk/src/cxa_default_handlers.cpp Wed Feb 15 07:43:05 2017
@@ -90,7 +90,7 @@ static std::terminate_handler default_te
 static std::terminate_handler default_unexpected_handler = 
demangling_unexpected_handler;
 #else
 static std::terminate_handler default_terminate_handler = std::abort;
-static std::terminate_handler default_unexpected_handler = std::abort;
+static std::terminate_handler default_unexpected_handler = std::terminate;
 #endif
 
 //


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


[PATCH] D29886: [clangd] Wire up ASTUnit and publish diagnostics with it.

2017-02-15 Thread Wojciech Cierpucha via Phabricator via cfe-commits
cierpuchaw added inline comments.



Comment at: clangd/DocumentStore.h:42
   /// Delete a document from the store.
-  void removeDocument(StringRef Uri) { Docs.erase(Uri); }
+  void removeDocument(StringRef Uri) { Docs.erase(Uri);
+for (const auto &Listener : Listeners)

bkramer wrote:
> klimek wrote:
> > krasimir wrote:
> > > cierpuchaw wrote:
> > > > cierpuchaw wrote:
> > > > > Shouldn't this be called under a lock_guard?
> > > > I should've reworded my comment before submitting it. By 'this' I'm 
> > > > referring to the 'Docs.erase()' part, not the whole function.
> > > > 
> > > Even under a guard, it may potentially still be unsafe since workers may 
> > > operate on erased/modified StringRef-s.
> > That depends on the guarantees made, and when we create copies :)
> Added guard.
'Docs.erase(Uri);' is still outside the critical section. It's easy to miss 
because of its placement directly after '{'.


https://reviews.llvm.org/D29886



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


[clang-tools-extra] r295176 - [clang-tidy] Don't warn about call to unresolved operator*

2017-02-15 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Wed Feb 15 08:01:41 2017
New Revision: 295176

URL: http://llvm.org/viewvc/llvm-project?rev=295176&view=rev
Log:
[clang-tidy] Don't warn about call to unresolved operator*

Summary:
The misc-unconventional-assign-operator check had a false positive
warning when the 'operator*' in 'return *this' was unresolved.

Change matcher to allow calls to unresolved operator.

Fixes PR31531.

Reviewers: alexfh, aaron.ballman

Subscribers: JDevlieghere, cfe-commits

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

Modified:

clang-tools-extra/trunk/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp

clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp?rev=295176&r1=295175&r2=295176&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp 
Wed Feb 15 08:01:41 2017
@@ -58,7 +58,10 @@ void UnconventionalAssignOperatorCheck::
   this);
 
   const auto IsBadReturnStatement = 
returnStmt(unless(has(ignoringParenImpCasts(
-  unaryOperator(hasOperatorName("*"), hasUnaryOperand(cxxThisExpr()));
+  anyOf(unaryOperator(hasOperatorName("*"), 
hasUnaryOperand(cxxThisExpr())),
+cxxOperatorCallExpr(argumentCountIs(1),
+callee(unresolvedLookupExpr()),
+hasArgument(0, cxxThisExpr(;
   const auto IsGoodAssign = cxxMethodDecl(IsAssign, HasGoodReturnType);
 
   Finder->addMatcher(returnStmt(IsBadReturnStatement, 
forFunction(IsGoodAssign))

Modified: 
clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp?rev=295176&r1=295175&r2=295176&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp 
Wed Feb 15 08:01:41 2017
@@ -87,3 +87,25 @@ public:
 return n;
   }
 };
+
+namespace pr31531 {
+enum E { e };
+// This declaration makes the 'return *this' below have an unresolved operator
+// in the class template, but not in an instantiation.
+E operator*(E, E);
+
+template 
+struct UnresolvedOperator {
+  UnresolvedOperator &operator=(const UnresolvedOperator &) { return *this; }
+};
+
+UnresolvedOperator UnresolvedOperatorInt;
+
+template 
+struct Template {
+  Template &operator=(const Template &) { return this; }
+  // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: operator=() should always 
return '*this'
+};
+
+Template TemplateInt;
+}


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


[PATCH] D29393: [clang-tidy] Don't warn about call to unresolved operator*

2017-02-15 Thread Malcolm Parsons via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
malcolm.parsons marked 4 inline comments as done.
Closed by commit rL295176: [clang-tidy] Don't warn about call to unresolved 
operator* (authored by malcolm.parsons).

Changed prior to commit:
  https://reviews.llvm.org/D29393?vs=86623&id=88518#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29393

Files:
  clang-tools-extra/trunk/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
  
clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp


Index: 
clang-tools-extra/trunk/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
===
--- 
clang-tools-extra/trunk/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
+++ 
clang-tools-extra/trunk/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
@@ -58,7 +58,10 @@
   this);
 
   const auto IsBadReturnStatement = 
returnStmt(unless(has(ignoringParenImpCasts(
-  unaryOperator(hasOperatorName("*"), hasUnaryOperand(cxxThisExpr()));
+  anyOf(unaryOperator(hasOperatorName("*"), 
hasUnaryOperand(cxxThisExpr())),
+cxxOperatorCallExpr(argumentCountIs(1),
+callee(unresolvedLookupExpr()),
+hasArgument(0, cxxThisExpr(;
   const auto IsGoodAssign = cxxMethodDecl(IsAssign, HasGoodReturnType);
 
   Finder->addMatcher(returnStmt(IsBadReturnStatement, 
forFunction(IsGoodAssign))
Index: 
clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp
===
--- 
clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp
+++ 
clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp
@@ -87,3 +87,25 @@
 return n;
   }
 };
+
+namespace pr31531 {
+enum E { e };
+// This declaration makes the 'return *this' below have an unresolved operator
+// in the class template, but not in an instantiation.
+E operator*(E, E);
+
+template 
+struct UnresolvedOperator {
+  UnresolvedOperator &operator=(const UnresolvedOperator &) { return *this; }
+};
+
+UnresolvedOperator UnresolvedOperatorInt;
+
+template 
+struct Template {
+  Template &operator=(const Template &) { return this; }
+  // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: operator=() should always 
return '*this'
+};
+
+Template TemplateInt;
+}


Index: clang-tools-extra/trunk/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
@@ -58,7 +58,10 @@
   this);
 
   const auto IsBadReturnStatement = returnStmt(unless(has(ignoringParenImpCasts(
-  unaryOperator(hasOperatorName("*"), hasUnaryOperand(cxxThisExpr()));
+  anyOf(unaryOperator(hasOperatorName("*"), hasUnaryOperand(cxxThisExpr())),
+cxxOperatorCallExpr(argumentCountIs(1),
+callee(unresolvedLookupExpr()),
+hasArgument(0, cxxThisExpr(;
   const auto IsGoodAssign = cxxMethodDecl(IsAssign, HasGoodReturnType);
 
   Finder->addMatcher(returnStmt(IsBadReturnStatement, forFunction(IsGoodAssign))
Index: clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp
@@ -87,3 +87,25 @@
 return n;
   }
 };
+
+namespace pr31531 {
+enum E { e };
+// This declaration makes the 'return *this' below have an unresolved operator
+// in the class template, but not in an instantiation.
+E operator*(E, E);
+
+template 
+struct UnresolvedOperator {
+  UnresolvedOperator &operator=(const UnresolvedOperator &) { return *this; }
+};
+
+UnresolvedOperator UnresolvedOperatorInt;
+
+template 
+struct Template {
+  Template &operator=(const Template &) { return this; }
+  // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: operator=() should always return '*this'
+};
+
+Template TemplateInt;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28768: [clang-tidy] Add check 'modernize-return-braced-init-list'

2017-02-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

There's one small wording nit with the diagnostic, but once that's resolved, 
LGTM as well.




Comment at: clang-tidy/modernize/ReturnBracedInitListCheck.cpp:65
+
+  auto Diag = diag(Loc, "to avoid repeating the return type from the "
+"declaration; use a braced initializer list instead");

This diagnostic reads strangely. I think you should drop the "to" at the start 
of the sentence.


Repository:
  rL LLVM

https://reviews.llvm.org/D28768



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


[PATCH] D29757: [libcxx] Threading support: Externalize hardware_concurrency()

2017-02-15 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

Ping?


https://reviews.llvm.org/D29757



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


[PATCH] D29967: Get class property selectors from property decl if it exists

2017-02-15 Thread David Herzka via Phabricator via cfe-commits
herzka updated this revision to Diff 88519.
herzka edited the summary of this revision.
herzka added a comment.

Added full context. Sorry about that! This is my first contribution, and I 
don't know how I completely missed that line while going through the steps.


https://reviews.llvm.org/D29967

Files:
  lib/Sema/SemaExprObjC.cpp


Index: lib/Sema/SemaExprObjC.cpp
===
--- lib/Sema/SemaExprObjC.cpp
+++ lib/Sema/SemaExprObjC.cpp
@@ -1984,13 +1984,26 @@
 }
   }
 
+  Selector GetterSel;
+  Selector SetterSel;
+  if (ObjCPropertyDecl *PD = IFace->FindPropertyDeclaration(
+  &propertyName, ObjCPropertyQueryKind::OBJC_PR_query_class)) {
+GetterSel = PD->getGetterName();
+SetterSel = PD->getSetterName();
+  } else {
+GetterSel = PP.getSelectorTable().getNullarySelector(&propertyName);
+SetterSel =
+  SelectorTable::constructSetterSelector(PP.getIdentifierTable(),
+ PP.getSelectorTable(),
+ &propertyName);
+  }
+
   // Search for a declared property first.
-  Selector Sel = PP.getSelectorTable().getNullarySelector(&propertyName);
-  ObjCMethodDecl *Getter = IFace->lookupClassMethod(Sel);
+  ObjCMethodDecl *Getter = IFace->lookupClassMethod(GetterSel);
 
   // If this reference is in an @implementation, check for 'private' methods.
   if (!Getter)
-Getter = IFace->lookupPrivateClassMethod(Sel);
+Getter = IFace->lookupPrivateClassMethod(GetterSel);
 
   if (Getter) {
 // FIXME: refactor/share with ActOnMemberReference().
@@ -2000,11 +2013,6 @@
   }
 
   // Look for the matching setter, in case it is needed.
-  Selector SetterSel =
-SelectorTable::constructSetterSelector(PP.getIdentifierTable(),
-PP.getSelectorTable(),
-   &propertyName);
-
   ObjCMethodDecl *Setter = IFace->lookupClassMethod(SetterSel);
   if (!Setter) {
 // If this reference is in an @implementation, also check for 'private'


Index: lib/Sema/SemaExprObjC.cpp
===
--- lib/Sema/SemaExprObjC.cpp
+++ lib/Sema/SemaExprObjC.cpp
@@ -1984,13 +1984,26 @@
 }
   }
 
+  Selector GetterSel;
+  Selector SetterSel;
+  if (ObjCPropertyDecl *PD = IFace->FindPropertyDeclaration(
+  &propertyName, ObjCPropertyQueryKind::OBJC_PR_query_class)) {
+GetterSel = PD->getGetterName();
+SetterSel = PD->getSetterName();
+  } else {
+GetterSel = PP.getSelectorTable().getNullarySelector(&propertyName);
+SetterSel =
+  SelectorTable::constructSetterSelector(PP.getIdentifierTable(),
+ PP.getSelectorTable(),
+ &propertyName);
+  }
+
   // Search for a declared property first.
-  Selector Sel = PP.getSelectorTable().getNullarySelector(&propertyName);
-  ObjCMethodDecl *Getter = IFace->lookupClassMethod(Sel);
+  ObjCMethodDecl *Getter = IFace->lookupClassMethod(GetterSel);
 
   // If this reference is in an @implementation, check for 'private' methods.
   if (!Getter)
-Getter = IFace->lookupPrivateClassMethod(Sel);
+Getter = IFace->lookupPrivateClassMethod(GetterSel);
 
   if (Getter) {
 // FIXME: refactor/share with ActOnMemberReference().
@@ -2000,11 +2013,6 @@
   }
 
   // Look for the matching setter, in case it is needed.
-  Selector SetterSel =
-SelectorTable::constructSetterSelector(PP.getIdentifierTable(),
-PP.getSelectorTable(),
-   &propertyName);
-
   ObjCMethodDecl *Setter = IFace->lookupClassMethod(SetterSel);
   if (!Setter) {
 // If this reference is in an @implementation, also check for 'private'
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29957: [clang-tidy] Ignore instantiated functions and static data members of classes in misc-definitions-in-headers.

2017-02-15 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL295178: [clang-tidy] Ignore instantiated functions and 
static data members of classes… (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D29957?vs=88413&id=88520#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29957

Files:
  clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp


Index: clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -104,8 +104,8 @@
 // Function templates are allowed.
 if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate)
   return;
-// Function template full specialization is prohibited in header file.
-if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation)
+// Ignore instantiated functions.
+if (FD->isTemplateInstantiation())
   return;
 // Member function of a class template and member function of a nested 
class
 // in a class template are allowed.
@@ -133,7 +133,8 @@
 // Static data members of a class template are allowed.
 if (VD->getDeclContext()->isDependentContext() && VD->isStaticDataMember())
   return;
-if (VD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation)
+// Ignore instantiated static data members of classes.
+if (isTemplateInstantiation(VD->getTemplateSpecializationKind()))
   return;
 // Ignore variable definition within function scope.
 if (VD->hasLocalStorage() || VD->isStaticLocal())
Index: clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp
===
--- clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp
+++ clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp
@@ -71,6 +71,12 @@
 template 
 int CB::a = 2; // OK: static data member definition of a class template.
 
+template class CB; // OK: explicitly instantiated static data member of a 
class template.
+inline int callCB() {
+  CB cb; // OK: implicitly instantiated static data member of a class 
template.
+  return cb.a;
+}
+
 template 
 T tf() { // OK: template function definition.
   T a;
@@ -107,6 +113,12 @@
 
 int f8() = delete; // OK: the function being marked delete is not callable.
 
+template 
+int f9(T t) { return 1; }
+
+inline void callF9() { f9(1); } // OK: implicitly instantiated function.
+template int f9(double); // OK: explicitly instantiated function.
+
 int a = 1;
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: variable 'a' defined in a header 
file; variable definitions in header files can lead to ODR violations 
[misc-definitions-in-headers]
 CA a1;


Index: clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -104,8 +104,8 @@
 // Function templates are allowed.
 if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate)
   return;
-// Function template full specialization is prohibited in header file.
-if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation)
+// Ignore instantiated functions.
+if (FD->isTemplateInstantiation())
   return;
 // Member function of a class template and member function of a nested class
 // in a class template are allowed.
@@ -133,7 +133,8 @@
 // Static data members of a class template are allowed.
 if (VD->getDeclContext()->isDependentContext() && VD->isStaticDataMember())
   return;
-if (VD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation)
+// Ignore instantiated static data members of classes.
+if (isTemplateInstantiation(VD->getTemplateSpecializationKind()))
   return;
 // Ignore variable definition within function scope.
 if (VD->hasLocalStorage() || VD->isStaticLocal())
Index: clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp
===
--- clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp
+++ clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp
@@ -71,6 +71,12 @@
 template 
 int CB::a = 2; // OK: static data member definition of a class template.
 
+template class CB; // OK: explicitly instantiated static data member of a class template.
+inline int callCB() {
+  CB cb; // OK: implicitly instantiated static data member of a class template.
+  return cb.a;
+}
+
 template 
 T tf() { // OK: template function definition.
   T a;
@@ -

[clang-tools-extra] r295178 - [clang-tidy] Ignore instantiated functions and static data members of classes in misc-definitions-in-headers.

2017-02-15 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Feb 15 08:10:50 2017
New Revision: 295178

URL: http://llvm.org/viewvc/llvm-project?rev=295178&view=rev
Log:
[clang-tidy] Ignore instantiated functions and static data members of classes 
in misc-definitions-in-headers.

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: JDevlieghere, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp?rev=295178&r1=295177&r2=295178&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp Wed 
Feb 15 08:10:50 2017
@@ -104,8 +104,8 @@ void DefinitionsInHeadersCheck::check(co
 // Function templates are allowed.
 if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate)
   return;
-// Function template full specialization is prohibited in header file.
-if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation)
+// Ignore instantiated functions.
+if (FD->isTemplateInstantiation())
   return;
 // Member function of a class template and member function of a nested 
class
 // in a class template are allowed.
@@ -133,7 +133,8 @@ void DefinitionsInHeadersCheck::check(co
 // Static data members of a class template are allowed.
 if (VD->getDeclContext()->isDependentContext() && VD->isStaticDataMember())
   return;
-if (VD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation)
+// Ignore instantiated static data members of classes.
+if (isTemplateInstantiation(VD->getTemplateSpecializationKind()))
   return;
 // Ignore variable definition within function scope.
 if (VD->hasLocalStorage() || VD->isStaticLocal())

Modified: 
clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp?rev=295178&r1=295177&r2=295178&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp Wed 
Feb 15 08:10:50 2017
@@ -71,6 +71,12 @@ void CB::CCB::f3() {
 template 
 int CB::a = 2; // OK: static data member definition of a class template.
 
+template class CB; // OK: explicitly instantiated static data member of a 
class template.
+inline int callCB() {
+  CB cb; // OK: implicitly instantiated static data member of a class 
template.
+  return cb.a;
+}
+
 template 
 T tf() { // OK: template function definition.
   T a;
@@ -107,6 +113,12 @@ namespace {
 
 int f8() = delete; // OK: the function being marked delete is not callable.
 
+template 
+int f9(T t) { return 1; }
+
+inline void callF9() { f9(1); } // OK: implicitly instantiated function.
+template int f9(double); // OK: explicitly instantiated function.
+
 int a = 1;
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: variable 'a' defined in a header 
file; variable definitions in header files can lead to ODR violations 
[misc-definitions-in-headers]
 CA a1;


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


[PATCH] D29032: [mips] Define macros related to -mabicalls in the preprocessor

2017-02-15 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

No need to preserve the BSD behavior for NetBSD.


https://reviews.llvm.org/D29032



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


[PATCH] D29818: [libcxx] Threading support: Attempt to externalize system_clock::now() and steady_clock::now() implementations

2017-02-15 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

Ping?


https://reviews.llvm.org/D29818



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


[PATCH] D29886: [clangd] Wire up ASTUnit and publish diagnostics with it.

2017-02-15 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer updated this revision to Diff 88522.
bkramer added a comment.

- Do not lock while running DocumentStore callbacks
- Replace fake queue with a real queue (but it still has at most one element.


https://reviews.llvm.org/D29886

Files:
  clangd/ASTManager.cpp
  clangd/ASTManager.h
  clangd/CMakeLists.txt
  clangd/ClangDMain.cpp
  clangd/DocumentStore.h
  test/clangd/diagnostics.test

Index: test/clangd/diagnostics.test
===
--- /dev/null
+++ test/clangd/diagnostics.test
@@ -0,0 +1,17 @@
+# RUN: clangd < %s | FileCheck %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+#
+Content-Length: 152
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///foo.c","languageId":"c","version":1,"text":"void main() {}"}}}
+#
+# CHECK: {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///foo.c","diagnostics":[{"range":{"start": {"line": 0, "character": 1}, "end": {"line": 0, "character": 1}},"severity":2,"message":"return type of 'main' is not 'int'"},{"range":{"start": {"line": 0, "character": 1}, "end": {"line": 0, "character": 1}},"severity":3,"message":"change return type to 'int'"}]}}
+#
+#
+Content-Length: 44
+
+{"jsonrpc":"2.0","id":5,"method":"shutdown"}
Index: clangd/DocumentStore.h
===
--- clangd/DocumentStore.h
+++ clangd/DocumentStore.h
@@ -12,27 +12,65 @@
 
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/StringMap.h"
+#include 
 #include 
 
 namespace clang {
 namespace clangd {
+class DocumentStore;
+
+struct DocumentStoreListener {
+  virtual ~DocumentStoreListener() = default;
+  virtual void onDocumentAdd(StringRef Uri) {}
+  virtual void onDocumentRemove(StringRef Uri) {}
+};
 
 /// A container for files opened in a workspace, addressed by URI. The contents
 /// are owned by the DocumentStore.
 class DocumentStore {
 public:
   /// Add a document to the store. Overwrites existing contents.
-  void addDocument(StringRef Uri, StringRef Text) { Docs[Uri] = Text; }
+  void addDocument(StringRef Uri, StringRef Text) {
+{
+  std::lock_guard Guard(DocsMutex);
+  Docs[Uri] = Text;
+}
+for (const auto &Listener : Listeners)
+  Listener->onDocumentAdd(Uri);
+  }
   /// Delete a document from the store.
-  void removeDocument(StringRef Uri) { Docs.erase(Uri); }
+  void removeDocument(StringRef Uri) {
+{
+  std::lock_guard Guard(DocsMutex);
+  Docs.erase(Uri);
+}
+for (const auto &Listener : Listeners)
+  Listener->onDocumentRemove(Uri);
+  }
   /// Retrieve a document from the store. Empty string if it's unknown.
-  StringRef getDocument(StringRef Uri) const {
-auto I = Docs.find(Uri);
-return I == Docs.end() ? StringRef("") : StringRef(I->second);
+  std::string getDocument(StringRef Uri) const {
+// FIXME: This could be a reader lock.
+std::lock_guard Guard(DocsMutex);
+return Docs.lookup(Uri);
+  }
+
+  /// Add a listener. Does not take ownership.
+  void addListener(DocumentStoreListener *DSL) { Listeners.push_back(DSL); }
+
+  /// Get name and constents of all documents in this store.
+  std::vector> getAllDocuments() const {
+std::vector> AllDocs;
+std::lock_guard Guard(DocsMutex);
+for (const auto &P : Docs)
+  AllDocs.emplace_back(P.first(), P.second);
+return AllDocs;
   }
 
 private:
   llvm::StringMap Docs;
+  std::vector Listeners;
+
+  mutable std::mutex DocsMutex;
 };
 
 } // namespace clangd
Index: clangd/ClangDMain.cpp
===
--- clangd/ClangDMain.cpp
+++ clangd/ClangDMain.cpp
@@ -7,6 +7,7 @@
 //
 //===--===//
 
+#include "ASTManager.h"
 #include "DocumentStore.h"
 #include "JSONRPCDispatcher.h"
 #include "ProtocolHandlers.h"
@@ -27,6 +28,8 @@
   // Set up a document store and intialize all the method handlers for JSONRPC
   // dispatching.
   DocumentStore Store;
+  ASTManager AST(Out, Store);
+  Store.addListener(&AST);
   JSONRPCDispatcher Dispatcher(llvm::make_unique(Out));
   Dispatcher.registerHandler("initialize",
  llvm::make_unique(Out));
Index: clangd/CMakeLists.txt
===
--- clangd/CMakeLists.txt
+++ clangd/CMakeLists.txt
@@ -1,4 +1,5 @@
 add_clang_executable(clangd
+  ASTManager.cpp
   ClangDMain.cpp
   JSONRPCDispatcher.cpp
   Protocol.cpp
@@ -8,5 +9,7 @@
 target_link_libraries(clangd
   clangBasic
   clangFormat
+  clangFrontend
+  clangTooling
   LLVMSupport
   )
Index: clangd/ASTManager.h
===
--- /dev/null
+++ clangd/ASTManager.h
@@ -0,0 +1,78 @@
+//=

[PATCH] D29886: [clangd] Wire up ASTUnit and publish diagnostics with it.

2017-02-15 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: clangd/ASTManager.h:67
+  /// Setting Done to true will make the worker thread terminate.
+  std::atomic Done;
+};

bkramer wrote:
> klimek wrote:
> > arphaman wrote:
> > > It looks like `Done` is always accessed in a scope where `RequestLock` is 
> > > locked, so `atomic` doesn't seem needed here.
> > Yea, after only having read this header, it looks like we might want to 
> > pull out a Request as an abstraction.
> Wrapped all the guarded variables in a struct.
For me that actually makes it worse (sorry): I now read "Request.Done" and 
think the request is done :)


https://reviews.llvm.org/D29886



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


[PATCH] D29886: [clangd] Wire up ASTUnit and publish diagnostics with it.

2017-02-15 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer updated this revision to Diff 88523.
bkramer added a comment.

- Inline the request struct again.


https://reviews.llvm.org/D29886

Files:
  clangd/ASTManager.cpp
  clangd/ASTManager.h
  clangd/CMakeLists.txt
  clangd/ClangDMain.cpp
  clangd/DocumentStore.h
  test/clangd/diagnostics.test

Index: test/clangd/diagnostics.test
===
--- /dev/null
+++ test/clangd/diagnostics.test
@@ -0,0 +1,17 @@
+# RUN: clangd < %s | FileCheck %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+#
+Content-Length: 152
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///foo.c","languageId":"c","version":1,"text":"void main() {}"}}}
+#
+# CHECK: {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///foo.c","diagnostics":[{"range":{"start": {"line": 0, "character": 1}, "end": {"line": 0, "character": 1}},"severity":2,"message":"return type of 'main' is not 'int'"},{"range":{"start": {"line": 0, "character": 1}, "end": {"line": 0, "character": 1}},"severity":3,"message":"change return type to 'int'"}]}}
+#
+#
+Content-Length: 44
+
+{"jsonrpc":"2.0","id":5,"method":"shutdown"}
Index: clangd/DocumentStore.h
===
--- clangd/DocumentStore.h
+++ clangd/DocumentStore.h
@@ -12,27 +12,65 @@
 
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/StringMap.h"
+#include 
 #include 
 
 namespace clang {
 namespace clangd {
+class DocumentStore;
+
+struct DocumentStoreListener {
+  virtual ~DocumentStoreListener() = default;
+  virtual void onDocumentAdd(StringRef Uri) {}
+  virtual void onDocumentRemove(StringRef Uri) {}
+};
 
 /// A container for files opened in a workspace, addressed by URI. The contents
 /// are owned by the DocumentStore.
 class DocumentStore {
 public:
   /// Add a document to the store. Overwrites existing contents.
-  void addDocument(StringRef Uri, StringRef Text) { Docs[Uri] = Text; }
+  void addDocument(StringRef Uri, StringRef Text) {
+{
+  std::lock_guard Guard(DocsMutex);
+  Docs[Uri] = Text;
+}
+for (const auto &Listener : Listeners)
+  Listener->onDocumentAdd(Uri);
+  }
   /// Delete a document from the store.
-  void removeDocument(StringRef Uri) { Docs.erase(Uri); }
+  void removeDocument(StringRef Uri) {
+{
+  std::lock_guard Guard(DocsMutex);
+  Docs.erase(Uri);
+}
+for (const auto &Listener : Listeners)
+  Listener->onDocumentRemove(Uri);
+  }
   /// Retrieve a document from the store. Empty string if it's unknown.
-  StringRef getDocument(StringRef Uri) const {
-auto I = Docs.find(Uri);
-return I == Docs.end() ? StringRef("") : StringRef(I->second);
+  std::string getDocument(StringRef Uri) const {
+// FIXME: This could be a reader lock.
+std::lock_guard Guard(DocsMutex);
+return Docs.lookup(Uri);
+  }
+
+  /// Add a listener. Does not take ownership.
+  void addListener(DocumentStoreListener *DSL) { Listeners.push_back(DSL); }
+
+  /// Get name and constents of all documents in this store.
+  std::vector> getAllDocuments() const {
+std::vector> AllDocs;
+std::lock_guard Guard(DocsMutex);
+for (const auto &P : Docs)
+  AllDocs.emplace_back(P.first(), P.second);
+return AllDocs;
   }
 
 private:
   llvm::StringMap Docs;
+  std::vector Listeners;
+
+  mutable std::mutex DocsMutex;
 };
 
 } // namespace clangd
Index: clangd/ClangDMain.cpp
===
--- clangd/ClangDMain.cpp
+++ clangd/ClangDMain.cpp
@@ -7,6 +7,7 @@
 //
 //===--===//
 
+#include "ASTManager.h"
 #include "DocumentStore.h"
 #include "JSONRPCDispatcher.h"
 #include "ProtocolHandlers.h"
@@ -27,6 +28,8 @@
   // Set up a document store and intialize all the method handlers for JSONRPC
   // dispatching.
   DocumentStore Store;
+  ASTManager AST(Out, Store);
+  Store.addListener(&AST);
   JSONRPCDispatcher Dispatcher(llvm::make_unique(Out));
   Dispatcher.registerHandler("initialize",
  llvm::make_unique(Out));
Index: clangd/CMakeLists.txt
===
--- clangd/CMakeLists.txt
+++ clangd/CMakeLists.txt
@@ -1,4 +1,5 @@
 add_clang_executable(clangd
+  ASTManager.cpp
   ClangDMain.cpp
   JSONRPCDispatcher.cpp
   Protocol.cpp
@@ -8,5 +9,7 @@
 target_link_libraries(clangd
   clangBasic
   clangFormat
+  clangFrontend
+  clangTooling
   LLVMSupport
   )
Index: clangd/ASTManager.h
===
--- /dev/null
+++ clangd/ASTManager.h
@@ -0,0 +1,76 @@
+//===--- ASTManager.h - Clang AST manager ---*- C++ -*-===//
+//
+//  

[PATCH] D29886: [clangd] Wire up ASTUnit and publish diagnostics with it.

2017-02-15 Thread Manuel Klimek via Phabricator via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

lg




Comment at: clangd/ASTManager.cpp:138-139
+  // Currently we discard all pending requests and just enqueue the latest one.
+  while (!RequestQueue.empty())
+RequestQueue.pop();
+  RequestQueue.push(Uri);

deque has resize *ducks and runs*


https://reviews.llvm.org/D29886



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


[PATCH] D28058: [OpenCL] Correct ndrange_t implementation

2017-02-15 Thread Dmitry Borisenkov via Phabricator via cfe-commits
dmitry updated this revision to Diff 88529.
dmitry added a comment.

Byval attribute was added for ndrange in enqueue kernel call.


https://reviews.llvm.org/D28058

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/BuiltinTypes.def
  include/clang/AST/Type.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTContext.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/NSAPI.cpp
  lib/AST/Type.cpp
  lib/AST/TypeLoc.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGOpenCLRuntime.cpp
  lib/CodeGen/CodeGenTypes.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/Headers/opencl-c.h
  lib/Index/USRGeneration.cpp
  lib/Sema/Sema.cpp
  lib/Sema/SemaChecking.cpp
  lib/Serialization/ASTCommon.cpp
  lib/Serialization/ASTReader.cpp
  test/CodeGenOpenCL/cl20-device-side-enqueue.cl
  test/Headers/opencl-c-header.cl
  test/PCH/ocl_types.h
  test/SemaOpenCL/cl20-device-side-enqueue.cl
  tools/libclang/CIndex.cpp

Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -1492,7 +1492,6 @@
   case BuiltinType::OCLEvent:
   case BuiltinType::OCLClkEvent:
   case BuiltinType::OCLQueue:
-  case BuiltinType::OCLNDRange:
   case BuiltinType::OCLReserveID:
 #define BUILTIN_TYPE(Id, SingletonId)
 #define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
Index: test/SemaOpenCL/cl20-device-side-enqueue.cl
===
--- test/SemaOpenCL/cl20-device-side-enqueue.cl
+++ test/SemaOpenCL/cl20-device-side-enqueue.cl
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-only -Wconversion -DWCONV
 
+typedef struct {int a;} ndrange_t;
 // Diagnostic tests for different overloads of enqueue_kernel from Table 6.13.17.1 of OpenCL 2.0 Spec.
 kernel void enqueue_kernel_tests() {
   queue_t default_queue;
Index: test/PCH/ocl_types.h
===
--- test/PCH/ocl_types.h
+++ test/PCH/ocl_types.h
@@ -32,9 +32,6 @@
 // queue_t
 typedef queue_t q_t;
 
-// ndrange_t
-typedef ndrange_t range_t;
-
 // reserve_id_t
 typedef reserve_id_t reserveid_t;
 
Index: test/Headers/opencl-c-header.cl
===
--- test/Headers/opencl-c-header.cl
+++ test/Headers/opencl-c-header.cl
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -cl-std=CL1.1| FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s| FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -cl-std=CL1.1| FileCheck %s
 
 // Test including the default header as a module.
 // The module should be compiled only once and loaded from cache afterwards.
@@ -25,38 +25,38 @@
 
 // ===
 // Compile for OpenCL 2.0 for the first time. The module should change.
-// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm -o - -cl-std=CL2.0 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -fdisable-module-hash -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK20 --check-prefix=CHECK-MOD %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -O0 -emit-llvm -o - -cl-std=CL2.0 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -fdisable-module-hash -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK20 --check-prefix=CHECK-MOD %s
 // RUN: not diff %t/1_0.pcm %t/opencl_c.pcm
 // RUN: chmod u-w %t/opencl_c.pcm
 
 // ===
 // Compile for OpenCL 2.0 for the second time. The module should not change.
-// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm -o - -cl-std=CL2.0 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -fdisable-module-hash -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK20 --check-prefix=CHECK-MOD %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -O0 -emit-llvm -o - -cl-std=CL2.0 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -fdisable-module-hash -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK20 --check-prefix=CHECK-MOD %s
 
 // Check cached module works for different OpenCL versions.
 // RUN: rm -rf %t
 // RUN: mkdir -p %t
 // RUN: %clang_cc1 -triple spir64-unknown-unknown -emit-llvm -o - -cl-std=CL1.2 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK --check-pr

[PATCH] D29884: [analyzer] Proper caching in CallDescription objects.

2017-02-15 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Yep, seems that somebody has missed these issues :)

I guess there's no way to test the operator case, because nobody made a 
CallDescription with an empty name for us (maybe we should even assert that).


https://reviews.llvm.org/D29884



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


[clang-tools-extra] r295180 - [clangd] Wire up ASTUnit and publish diagnostics with it.

2017-02-15 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Wed Feb 15 09:04:20 2017
New Revision: 295180

URL: http://llvm.org/viewvc/llvm-project?rev=295180&view=rev
Log:
[clangd] Wire up ASTUnit and publish diagnostics with it.

Summary:
This requires an accessible compilation database. The parsing is done
asynchronously on a separate thread.

Reviewers: klimek, krasimir

Subscribers: cfe-commits, mgorny

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

Added:
clang-tools-extra/trunk/clangd/ASTManager.cpp
clang-tools-extra/trunk/clangd/ASTManager.h
clang-tools-extra/trunk/test/clangd/diagnostics.test
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/ClangDMain.cpp
clang-tools-extra/trunk/clangd/DocumentStore.h

Added: clang-tools-extra/trunk/clangd/ASTManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ASTManager.cpp?rev=295180&view=auto
==
--- clang-tools-extra/trunk/clangd/ASTManager.cpp (added)
+++ clang-tools-extra/trunk/clangd/ASTManager.cpp Wed Feb 15 09:04:20 2017
@@ -0,0 +1,201 @@
+//===--- ASTManager.cpp - Clang AST manager 
---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ASTManager.h"
+#include "JSONRPCDispatcher.h"
+#include "Protocol.h"
+#include "clang/Frontend/ASTUnit.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/Support/Format.h"
+#include "llvm/Support/Path.h"
+#include 
+#include 
+using namespace clang;
+using namespace clangd;
+
+/// Retrieve a copy of the contents of every file in the store, for feeding 
into
+/// ASTUnit.
+static std::vector
+getRemappedFiles(const DocumentStore &Docs) {
+  // FIXME: Use VFS instead. This would allow us to get rid of the chdir below.
+  std::vector RemappedFiles;
+  for (const auto &P : Docs.getAllDocuments()) {
+StringRef FileName = P.first;
+FileName.consume_front("file://");
+RemappedFiles.push_back(ASTUnit::RemappedFile(
+FileName,
+llvm::MemoryBuffer::getMemBufferCopy(P.second, FileName).release()));
+  }
+  return RemappedFiles;
+}
+
+/// Convert from clang diagnostic level to LSP severity.
+static int getSeverity(DiagnosticsEngine::Level L) {
+  switch (L) {
+  case DiagnosticsEngine::Remark:
+return 4;
+  case DiagnosticsEngine::Note:
+return 3;
+  case DiagnosticsEngine::Warning:
+return 2;
+  case DiagnosticsEngine::Fatal:
+  case DiagnosticsEngine::Error:
+return 1;
+  case DiagnosticsEngine::Ignored:
+return 0;
+  }
+}
+
+ASTManager::ASTManager(JSONOutput &Output, DocumentStore &Store)
+: Output(Output), Store(Store),
+  PCHs(std::make_shared()),
+  ClangWorker([this]() { runWorker(); }) {}
+
+void ASTManager::runWorker() {
+  while (true) {
+std::string File;
+
+{
+  std::unique_lock Lock(RequestLock);
+  // Check if there's another request pending. We keep parsing until
+  // our one-element queue is empty.
+  ClangRequestCV.wait(Lock, [this] {
+return !RequestQueue.empty() || Done;
+  });
+
+  if (RequestQueue.empty() && Done)
+return;
+
+  File = std::move(RequestQueue.back());
+  RequestQueue.pop_back();
+} // unlock.
+
+auto &Unit = ASTs[File]; // Only one thread can access this at a time.
+
+if (!Unit) {
+  Unit = createASTUnitForFile(File, this->Store);
+} else {
+  // Do a reparse if this wasn't the first parse.
+  // FIXME: This might have the wrong working directory if it changed in 
the
+  // meantime.
+  Unit->Reparse(PCHs, getRemappedFiles(this->Store));
+}
+
+if (!Unit)
+  continue;
+
+// Send the diagnotics to the editor.
+// FIXME: If the diagnostic comes from a different file, do we want to
+// show them all? Right now we drop everything not coming from the
+// main file.
+// FIXME: Send FixIts to the editor.
+std::string Diagnostics;
+for (ASTUnit::stored_diag_iterator D = Unit->stored_diag_begin(),
+   DEnd = Unit->stored_diag_end();
+ D != DEnd; ++D) {
+  if (!D->getLocation().isValid() ||
+  !D->getLocation().getManager().isInMainFile(D->getLocation()))
+continue;
+  Position P;
+  P.line = D->getLocation().getSpellingLineNumber() - 1;
+  P.character = D->getLocation().getSpellingColumnNumber();
+  Range R = {P, P};
+  Diagnostics +=
+  R"({"range":)" + Range::unparse(R) +
+  R"(,"severity":)" + std::to_string(getSeverity(D->getLevel())) +
+  R"(,"message":")" + llvm::yaml::escape(D->getMessage()) +
+  R"("},)";
+}
+
+if (!Diagnostics.empty())

[PATCH] D29886: [clangd] Wire up ASTUnit and publish diagnostics with it.

2017-02-15 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL295180: [clangd] Wire up ASTUnit and publish diagnostics 
with it. (authored by d0k).

Changed prior to commit:
  https://reviews.llvm.org/D29886?vs=88523&id=88532#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29886

Files:
  clang-tools-extra/trunk/clangd/ASTManager.cpp
  clang-tools-extra/trunk/clangd/ASTManager.h
  clang-tools-extra/trunk/clangd/CMakeLists.txt
  clang-tools-extra/trunk/clangd/ClangDMain.cpp
  clang-tools-extra/trunk/clangd/DocumentStore.h
  clang-tools-extra/trunk/test/clangd/diagnostics.test

Index: clang-tools-extra/trunk/test/clangd/diagnostics.test
===
--- clang-tools-extra/trunk/test/clangd/diagnostics.test
+++ clang-tools-extra/trunk/test/clangd/diagnostics.test
@@ -0,0 +1,17 @@
+# RUN: clangd < %s | FileCheck %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+#
+Content-Length: 152
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///foo.c","languageId":"c","version":1,"text":"void main() {}"}}}
+#
+# CHECK: {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///foo.c","diagnostics":[{"range":{"start": {"line": 0, "character": 1}, "end": {"line": 0, "character": 1}},"severity":2,"message":"return type of 'main' is not 'int'"},{"range":{"start": {"line": 0, "character": 1}, "end": {"line": 0, "character": 1}},"severity":3,"message":"change return type to 'int'"}]}}
+#
+#
+Content-Length: 44
+
+{"jsonrpc":"2.0","id":5,"method":"shutdown"}
Index: clang-tools-extra/trunk/clangd/ClangDMain.cpp
===
--- clang-tools-extra/trunk/clangd/ClangDMain.cpp
+++ clang-tools-extra/trunk/clangd/ClangDMain.cpp
@@ -7,6 +7,7 @@
 //
 //===--===//
 
+#include "ASTManager.h"
 #include "DocumentStore.h"
 #include "JSONRPCDispatcher.h"
 #include "ProtocolHandlers.h"
@@ -27,6 +28,8 @@
   // Set up a document store and intialize all the method handlers for JSONRPC
   // dispatching.
   DocumentStore Store;
+  ASTManager AST(Out, Store);
+  Store.addListener(&AST);
   JSONRPCDispatcher Dispatcher(llvm::make_unique(Out));
   Dispatcher.registerHandler("initialize",
  llvm::make_unique(Out));
Index: clang-tools-extra/trunk/clangd/CMakeLists.txt
===
--- clang-tools-extra/trunk/clangd/CMakeLists.txt
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt
@@ -1,4 +1,5 @@
 add_clang_executable(clangd
+  ASTManager.cpp
   ClangDMain.cpp
   JSONRPCDispatcher.cpp
   Protocol.cpp
@@ -8,5 +9,7 @@
 target_link_libraries(clangd
   clangBasic
   clangFormat
+  clangFrontend
+  clangTooling
   LLVMSupport
   )
Index: clang-tools-extra/trunk/clangd/ASTManager.h
===
--- clang-tools-extra/trunk/clangd/ASTManager.h
+++ clang-tools-extra/trunk/clangd/ASTManager.h
@@ -0,0 +1,76 @@
+//===--- ASTManager.h - Clang AST manager ---*- 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_CLANGD_ASTMANAGER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_ASTMANAGER_H
+
+#include "DocumentStore.h"
+#include "JSONRPCDispatcher.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include 
+#include 
+#include 
+
+namespace clang {
+class ASTUnit;
+class DiagnosticsEngine;
+class PCHContainerOperations;
+namespace tooling {
+class CompilationDatabase;
+} // namespace tooling
+
+namespace clangd {
+
+class ASTManager : public DocumentStoreListener {
+public:
+  ASTManager(JSONOutput &Output, DocumentStore &Store);
+  ~ASTManager() override;
+
+  void onDocumentAdd(StringRef Uri) override;
+  // FIXME: Implement onDocumentRemove
+  // FIXME: Implement codeComplete
+
+private:
+  JSONOutput &Output;
+  DocumentStore &Store;
+
+  /// Loads a compilation database for URI. May return nullptr if it fails. The
+  /// database is cached for subsequent accesses.
+  clang::tooling::CompilationDatabase *
+  getOrCreateCompilationDatabaseForFile(StringRef Uri);
+  // Craetes a new ASTUnit for the document at Uri.
+  // FIXME: This calls chdir internally, which is thread unsafe.
+  std::unique_ptr
+  createASTUnitForFile(StringRef Uri, const DocumentStore &Docs);
+
+  void runWorker();
+
+  /// Clang objects.
+  llvm::StringMap> ASTs;
+  llvm::StringMap>
+  CompilationDatabases;
+  std::shared_ptr PCHs;
+
+  /// We 

r295183 - Fix spelling mistake - paramater -> parameter. NFCI.

2017-02-15 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Wed Feb 15 09:12:06 2017
New Revision: 295183

URL: http://llvm.org/viewvc/llvm-project?rev=295183&view=rev
Log:
Fix spelling mistake - paramater -> parameter. NFCI.

Modified:
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=295183&r1=295182&r2=295183&view=diff
==
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Wed Feb 15 09:12:06 2017
@@ -1961,7 +1961,7 @@ void MicrosoftCXXNameMangler::mangleFunc
 // Happens for function pointer type arguments for example.
 for (unsigned I = 0, E = Proto->getNumParams(); I != E; ++I) {
   mangleArgumentType(Proto->getParamType(I), Range);
-  // Mangle each pass_object_size parameter as if it's a paramater of enum
+  // Mangle each pass_object_size parameter as if it's a parameter of enum
   // type passed directly after the parameter with the pass_object_size
   // attribute. The aforementioned enum's name is __pass_object_size, and 
we
   // pretend it resides in a top-level namespace called __clang.

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=295183&r1=295182&r2=295183&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Wed Feb 15 09:12:06 2017
@@ -101,7 +101,7 @@ CodeGenTypes::arrangeFreeFunctionType(Ca
  FTNP->getExtInfo(), {}, RequiredArgs(0));
 }
 
-/// Adds the formal paramaters in FPT to the given prefix. If any parameter in
+/// Adds the formal parameters in FPT to the given prefix. If any parameter in
 /// FPT has pass_object_size attrs, then we'll add parameters for those, too.
 static void appendParameterTypes(const CodeGenTypes &CGT,
  SmallVectorImpl &prefix,

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=295183&r1=295182&r2=295183&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Feb 15 09:12:06 2017
@@ -792,7 +792,7 @@ static void handleAllocSizeAttr(Sema &S,
 
   const Expr *SizeExpr = Attr.getArgAsExpr(0);
   int SizeArgNo;
-  // Paramater indices are 1-indexed, hence Index=1
+  // Parameter indices are 1-indexed, hence Index=1
   if (!checkPositiveIntArgument(S, Attr, SizeExpr, SizeArgNo, /*Index=*/1))
 return;
 
@@ -803,7 +803,7 @@ static void handleAllocSizeAttr(Sema &S,
   int NumberArgNo = 0;
   if (Attr.getNumArgs() == 2) {
 const Expr *NumberExpr = Attr.getArgAsExpr(1);
-// Paramater indices are 1-based, hence Index=2
+// Parameter indices are 1-based, hence Index=2
 if (!checkPositiveIntArgument(S, Attr, NumberExpr, NumberArgNo,
   /*Index=*/2))
   return;


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


[PATCH] D28058: [OpenCL] Correct ndrange_t implementation

2017-02-15 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks!


https://reviews.llvm.org/D28058



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


[PATCH] D28297: [StaticAnalyzer] Fix crash in CastToStructChecker

2017-02-15 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

I sometimes wish ASTContext methods just didn't crash :)
Oh well, let's just see if more problems show up.




Comment at: lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp:93
 
 // Warn when there is widening cast.
 unsigned ToWidth = Ctx.getTypeInfo(ToPointeeTy).Width;

I think we should move the check here then. That'd avoid double-checking if 
`ToPointeeTy` is a record type (we could `cast<>` directly on this branch).


Repository:
  rL LLVM

https://reviews.llvm.org/D28297



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


[clang-tools-extra] r295184 - [clangd] Add missing include.

2017-02-15 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Wed Feb 15 09:19:13 2017
New Revision: 295184

URL: http://llvm.org/viewvc/llvm-project?rev=295184&view=rev
Log:
[clangd] Add missing include.

Modified:
clang-tools-extra/trunk/clangd/DocumentStore.h

Modified: clang-tools-extra/trunk/clangd/DocumentStore.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/DocumentStore.h?rev=295184&r1=295183&r2=295184&view=diff
==
--- clang-tools-extra/trunk/clangd/DocumentStore.h (original)
+++ clang-tools-extra/trunk/clangd/DocumentStore.h Wed Feb 15 09:19:13 2017
@@ -14,6 +14,7 @@
 #include "llvm/ADT/StringMap.h"
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace clangd {


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


r295186 - [analyzer] Proper caching in CallDescription objects.

2017-02-15 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Wed Feb 15 09:35:56 2017
New Revision: 295186

URL: http://llvm.org/viewvc/llvm-project?rev=295186&view=rev
Log:
[analyzer] Proper caching in CallDescription objects.

During the review of D29567 it turned out the caching in CallDescription is not 
implemented properly. In case an identifier does not exist in a translation 
unit, repeated identifier lookups will be done which might have bad impact on 
the performance. This patch guarantees that the lookup is only executed once. 
Moreover this patch fixes a corner case when the identifier of CallDescription 
does not exist in the translation unit and the called function does not have an 
identifier (e.g.: overloaded operator in C++).

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


Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h?rev=295186&r1=295185&r2=295186&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h Wed 
Feb 15 09:35:56 2017
@@ -55,6 +55,7 @@ class CallEventManager;
 class CallDescription {
   friend CallEvent;
   mutable IdentifierInfo *II;
+  mutable bool IsLookupDone;
   StringRef FuncName;
   unsigned RequiredArgs;
 
@@ -68,7 +69,8 @@ public:
   /// call. Omit this parameter to match every occurance of call with a given
   /// name regardless the number of arguments.
   CallDescription(StringRef FuncName, unsigned RequiredArgs = NoArgRequirement)
-  : II(nullptr), FuncName(FuncName), RequiredArgs(RequiredArgs) {}
+  : II(nullptr), IsLookupDone(false), FuncName(FuncName),
+RequiredArgs(RequiredArgs) {}
 
   /// \brief Get the name of the function that this object matches.
   StringRef getFunctionName() const { return FuncName; }

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp?rev=295186&r1=295185&r2=295186&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp Wed Feb 15 09:35:56 2017
@@ -212,9 +212,12 @@ ProgramPoint CallEvent::getProgramPoint(
 
 bool CallEvent::isCalled(const CallDescription &CD) const {
   assert(getKind() != CE_ObjCMessage && "Obj-C methods are not supported");
-  if (!CD.II)
+  if (!CD.IsLookupDone) {
+CD.IsLookupDone = true;
 CD.II = 
&getState()->getStateManager().getContext().Idents.get(CD.FuncName);
-  if (getCalleeIdentifier() != CD.II)
+  }
+  const IdentifierInfo *II = getCalleeIdentifier();
+  if (!II || II != CD.II)
 return false;
   return (CD.RequiredArgs == CallDescription::NoArgRequirement ||
   CD.RequiredArgs == getNumArgs());


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


[PATCH] D29884: [analyzer] Proper caching in CallDescription objects.

2017-02-15 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL295186: [analyzer] Proper caching in CallDescription 
objects. (authored by xazax).

Changed prior to commit:
  https://reviews.llvm.org/D29884?vs=88166&id=88537#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29884

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
  cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp


Index: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -212,9 +212,12 @@
 
 bool CallEvent::isCalled(const CallDescription &CD) const {
   assert(getKind() != CE_ObjCMessage && "Obj-C methods are not supported");
-  if (!CD.II)
+  if (!CD.IsLookupDone) {
+CD.IsLookupDone = true;
 CD.II = 
&getState()->getStateManager().getContext().Idents.get(CD.FuncName);
-  if (getCalleeIdentifier() != CD.II)
+  }
+  const IdentifierInfo *II = getCalleeIdentifier();
+  if (!II || II != CD.II)
 return false;
   return (CD.RequiredArgs == CallDescription::NoArgRequirement ||
   CD.RequiredArgs == getNumArgs());
Index: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
@@ -55,6 +55,7 @@
 class CallDescription {
   friend CallEvent;
   mutable IdentifierInfo *II;
+  mutable bool IsLookupDone;
   StringRef FuncName;
   unsigned RequiredArgs;
 
@@ -68,7 +69,8 @@
   /// call. Omit this parameter to match every occurance of call with a given
   /// name regardless the number of arguments.
   CallDescription(StringRef FuncName, unsigned RequiredArgs = NoArgRequirement)
-  : II(nullptr), FuncName(FuncName), RequiredArgs(RequiredArgs) {}
+  : II(nullptr), IsLookupDone(false), FuncName(FuncName),
+RequiredArgs(RequiredArgs) {}
 
   /// \brief Get the name of the function that this object matches.
   StringRef getFunctionName() const { return FuncName; }


Index: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -212,9 +212,12 @@
 
 bool CallEvent::isCalled(const CallDescription &CD) const {
   assert(getKind() != CE_ObjCMessage && "Obj-C methods are not supported");
-  if (!CD.II)
+  if (!CD.IsLookupDone) {
+CD.IsLookupDone = true;
 CD.II = &getState()->getStateManager().getContext().Idents.get(CD.FuncName);
-  if (getCalleeIdentifier() != CD.II)
+  }
+  const IdentifierInfo *II = getCalleeIdentifier();
+  if (!II || II != CD.II)
 return false;
   return (CD.RequiredArgs == CallDescription::NoArgRequirement ||
   CD.RequiredArgs == getNumArgs());
Index: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
@@ -55,6 +55,7 @@
 class CallDescription {
   friend CallEvent;
   mutable IdentifierInfo *II;
+  mutable bool IsLookupDone;
   StringRef FuncName;
   unsigned RequiredArgs;
 
@@ -68,7 +69,8 @@
   /// call. Omit this parameter to match every occurance of call with a given
   /// name regardless the number of arguments.
   CallDescription(StringRef FuncName, unsigned RequiredArgs = NoArgRequirement)
-  : II(nullptr), FuncName(FuncName), RequiredArgs(RequiredArgs) {}
+  : II(nullptr), IsLookupDone(false), FuncName(FuncName),
+RequiredArgs(RequiredArgs) {}
 
   /// \brief Get the name of the function that this object matches.
   StringRef getFunctionName() const { return FuncName; }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r295187 - [clangd] Fix use after free.

2017-02-15 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Wed Feb 15 09:56:14 2017
New Revision: 295187

URL: http://llvm.org/viewvc/llvm-project?rev=295187&view=rev
Log:
[clangd] Fix use after free.

Modified:
clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp

Modified: clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp?rev=295187&r1=295186&r2=295187&view=diff
==
--- clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp (original)
+++ clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp Wed Feb 15 09:56:14 2017
@@ -95,7 +95,7 @@ void TextDocumentRangeFormattingHandler:
 return;
   }
 
-  StringRef Code = Store.getDocument(DRFP->textDocument.uri);
+  std::string Code = Store.getDocument(DRFP->textDocument.uri);
 
   size_t Begin = positionToOffset(Code, DRFP->range.start);
   size_t Len = positionToOffset(Code, DRFP->range.end) - Begin;


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


[PATCH] D23421: [Clang-tidy] CERT-DCL58-CPP (checker for std namespace modification)

2017-02-15 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun updated this revision to Diff 88541.
xazax.hun added a comment.

- Do not warn for function specializations within the std namespace.
- Add a test case for swap.


https://reviews.llvm.org/D23421

Files:
  clang-tidy/cert/CERTTidyModule.cpp
  clang-tidy/cert/CMakeLists.txt
  clang-tidy/cert/DontModifyStdNamespaceCheck.cpp
  clang-tidy/cert/DontModifyStdNamespaceCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cert-dcl58-cpp.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/Inputs/Headers/system.h
  test/clang-tidy/cert-dcl58-cpp.cpp

Index: test/clang-tidy/cert-dcl58-cpp.cpp
===
--- /dev/null
+++ test/clang-tidy/cert-dcl58-cpp.cpp
@@ -0,0 +1,67 @@
+// RUN: %check_clang_tidy %s cert-dcl58-cpp %t -- -- -std=c++1z -I %S/Inputs/Headers
+
+#include "system.h"
+
+namespace A {
+  namespace B {
+int b;
+  }
+}
+
+namespace A {
+  namespace B {
+int c;
+  }
+}
+
+namespace posix {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: modification of 'posix' namespace can result in undefined behavior [cert-dcl58-cpp]
+  namespace vmi {
+  }
+}
+
+namespace std {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: modification of 'std' namespace can
+  int stdInt;
+}
+
+namespace foobar {
+  namespace std {
+int bar;
+  }
+}
+
+namespace posix::a {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: modification of 'posix' namespace 
+}
+
+enum class MyError {
+  ErrorA,
+  ErrorB
+};
+
+namespace std {
+template <>
+struct is_error_code_enum : std::true_type {};
+
+template<>
+void swap(MyError &a, MyError &b);
+}
+
+enum class MyError2 {
+  Error2A,
+  Error2B
+};
+
+namespace std {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: modification of 'std' namespace 
+template <>
+struct is_error_code_enum : std::true_type {};
+
+int foobar;
+}
+
+using namespace std;
+
+int x;
+
Index: test/clang-tidy/Inputs/Headers/system.h
===
--- /dev/null
+++ test/clang-tidy/Inputs/Headers/system.h
@@ -0,0 +1,24 @@
+#pragma clang system_header
+
+namespace std {
+
+template
+struct integral_constant {
+static constexpr T value = v;
+typedef T value_type;
+typedef integral_constant type;
+constexpr operator value_type() const noexcept { return value; }
+};
+
+template 
+using bool_constant = integral_constant;
+using true_type = bool_constant;
+using false_type = bool_constant;
+
+template
+struct is_error_code_enum : false_type {};
+
+template
+void swap(T &a, T &b);
+}
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -8,6 +8,7 @@
cert-dcl03-c (redirects to misc-static-assert) 
cert-dcl50-cpp
cert-dcl54-cpp (redirects to misc-new-delete-overloads) 
+   cert-dcl58-cpp
cert-dcl59-cpp (redirects to google-build-namespaces) 
cert-env33-c
cert-err09-cpp (redirects to misc-throw-by-value-catch-by-reference) 
Index: docs/clang-tidy/checks/cert-dcl58-cpp.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cert-dcl58-cpp.rst
@@ -0,0 +1,21 @@
+.. title:: clang-tidy - cert-dcl58-cpp
+
+cert-dcl58-cpp
+==
+
+Modification of the ``std`` or ``posix`` namespace can result in undefined
+behavior.
+This check warns for such modifications.
+
+Examples:
+
+.. code-block:: c++
+
+  namespace std {
+int x; // May cause undefined behavior.
+  }
+
+
+This check corresponds to the CERT C++ Coding Standard rule
+`DCL58-CPP. Do not modify the standard namespaces
+`_.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New `cert-dcl58-cpp
+  `_ check
+
+  Finds modification of the ``std`` or ``posix`` namespace.
+
 - New `safety-no-assembler
   `_ check
 
Index: clang-tidy/cert/DontModifyStdNamespaceCheck.h
===
--- /dev/null
+++ clang-tidy/cert/DontModifyStdNamespaceCheck.h
@@ -0,0 +1,36 @@
+//===--- DontModifyStdNamespaceCheck.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_CERT_DONT_MODIFY_STD_NAMESPACE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_DONT_MODIFY_STD_NAMESPACE_H
+
+

[PATCH] D19201: [clang-tidy] misc-throw-with-noexcept

2017-02-15 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: clang-tidy/misc/ThrowWithNoexceptCheck.cpp:54
+// FIXME use DiagnosticIDs::Level::Note
+diag(NoExceptRange.getBegin(), "in a function declared no-throw here:", 
DiagnosticIDs::Note)
+<< FixItHint::CreateRemoval(NoExceptRange);

Prazek wrote:
> sbarzowski wrote:
> > Prazek wrote:
> > > sbarzowski wrote:
> > > > alexfh wrote:
> > > > > nit: `nothrow` (without a dash), no colon needed (it will look weird, 
> > > > > since the location is mentioned _before_ the message, not after it)
> > > > No, it's after the message now. When I changed the level to note the 
> > > > order of messages changed as well.
> > > > 
> > > > It looks like that:
> > > > ```
> > > > /Users/uland/clang-new/build/tools/clang/tools/extra/test/clang-tidy/Output/misc-throw-with-noexcept.cpp.tmp.cpp:5:5:
> > > >  warning: 'throw' expression in a function declared with a non-throwing 
> > > > exception specification [misc-throw-with-noexcept]
> > > > throw 5;
> > > > ^
> > > > /Users/uland/clang-new/build/tools/clang/tools/extra/test/clang-tidy/Output/misc-throw-with-noexcept.cpp.tmp.cpp:3:24:
> > > >  note: FIX-IT applied suggested code changes
> > > > void f_throw_with_ne() noexcept(true) {
> > > >^
> > > > /Users/uland/clang-new/build/tools/clang/tools/extra/test/clang-tidy/Output/misc-throw-with-noexcept.cpp.tmp.cpp:3:24:
> > > >  note: in a function declared nothrow here:
> > > > void f_throw_with_ne() noexcept(true) {
> > > >^
> > > > 
> > > > ```
> > > > 
> > > > So, should I leave the colon or remove it anyway?
> > > I think that the best way would be to have warnings in order:
> > > 
> > > warning function declared nothrow here have throw statement inside:
> > > Note: throw statement here
> > > 
> > > Note: Fixit applied for every other declaration
> > > 
> > > What do you think Alex?
> > > 
> > > 
> > > 
> > @Prazek 
> > So, do you suggest that we don't emit anything for additional declarations 
> > (without -fix)?
> > 
> > BTW (in the current version) I don't know if I can control if FIX-IT goes 
> > first or the location message. As you can see in the code the FIX-IT goes 
> > after the location.
> Yep, there is no need for user to know all the locations if he doesn't want 
> to perform fixit. This way it is easier to read the warning.
The `FIX-IT applied suggested code changes` notes are shown by clang-tidy 
itself and only when the user passes -fix flag. There's no way to control them 
from the check (apart from removing fixes or attaching them to a different 
warning).


https://reviews.llvm.org/D19201



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


[PATCH] D29884: [analyzer] Proper caching in CallDescription objects.

2017-02-15 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

In https://reviews.llvm.org/D29884#677387, @NoQ wrote:

> Yep, seems that somebody has missed these issues :)
>
> I guess there's no way to test the operator case, because nobody made a 
> CallDescription with an empty name for us (maybe we should even assert that).


Thank you for the review! :) Unfortunately, I did not get where would you put 
that assert. But in case you think it is important, I would be happy to review 
a patch :)


Repository:
  rL LLVM

https://reviews.llvm.org/D29884



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


[PATCH] D29884: [analyzer] Proper caching in CallDescription objects.

2017-02-15 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h:73
+  : II(nullptr), IsLookupDone(false), FuncName(FuncName),
+RequiredArgs(RequiredArgs) {}
 

Maybe `assert(FuncName.size() > 0)` here?


Repository:
  rL LLVM

https://reviews.llvm.org/D29884



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


[PATCH] D29884: [analyzer] Proper caching in CallDescription objects.

2017-02-15 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h:73
+  : II(nullptr), IsLookupDone(false), FuncName(FuncName),
+RequiredArgs(RequiredArgs) {}
 

NoQ wrote:
> Maybe `assert(FuncName.size() > 0)` here?
Oh, I see now. Yeah, that would make sense :) Do you want me to commit that or 
will you?


Repository:
  rL LLVM

https://reviews.llvm.org/D29884



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


r295191 - [index] USR generation: use getTemplateArgs() instead of getTemplateInstantiationArgs()

2017-02-15 Thread Argyrios Kyrtzidis via cfe-commits
Author: akirtzidis
Date: Wed Feb 15 10:16:27 2017
New Revision: 295191

URL: http://llvm.org/viewvc/llvm-project?rev=295191&view=rev
Log:
[index] USR generation: use getTemplateArgs() instead of 
getTemplateInstantiationArgs()

Otherwise we may end up creating a different USR for the definition of a 
function, vs its declaration.

Modified:
cfe/trunk/lib/Index/USRGeneration.cpp
cfe/trunk/test/Index/Core/index-source.cpp

Modified: cfe/trunk/lib/Index/USRGeneration.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/USRGeneration.cpp?rev=295191&r1=295190&r2=295191&view=diff
==
--- cfe/trunk/lib/Index/USRGeneration.cpp (original)
+++ cfe/trunk/lib/Index/USRGeneration.cpp Wed Feb 15 10:16:27 2017
@@ -310,7 +310,7 @@ void USRGenerator::VisitVarDecl(const Va
   // For a template specialization, mangle the template arguments.
   if (const VarTemplateSpecializationDecl *Spec
   = dyn_cast(D)) {
-const TemplateArgumentList &Args = Spec->getTemplateInstantiationArgs();
+const TemplateArgumentList &Args = Spec->getTemplateArgs();
 Out << '>';
 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
   Out << '#';
@@ -521,7 +521,7 @@ void USRGenerator::VisitTagDecl(const Ta
   // For a class template specialization, mangle the template arguments.
   if (const ClassTemplateSpecializationDecl *Spec
   = dyn_cast(D)) {
-const TemplateArgumentList &Args = Spec->getTemplateInstantiationArgs();
+const TemplateArgumentList &Args = Spec->getTemplateArgs();
 Out << '>';
 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
   Out << '#';

Modified: cfe/trunk/test/Index/Core/index-source.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-source.cpp?rev=295191&r1=295190&r2=295191&view=diff
==
--- cfe/trunk/test/Index/Core/index-source.cpp (original)
+++ cfe/trunk/test/Index/Core/index-source.cpp Wed Feb 15 10:16:27 2017
@@ -23,6 +23,16 @@ public:
 TemplCls gtv(0);
 // CHECK: [[@LINE-1]]:1 | class(Gen)/C++ | TemplCls | c:@ST>1#T@TemplCls | 
 | Ref,RelCont | rel: 1
 
+template
+class Wrapper {};
+template
+class Wrapper {};
+
+// CHECK: [[@LINE+1]]:6 | function/C | test1 | [[TEST1_USR:.*]] | 
[[TEST1_CG:.*]] | Decl | rel: 0
+void test1(Wrapper f);
+// CHECK: [[@LINE+1]]:6 | function/C | test1 | [[TEST1_USR]] | [[TEST1_CG]] | 
Def | rel: 0
+void test1(Wrapper f) {}
+
 template 
 class BT {
   struct KLR {


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


[PATCH] D29884: [analyzer] Proper caching in CallDescription objects.

2017-02-15 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h:73
+  : II(nullptr), IsLookupDone(false), FuncName(FuncName),
+RequiredArgs(RequiredArgs) {}
 

xazax.hun wrote:
> NoQ wrote:
> > Maybe `assert(FuncName.size() > 0)` here?
> Oh, I see now. Yeah, that would make sense :) Do you want me to commit that 
> or will you?
Because C++ checkers are receiving a lot of attention recently, i'd probably be 
looking into modifying this class to work with qualified names and overloads. 
You can commit though if you want it sooner :)


Repository:
  rL LLVM

https://reviews.llvm.org/D29884



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


[clang-tools-extra] r295192 - [clang-tidy] Don't delay parsing of templates in test for misc-unconventional-assign-operator

2017-02-15 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Wed Feb 15 10:32:55 2017
New Revision: 295192

URL: http://llvm.org/viewvc/llvm-project?rev=295192&view=rev
Log:
[clang-tidy] Don't delay parsing of templates in test for 
misc-unconventional-assign-operator

Modified:

clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp?rev=295192&r1=295191&r2=295192&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp 
Wed Feb 15 10:32:55 2017
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s misc-unconventional-assign-operator %t -- -- 
-std=c++11 -isystem %S/Inputs/Headers
+// RUN: %check_clang_tidy %s misc-unconventional-assign-operator %t -- -- 
-std=c++11 -isystem %S/Inputs/Headers -fno-delayed-template-parsing
 
 namespace std {
 template 


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


[PATCH] D28768: [clang-tidy] Add check 'modernize-return-braced-init-list'

2017-02-15 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere updated this revision to Diff 88550.
JDevlieghere added a comment.

Fixed latest comment from @aaron.ballman before landing.


Repository:
  rL LLVM

https://reviews.llvm.org/D28768

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/ReturnBracedInitListCheck.cpp
  clang-tidy/modernize/ReturnBracedInitListCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-return-braced-init-list.rst
  test/clang-tidy/modernize-return-braced-init-list.cpp

Index: test/clang-tidy/modernize-return-braced-init-list.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-return-braced-init-list.cpp
@@ -0,0 +1,199 @@
+// RUN: %check_clang_tidy %s modernize-return-braced-init-list %t -- --
+// -std=c++14
+
+namespace std {
+typedef decltype(sizeof(int)) size_t;
+
+// libc++'s implementation
+template 
+class initializer_list {
+  const _E *__begin_;
+  size_t __size_;
+
+  initializer_list(const _E *__b, size_t __s)
+  : __begin_(__b),
+__size_(__s) {}
+
+public:
+  typedef _E value_type;
+  typedef const _E &reference;
+  typedef const _E &const_reference;
+  typedef size_t size_type;
+
+  typedef const _E *iterator;
+  typedef const _E *const_iterator;
+
+  initializer_list() : __begin_(nullptr), __size_(0) {}
+
+  size_t size() const { return __size_; }
+  const _E *begin() const { return __begin_; }
+  const _E *end() const { return __begin_ + __size_; }
+};
+
+template 
+class vector {
+public:
+  vector(T) {}
+  vector(std::initializer_list) {}
+};
+}
+
+class Bar {};
+
+Bar b0;
+
+class Foo {
+public:
+  Foo(Bar) {}
+  explicit Foo(Bar, unsigned int) {}
+  Foo(unsigned int) {}
+};
+
+class Baz {
+public:
+  Foo m() {
+Bar bm;
+return Foo(bm);
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: avoid repeating the return type from the declaration; use a braced initializer list instead [modernize-return-braced-init-list]
+// CHECK-FIXES: return {bm};
+  }
+};
+
+class Quux : public Foo {
+public:
+  Quux(Bar bar) : Foo(bar) {}
+  Quux(unsigned, unsigned, unsigned k = 0) : Foo(k) {}
+};
+
+Foo f() {
+  Bar b1;
+  return Foo(b1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: avoid repeating the return type
+  // CHECK-FIXES: return {b1};
+}
+
+Foo f2() {
+  Bar b2;
+  return {b2};
+}
+
+auto f3() {
+  Bar b3;
+  return Foo(b3);
+}
+
+#define A(b) Foo(b)
+
+Foo f4() {
+  Bar b4;
+  return A(b4);
+}
+
+Foo f5() {
+  Bar b5;
+  return Quux(b5);
+}
+
+Foo f6() {
+  Bar b6;
+  return Foo(b6, 1);
+}
+
+std::vector f7() {
+  int i7 = 1;
+  return std::vector(i7);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: avoid repeating the return type
+}
+
+Bar f8() {
+  return {};
+}
+
+Bar f9() {
+  return Bar();
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: avoid repeating the return type
+}
+
+Bar f10() {
+  return Bar{};
+}
+
+Foo f11(Bar b11) {
+  return Foo(b11);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: avoid repeating the return type
+  // CHECK-FIXES: return {b11};
+}
+
+Foo f12() {
+  return f11(Bar());
+}
+
+Foo f13() {
+  return Foo(Bar()); // 13
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: avoid repeating the return type
+  // CHECK-FIXES: return {Bar()}; // 13
+}
+
+Foo f14() {
+  // FIXME: Type narrowing should not occur!
+  return Foo(-1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: avoid repeating the return type
+  // CHECK-FIXES: return {-1};
+}
+
+Foo f15() {
+  return Foo(f10());
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: avoid repeating the return type
+  // CHECK-FIXES: return {f10()};
+}
+
+Quux f16() {
+  return Quux(1, 2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: avoid repeating the return type
+  // CHECK-FIXES: return {1, 2};
+}
+
+Quux f17() {
+  return Quux(1, 2, 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: avoid repeating the return type
+  // CHECK-FIXES: return {1, 2, 3};
+}
+
+template 
+T f19() {
+  return T();
+}
+
+Bar i1 = f19();
+Baz i2 = f19();
+
+template 
+Foo f20(T t) {
+  return Foo(t);
+}
+
+Foo i3 = f20(b0);
+
+template 
+class BazT {
+public:
+  T m() {
+Bar b;
+return T(b);
+  }
+
+  Foo m2(T t) {
+return Foo(t);
+  }
+};
+
+BazT bazFoo;
+Foo i4 = bazFoo.m();
+Foo i5 = bazFoo.m2(b0);
+
+BazT bazQuux;
+Foo i6 = bazQuux.m();
+Foo i7 = bazQuux.m2(b0);
+
+auto v1 = []() { return std::vector({1, 2}); }();
+auto v2 = []() -> std::vector { return std::vector({1, 2}); }();
Index: docs/clang-tidy/checks/modernize-return-braced-init-list.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-return-braced-init-list.rst
@@ -0,0 +1,22 @@
+.. title:: clang-tidy - modernize-return-braced-init-list
+
+modernize-return-braced-init-list
+=
+
+Replaces explicit calls to the constructor in a return with a braced
+initializer list. This way the return type is not n

[clang-tools-extra] r295193 - [clangd] Initialize the thread after the mutex.

2017-02-15 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Wed Feb 15 10:34:58 2017
New Revision: 295193

URL: http://llvm.org/viewvc/llvm-project?rev=295193&view=rev
Log:
[clangd] Initialize the thread after the mutex.

Otherwise locking the mutex yields a racy assertion failure on picky
implementations.

Modified:
clang-tools-extra/trunk/clangd/ASTManager.h

Modified: clang-tools-extra/trunk/clangd/ASTManager.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ASTManager.h?rev=295193&r1=295192&r2=295193&view=diff
==
--- clang-tools-extra/trunk/clangd/ASTManager.h (original)
+++ clang-tools-extra/trunk/clangd/ASTManager.h Wed Feb 15 10:34:58 2017
@@ -57,9 +57,6 @@ private:
   CompilationDatabases;
   std::shared_ptr PCHs;
 
-  /// We run parsing on a separate thread. This thread looks into 
PendingRequest
-  /// as a 'one element work queue' as long as RequestIsPending is true.
-  std::thread ClangWorker;
   /// Queue of requests.
   std::deque RequestQueue;
   /// Setting Done to true will make the worker thread terminate.
@@ -68,6 +65,10 @@ private:
   std::condition_variable ClangRequestCV;
   /// Lock for accesses to RequestQueue and Done.
   std::mutex RequestLock;
+
+  /// We run parsing on a separate thread. This thread looks into 
PendingRequest
+  /// as a 'one element work queue' as the queue is non-empty.
+  std::thread ClangWorker;
 };
 
 } // namespace clangd


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


[clang-tools-extra] r295194 - [clangd] Synchronize logs access.

2017-02-15 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Wed Feb 15 10:44:11 2017
New Revision: 295194

URL: http://llvm.org/viewvc/llvm-project?rev=295194&view=rev
Log:
[clangd] Synchronize logs access.

I don't think that this is necessary for correctness, but makes tsan
much more useful.

Modified:
clang-tools-extra/trunk/clangd/ASTManager.cpp
clang-tools-extra/trunk/clangd/ClangDMain.cpp
clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp

Modified: clang-tools-extra/trunk/clangd/ASTManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ASTManager.cpp?rev=295194&r1=295193&r2=295194&view=diff
==
--- clang-tools-extra/trunk/clangd/ASTManager.cpp (original)
+++ clang-tools-extra/trunk/clangd/ASTManager.cpp Wed Feb 15 10:44:11 2017
@@ -150,7 +150,7 @@ ASTManager::getOrCreateCompilationDataba
 
   std::string Error;
   I = tooling::CompilationDatabase::autoDetectFromSource(Uri, Error);
-  Output.logs() << "Failed to load compilation database: " << Error << '\n';
+  Output.log("Failed to load compilation database: " + Twine(Error) + "\n");
   return I.get();
 }
 

Modified: clang-tools-extra/trunk/clangd/ClangDMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangDMain.cpp?rev=295194&r1=295193&r2=295194&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangDMain.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangDMain.cpp Wed Feb 15 10:44:11 2017
@@ -88,12 +88,11 @@ int main(int argc, char *argv[]) {
 if (Len > 0) {
   llvm::StringRef JSONRef(JSON.data(), Len);
   // Log the message.
-  Logs << "<-- " << JSONRef << '\n';
-  Logs.flush();
+  Out.log("<-- " + JSONRef + "\n");
 
   // Finally, execute the action for this JSON message.
   if (!Dispatcher.call(JSONRef))
-Logs << "JSON dispatch failed!\n";
+Out.log("JSON dispatch failed!\n");
 
   // If we're done, exit the loop.
   if (ShutdownHandler->isDone())

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp?rev=295194&r1=295193&r2=295194&view=diff
==
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Wed Feb 15 10:44:11 
2017
@@ -29,8 +29,14 @@ void JSONOutput::writeMessage(const Twin
   Outs.flush();
 }
 
+void JSONOutput::log(const Twine &Message) {
+  std::lock_guard Guard(StreamMutex);
+  Logs << Message;
+  Logs.flush();
+}
+
 void Handler::handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) {
-  Output.logs() << "Method ignored.\n";
+  Output.log("Method ignored.\n");
   // Return that this method is unsupported.
   writeMessage(
   R"({"jsonrpc":"2.0","id":)" + ID +
@@ -38,7 +44,7 @@ void Handler::handleMethod(llvm::yaml::M
 }
 
 void Handler::handleNotification(llvm::yaml::MappingNode *Params) {
-  Output.logs() << "Notification ignored.\n";
+  Output.log("Notification ignored.\n");
 }
 
 void JSONRPCDispatcher::registerHandler(StringRef Method,

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h?rev=295194&r1=295193&r2=295194&view=diff
==
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h Wed Feb 15 10:44:11 2017
@@ -28,8 +28,8 @@ public:
   /// Emit a JSONRPC message.
   void writeMessage(const Twine &Message);
 
-  /// Get the logging stream.
-  llvm::raw_ostream &logs() { return Logs; }
+  /// Write to the logging stream.
+  void log(const Twine &Message);
 
 private:
   llvm::raw_ostream &Outs;

Modified: clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp?rev=295194&r1=295193&r2=295194&view=diff
==
--- clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp (original)
+++ clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp Wed Feb 15 10:44:11 2017
@@ -17,7 +17,7 @@ void TextDocumentDidOpenHandler::handleN
 llvm::yaml::MappingNode *Params) {
   auto DOTDP = DidOpenTextDocumentParams::parse(Params);
   if (!DOTDP) {
-Output.logs() << "Failed to decode DidOpenTextDocumentParams!\n";
+Output.log("Failed to decode DidOpenTextDocumentParams!\n");
 return;
   }
   Store.addDocument(DOTDP->textDocument.uri, DOTDP->textDocument.text);
@@ -27,7 +27,7 @@ void TextDocumentDidChangeHandler::handl
 llvm::yaml::Mapp

[PATCH] D29599: Clang Changes for alloc_align

2017-02-15 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Ah, I see!  Sorry for missing that.  I don't see a reason why we cannot support 
that, but I wasn't really considering it.  In general, this attribute is a 
compiler hint for some C standard library stuff in glibc.

I've been playing with it a few hours now, and it seems that GCC ONLY complains 
about the attribute parameter being in range (same error for the type of the 
parameter as well!), so we DO a bit extra SEMA here, though I think that is 
correct.  I'll dig into this a bit more and see if I can get the template 
return type working correctly.


https://reviews.llvm.org/D29599



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


[clang-tools-extra] r295196 - [clangd] Silence GCC warning about falling off a fully covered switch.

2017-02-15 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Wed Feb 15 10:58:44 2017
New Revision: 295196

URL: http://llvm.org/viewvc/llvm-project?rev=295196&view=rev
Log:
[clangd] Silence GCC warning about falling off a fully covered switch.

Modified:
clang-tools-extra/trunk/clangd/ASTManager.cpp

Modified: clang-tools-extra/trunk/clangd/ASTManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ASTManager.cpp?rev=295196&r1=295195&r2=295196&view=diff
==
--- clang-tools-extra/trunk/clangd/ASTManager.cpp (original)
+++ clang-tools-extra/trunk/clangd/ASTManager.cpp Wed Feb 15 10:58:44 2017
@@ -51,6 +51,7 @@ static int getSeverity(DiagnosticsEngine
   case DiagnosticsEngine::Ignored:
 return 0;
   }
+  llvm_unreachable("Unknown diagnostic level!");
 }
 
 ASTManager::ASTManager(JSONOutput &Output, DocumentStore &Store)


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


[clang-tools-extra] r295198 - [clangd] Fix another use after free that I missed because COW strings.

2017-02-15 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Wed Feb 15 11:04:57 2017
New Revision: 295198

URL: http://llvm.org/viewvc/llvm-project?rev=295198&view=rev
Log:
[clangd] Fix another use after free that I missed because COW strings.

Modified:
clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp

Modified: clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp?rev=295198&r1=295197&r2=295198&view=diff
==
--- clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp (original)
+++ clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp Wed Feb 15 11:04:57 2017
@@ -113,7 +113,7 @@ void TextDocumentFormattingHandler::hand
   }
 
   // Format everything.
-  StringRef Code = Store.getDocument(DFP->textDocument.uri);
+  std::string Code = Store.getDocument(DFP->textDocument.uri);
   writeMessage(formatCode(Code, DFP->textDocument.uri,
   {clang::tooling::Range(0, Code.size())}, ID));
 }


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


[clang-tools-extra] r295199 - [clang-tidy] Add check 'modernize-return-braced-init-list'

2017-02-15 Thread Jonas Devlieghere via cfe-commits
Author: jdevlieghere
Date: Wed Feb 15 11:06:06 2017
New Revision: 295199

URL: http://llvm.org/viewvc/llvm-project?rev=295199&view=rev
Log:
[clang-tidy] Add check 'modernize-return-braced-init-list'

Summary:
Replaces explicit calls to the constructor in a return with a braced
initializer list. This way the return type is not needlessly duplicated in the
return type and the return statement.

```
Foo bar() {
  Baz baz;
  return Foo(baz);
}

// transforms to:

Foo bar() {
  Baz baz;
  return {baz};
}
```

Reviewers: hokein, Prazek, aaron.ballman, alexfh

Reviewed By: Prazek, aaron.ballman, alexfh

Subscribers: malcolm.parsons, mgorny, cfe-commits

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/ReturnBracedInitListCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-return-braced-init-list.rst

clang-tools-extra/trunk/test/clang-tidy/modernize-return-braced-init-list.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt?rev=295199&r1=295198&r2=295199&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt Wed Feb 15 
11:06:06 2017
@@ -13,6 +13,7 @@ add_clang_library(clangTidyModernizeModu
   RawStringLiteralCheck.cpp
   RedundantVoidArgCheck.cpp
   ReplaceAutoPtrCheck.cpp
+  ReturnBracedInitListCheck.cpp
   ShrinkToFitCheck.cpp
   UseAutoCheck.cpp
   UseBoolLiteralsCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp?rev=295199&r1=295198&r2=295199&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp Wed 
Feb 15 11:06:06 2017
@@ -19,6 +19,7 @@
 #include "RawStringLiteralCheck.h"
 #include "RedundantVoidArgCheck.h"
 #include "ReplaceAutoPtrCheck.h"
+#include "ReturnBracedInitListCheck.h"
 #include "ShrinkToFitCheck.h"
 #include "UseAutoCheck.h"
 #include "UseBoolLiteralsCheck.h"
@@ -53,6 +54,8 @@ public:
 "modernize-redundant-void-arg");
 CheckFactories.registerCheck(
 "modernize-replace-auto-ptr");
+CheckFactories.registerCheck(
+"modernize-return-braced-init-list");
 CheckFactories.registerCheck("modernize-shrink-to-fit");
 CheckFactories.registerCheck("modernize-use-auto");
 CheckFactories.registerCheck(

Added: 
clang-tools-extra/trunk/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/ReturnBracedInitListCheck.cpp?rev=295199&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/modernize/ReturnBracedInitListCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/modernize/ReturnBracedInitListCheck.cpp 
Wed Feb 15 11:06:06 2017
@@ -0,0 +1,97 @@
+//===--- ReturnBracedInitListCheck.cpp - 
clang-tidy===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ReturnBracedInitListCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/FixIt.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+void ReturnBracedInitListCheck::registerMatchers(MatchFinder *Finder) {
+  // Only register the matchers for C++.
+  if (!getLangOpts().CPlusPlus11)
+return;
+
+  // Skip list initialization and constructors with an initializer list.
+  auto ConstructExpr =
+  cxxConstructExpr(
+  unless(anyOf(hasDeclaration(cxxConstructorDecl(isExplicit())),
+   isListInitialization(), hasDescendant(initListExpr()),
+   isInTemplateInstantiation(
+  .bind("ctor");
+
+  auto CtorAsArgument = materializeTemporaryExpr(anyOf(
+  has(ConstructExpr), has(cxxFunctionalCastExpr(has(ConstructExpr);
+
+  Finder->addMatc

[PATCH] D29032: [mips] Define macros related to -mabicalls in the preprocessor

2017-02-15 Thread Simon Dardis via Phabricator via cfe-commits
sdardis added a comment.

Ok, I'll have `__mips_abicalls` unconditionally defined for everyone, The other 
two BSD's will have the traditional macro defined as well.


https://reviews.llvm.org/D29032



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


[libunwind] r295202 - Revert "[libunwind][CMake] Use libc++ headers when available"

2017-02-15 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Wed Feb 15 11:15:41 2017
New Revision: 295202

URL: http://llvm.org/viewvc/llvm-project?rev=295202&view=rev
Log:
Revert "[libunwind][CMake] Use libc++ headers when available"

This causing build failure on sanitizer bots because of the unused
argument '-nostdinc++' during linking of libunwind.

This reverts commit 0e14fd1a1d37b9c6d55a2d3bc7649e5b39ce74d3.

Modified:
libunwind/trunk/CMakeLists.txt

Modified: libunwind/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/CMakeLists.txt?rev=295202&r1=295201&r2=295202&view=diff
==
--- libunwind/trunk/CMakeLists.txt (original)
+++ libunwind/trunk/CMakeLists.txt Wed Feb 15 11:15:41 2017
@@ -282,24 +282,4 @@ endif()
 
 include_directories(include)
 
-find_path(
-  LIBUNWIND_LIBCXX_INCLUDES_INTERNAL
-  __libcpp_version
-  PATHS ${LLVM_MAIN_SRC_DIR}/projects/libcxx/include
-${LLVM_MAIN_SRC_DIR}/runtimes/libcxx/include
-  NO_DEFAULT_PATH
-)
-if ((NOT LIBUNWIND_STANDALONE_BUILD OR HAVE_LIBCXX) AND
-IS_DIRECTORY "${LIBUNWIND_LIBCXX_INCLUDES_INTERNAL}")
-  set(LIBUNWIND_CXX_INCLUDE_PATHS_DEFAULT 
"${LIBUNWIND_LIBCXX_INCLUDES_INTERNAL}")
-endif()
-
-set(LIBUNWIND_CXX_INCLUDE_PATHS "${LIBUNWIND_CXX_INCLUDE_PATHS_DEFAULT}" CACHE 
PATH
-"Paths to C++ header directories separated by ';'.")
-
-if (NOT LIBUNWIND_CXX_INCLUDE_PATHS STREQUAL "")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdinc++")
-  include_directories("${LIBUNWIND_CXX_INCLUDE_PATHS}")
-endif()
-
 add_subdirectory(src)


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


[clang-tools-extra] r295205 - Fixed indentation issue in release notes

2017-02-15 Thread Jonas Devlieghere via cfe-commits
Author: jdevlieghere
Date: Wed Feb 15 11:19:44 2017
New Revision: 295205

URL: http://llvm.org/viewvc/llvm-project?rev=295205&view=rev
Log:
Fixed indentation issue in release notes

Modified:
clang-tools-extra/trunk/docs/ReleaseNotes.rst

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=295205&r1=295204&r2=295205&view=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Wed Feb 15 11:19:44 2017
@@ -68,7 +68,7 @@ Improvements to clang-tidy
   Finds uses of inline assembler.
 
 - New `modernize-return-braced-init-list
-
`_
 check
+  
`_
 check
 
   Finds and replaces explicit calls to the constructor in a return statement by
   a braced initializer list so that the return type is not needlessly repeated.


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


[clang-tools-extra] r295207 - [clang-tidy] Fix test modernize-return-braced-init-list

2017-02-15 Thread Jonas Devlieghere via cfe-commits
Author: jdevlieghere
Date: Wed Feb 15 11:37:58 2017
New Revision: 295207

URL: http://llvm.org/viewvc/llvm-project?rev=295207&view=rev
Log:
[clang-tidy] Fix test modernize-return-braced-init-list

Modified:

clang-tools-extra/trunk/test/clang-tidy/modernize-return-braced-init-list.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/modernize-return-braced-init-list.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-return-braced-init-list.cpp?rev=295207&r1=295206&r2=295207&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/modernize-return-braced-init-list.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/modernize-return-braced-init-list.cpp 
Wed Feb 15 11:37:58 2017
@@ -1,5 +1,4 @@
-// RUN: %check_clang_tidy %s modernize-return-braced-init-list %t -- --
-// -std=c++14
+// RUN: %check_clang_tidy %s modernize-return-braced-init-list %t -- -- 
-std=c++14
 
 namespace std {
 typedef decltype(sizeof(int)) size_t;


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


[PATCH] D29990: [clangd] Implement format on type

2017-02-15 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer added inline comments.



Comment at: clangd/ProtocolHandlers.cpp:117
+  // starting from there.
+  StringRef Code = Store.getDocument(DOTFP->textDocument.uri);
+  size_t CursorPos = positionToOffset(Code, DOTFP->position);

This should be a std::string in trunk, StringRef gives you a use after free.



Comment at: clangd/ProtocolHandlers.cpp:119
+  size_t CursorPos = positionToOffset(Code, DOTFP->position);
+  size_t PreviousLBracePos = Code.find_last_of("{", CursorPos);
+  if (PreviousLBracePos == StringRef::npos)

nit: use the character overload of this function (`Code.find_last_of('{'...`)


https://reviews.llvm.org/D29990



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


[PATCH] D26654: [CMake] Add Fuchsia toolchain CMake cache files

2017-02-15 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 88575.

Repository:
  rL LLVM

https://reviews.llvm.org/D26654

Files:
  cmake/caches/Fuchsia-stage2.cmake
  cmake/caches/Fuchsia.cmake

Index: cmake/caches/Fuchsia.cmake
===
--- /dev/null
+++ cmake/caches/Fuchsia.cmake
@@ -0,0 +1,44 @@
+# This file sets up a CMakeCache for a Fuchsia toolchain build.
+
+set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
+
+set(PACKAGE_VENDOR Fuchsia CACHE STRING "")
+
+set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
+set(LLVM_INCLUDE_TESTS OFF CACHE BOOL "")
+set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
+set(CLANG_INCLUDE_TESTS OFF CACHE BOOL "")
+set(LLVM_ENABLE_ZLIB OFF CACHE BOOL "")
+set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
+set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
+
+set(CMAKE_BUILD_TYPE Release CACHE STRING "")
+
+set(BOOTSTRAP_LLVM_ENABLE_LTO ON CACHE BOOL "")
+if(NOT APPLE)
+  set(BOOTSTRAP_LLVM_ENABLE_LLD ON CACHE BOOL "")
+endif()
+
+set(CLANG_BOOTSTRAP_TARGETS
+  check-all
+  check-llvm
+  check-clang
+  llvm-config
+  test-suite
+  test-depends
+  llvm-test-depends
+  clang-test-depends
+  distribution
+  install-distribution
+  clang CACHE STRING "")
+
+if(FUCHSIA_SYSROOT)
+  set(EXTRA_ARGS -DFUCHSIA_SYSROOT=${FUCHSIA_SYSROOT})
+endif()
+
+# Setup the bootstrap build.
+set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
+set(CLANG_BOOTSTRAP_CMAKE_ARGS
+  ${EXTRA_ARGS}
+  -C ${CMAKE_CURRENT_LIST_DIR}/Fuchsia-stage2.cmake
+  CACHE STRING "")
Index: cmake/caches/Fuchsia-stage2.cmake
===
--- /dev/null
+++ cmake/caches/Fuchsia-stage2.cmake
@@ -0,0 +1,64 @@
+# This file sets up a CMakeCache for the second stage of a Fuchsia toolchain
+# build.
+
+set(LLVM_TARGETS_TO_BUILD X86;AArch64 CACHE STRING "")
+
+set(PACKAGE_VENDOR Fuchsia CACHE STRING "")
+
+set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
+set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
+set(LLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD OFF CACHE BOOL "")
+set(LLVM_ENABLE_ZLIB ON CACHE BOOL "")
+set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
+set(LLVM_EXTERNALIZE_DEBUGINFO ON CACHE BOOL "")
+set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
+
+set(LLVM_ENABLE_LTO ON CACHE BOOL "")
+if(NOT APPLE)
+  set(LLVM_ENABLE_LLD ON CACHE BOOL "")
+  set(CLANG_DEFAULT_LINKER lld CACHE STRING "")
+endif()
+
+#set(CLANG_DEFAULT_CXX_STDLIB libc++ CACHE STRING "")
+
+#set(CMAKE_BUILD_TYPE Release CACHE STRING "")
+set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -gline-tables-only -DNDEBUG" CACHE STRING "")
+set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -gline-tables-only -DNDEBUG" CACHE STRING "")
+
+set(LLVM_BUILTIN_TARGETS "x86_64-fuchsia-none;aarch64-fuchsia-none" CACHE STRING "")
+set(BUILTINS_x86_64-fuchsia-none_CMAKE_SYSROOT ${FUCHSIA_SYSROOT} CACHE STRING "")
+set(BUILTINS_x86_64-fuchsia-none_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
+set(BUILTINS_aarch64-fuchsia-none_CMAKE_SYSROOT ${FUCHSIA_SYSROOT} CACHE STRING "")
+set(BUILTINS_aarch64-fuchsia-none_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
+
+# Setup toolchain.
+set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
+set(LLVM_TOOLCHAIN_TOOLS
+  llvm-ar
+  llvm-cov
+  llvm-cxxfilt
+  llvm-dwarfdump
+  llvm-dsymutil
+  llvm-lib
+  llvm-nm
+  llvm-objdump
+  llvm-profdata
+  llvm-ranlib
+  llvm-readobj
+  llvm-size
+  llvm-symbolizer
+  CACHE STRING "")
+
+set(LLVM_DISTRIBUTION_COMPONENTS
+  clang
+  lld
+  lldb
+  LTO
+  clang-format
+  clang-headers
+  builtins-x86_64-fuchsia-none
+  builtins-aarch64-fuchsia-none
+  runtimes
+  ${LLVM_TOOLCHAIN_TOOLS}
+  CACHE STRING "")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r295214 - Merging r294431:

2017-02-15 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Wed Feb 15 12:40:52 2017
New Revision: 295214

URL: http://llvm.org/viewvc/llvm-project?rev=295214&view=rev
Log:
Merging r294431:

r294431 | mgorny | 2017-02-08 01:57:32 -0800 (Wed, 08 Feb 2017) | 7 lines

[test] Fix hard_link_count test to account for fs with dir nlink==1

Filesystems are not required to maintain a hard link count consistent
with number of subdirectories. For example, on btrfs all directories
have nlink==1. Account for that in the test.

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


Modified:
libcxx/branches/release_40/   (props changed)

libcxx/branches/release_40/test/std/experimental/filesystem/fs.op.funcs/fs.op.hard_lk_ct/hard_link_count.pass.cpp

Propchange: libcxx/branches/release_40/
--
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Feb 15 12:40:52 2017
@@ -1,2 +1,2 @@
 /libcxx/branches/apple:136569-137939
-/libcxx/trunk:292013,292091,292607,292990,293154,293197,293581,294133,294142
+/libcxx/trunk:292013,292091,292607,292990,293154,293197,293581,294133,294142,294431

Modified: 
libcxx/branches/release_40/test/std/experimental/filesystem/fs.op.funcs/fs.op.hard_lk_ct/hard_link_count.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_40/test/std/experimental/filesystem/fs.op.funcs/fs.op.hard_lk_ct/hard_link_count.pass.cpp?rev=295214&r1=295213&r2=295214&view=diff
==
--- 
libcxx/branches/release_40/test/std/experimental/filesystem/fs.op.funcs/fs.op.hard_lk_ct/hard_link_count.pass.cpp
 (original)
+++ 
libcxx/branches/release_40/test/std/experimental/filesystem/fs.op.funcs/fs.op.hard_lk_ct/hard_link_count.pass.cpp
 Wed Feb 15 12:40:52 2017
@@ -57,15 +57,19 @@ TEST_CASE(hard_link_count_for_directory)
 Dir3Expect = 3; // .  ..  file5
 #endif
 TEST_CHECK(hard_link_count(StaticEnv::Dir) == DirExpect ||
-   hard_link_count(StaticEnv::Dir) == DirExpectAlt);
+   hard_link_count(StaticEnv::Dir) == DirExpectAlt ||
+   hard_link_count(StaticEnv::Dir) == 1);
 TEST_CHECK(hard_link_count(StaticEnv::Dir3) == Dir3Expect ||
-   hard_link_count(StaticEnv::Dir3) == Dir3ExpectAlt);
+   hard_link_count(StaticEnv::Dir3) == Dir3ExpectAlt ||
+   hard_link_count(StaticEnv::Dir3) == 1);
 
 std::error_code ec;
 TEST_CHECK(hard_link_count(StaticEnv::Dir, ec) == DirExpect ||
-   hard_link_count(StaticEnv::Dir, ec) == DirExpectAlt);
+   hard_link_count(StaticEnv::Dir, ec) == DirExpectAlt ||
+   hard_link_count(StaticEnv::Dir) == 1);
 TEST_CHECK(hard_link_count(StaticEnv::Dir3, ec) == Dir3Expect ||
-   hard_link_count(StaticEnv::Dir3, ec) == Dir3ExpectAlt);
+   hard_link_count(StaticEnv::Dir3, ec) == Dir3ExpectAlt ||
+   hard_link_count(StaticEnv::Dir3) == 1);
 }
 TEST_CASE(hard_link_count_increments_test)
 {


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


Re: [libcxx] r294431 - [test] Fix hard_link_count test to account for fs with dir nlink==1

2017-02-15 Thread Hans Wennborg via cfe-commits
Michal requested this to be merged in PR31965, it seems fine to me,
and Marshall OK'd it in an email to me. Merged in r295214.

On Wed, Feb 8, 2017 at 1:57 AM, Michal Gorny via cfe-commits
 wrote:
> Author: mgorny
> Date: Wed Feb  8 03:57:32 2017
> New Revision: 294431
>
> URL: http://llvm.org/viewvc/llvm-project?rev=294431&view=rev
> Log:
> [test] Fix hard_link_count test to account for fs with dir nlink==1
>
> Filesystems are not required to maintain a hard link count consistent
> with number of subdirectories. For example, on btrfs all directories
> have nlink==1. Account for that in the test.
>
> Differential Revision: https://reviews.llvm.org/D29706
>
> Modified:
> 
> libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.hard_lk_ct/hard_link_count.pass.cpp
>
> Modified: 
> libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.hard_lk_ct/hard_link_count.pass.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.hard_lk_ct/hard_link_count.pass.cpp?rev=294431&r1=294430&r2=294431&view=diff
> ==
> --- 
> libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.hard_lk_ct/hard_link_count.pass.cpp
>  (original)
> +++ 
> libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.hard_lk_ct/hard_link_count.pass.cpp
>  Wed Feb  8 03:57:32 2017
> @@ -57,15 +57,19 @@ TEST_CASE(hard_link_count_for_directory)
>  Dir3Expect = 3; // .  ..  file5
>  #endif
>  TEST_CHECK(hard_link_count(StaticEnv::Dir) == DirExpect ||
> -   hard_link_count(StaticEnv::Dir) == DirExpectAlt);
> +   hard_link_count(StaticEnv::Dir) == DirExpectAlt ||
> +   hard_link_count(StaticEnv::Dir) == 1);
>  TEST_CHECK(hard_link_count(StaticEnv::Dir3) == Dir3Expect ||
> -   hard_link_count(StaticEnv::Dir3) == Dir3ExpectAlt);
> +   hard_link_count(StaticEnv::Dir3) == Dir3ExpectAlt ||
> +   hard_link_count(StaticEnv::Dir3) == 1);
>
>  std::error_code ec;
>  TEST_CHECK(hard_link_count(StaticEnv::Dir, ec) == DirExpect ||
> -   hard_link_count(StaticEnv::Dir, ec) == DirExpectAlt);
> +   hard_link_count(StaticEnv::Dir, ec) == DirExpectAlt ||
> +   hard_link_count(StaticEnv::Dir) == 1);
>  TEST_CHECK(hard_link_count(StaticEnv::Dir3, ec) == Dir3Expect ||
> -   hard_link_count(StaticEnv::Dir3, ec) == Dir3ExpectAlt);
> +   hard_link_count(StaticEnv::Dir3, ec) == Dir3ExpectAlt ||
> +   hard_link_count(StaticEnv::Dir3) == 1);
>  }
>  TEST_CASE(hard_link_count_increments_test)
>  {
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D30000: Fix for pr31836 - pp_nonportable_path on absolute paths: broken delimiters

2017-02-15 Thread Taewook Oh via Phabricator via cfe-commits
twoh created this revision.

This is a patch for PR31836. As the bug replaces the path separators in the 
included file name with the characters following them, the test script makes 
sure that there's no "Ccase-insensitive-include-pr31836.h" in the warning 
message.


https://reviews.llvm.org/D3

Files:
  lib/Lex/PPDirectives.cpp
  test/Lexer/case-insensitive-include-pr31836.sh


Index: test/Lexer/case-insensitive-include-pr31836.sh
===
--- /dev/null
+++ test/Lexer/case-insensitive-include-pr31836.sh
@@ -0,0 +1,9 @@
+// REQUIRES: case-insensitive-filesystem
+
+// RUN: mkdir -p %T
+// RUN: touch %T/case-insensitive-include-pr31836.h
+// RUN: echo "#include \"%T/Case-Insensitive-Include-Pr31836.h\"" | %clang_cc1 
-E - 2>&1 | FileCheck %s
+
+// CHECK: warning: non-portable path to file
+// CHECK-NOT: Ccase-insensitive-include-pr31836.h
+// CHECK: {{$}}
Index: lib/Lex/PPDirectives.cpp
===
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -1976,8 +1976,12 @@
   SmallString<128> Path;
   Path.reserve(Name.size()+2);
   Path.push_back(isAngled ? '<' : '"');
+  bool isLeadingSeparator = llvm::sys::path::is_absolute(Name);
   for (auto Component : Components) {
-Path.append(Component);
+if (isLeadingSeparator)
+  isLeadingSeparator = false;
+else
+  Path.append(Component);
 // Append the separator the user used, or the close quote
 Path.push_back(
   Path.size() <= Filename.size() ? Filename[Path.size()-1] :


Index: test/Lexer/case-insensitive-include-pr31836.sh
===
--- /dev/null
+++ test/Lexer/case-insensitive-include-pr31836.sh
@@ -0,0 +1,9 @@
+// REQUIRES: case-insensitive-filesystem
+
+// RUN: mkdir -p %T
+// RUN: touch %T/case-insensitive-include-pr31836.h
+// RUN: echo "#include \"%T/Case-Insensitive-Include-Pr31836.h\"" | %clang_cc1 -E - 2>&1 | FileCheck %s
+
+// CHECK: warning: non-portable path to file
+// CHECK-NOT: Ccase-insensitive-include-pr31836.h
+// CHECK: {{$}}
Index: lib/Lex/PPDirectives.cpp
===
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -1976,8 +1976,12 @@
   SmallString<128> Path;
   Path.reserve(Name.size()+2);
   Path.push_back(isAngled ? '<' : '"');
+  bool isLeadingSeparator = llvm::sys::path::is_absolute(Name);
   for (auto Component : Components) {
-Path.append(Component);
+if (isLeadingSeparator)
+  isLeadingSeparator = false;
+else
+  Path.append(Component);
 // Append the separator the user used, or the close quote
 Path.push_back(
   Path.size() <= Filename.size() ? Filename[Path.size()-1] :
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D23421: [Clang-tidy] CERT-DCL58-CPP (checker for std namespace modification)

2017-02-15 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 working on this!


https://reviews.llvm.org/D23421



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


[PATCH] D30000: Fix for pr31836 - pp_nonportable_path on absolute paths: broken delimiters

2017-02-15 Thread Eric Niebler via Phabricator via cfe-commits
eric_niebler added a subscriber: karies.
eric_niebler added inline comments.



Comment at: lib/Lex/PPDirectives.cpp:1983
+  isLeadingSeparator = false;
+else
+  Path.append(Component);

What happens on Windows for an absolute path like "C:/hello/world.h", I wonder? 
Does this correctly generate the fixit? @karies?



Comment at: test/Lexer/case-insensitive-include-pr31836.sh:8
+// CHECK: warning: non-portable path to file
+// CHECK-NOT: Ccase-insensitive-include-pr31836.h
+// CHECK: {{$}}

@twoh I'm curious why you chose to check that the output was not a specific 
incorrect answer instead of checking that the output was the correct answer.


https://reviews.llvm.org/D3



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


[PATCH] D30002: [clang-tidy] Fix handling of methods with try-statement as a body in modernize-use-override

2017-02-15 Thread Paweł Żukowski via Phabricator via cfe-commits
idlecode created this revision.
idlecode added a project: clang-tools-extra.
Herald added a subscriber: JDevlieghere.

Fix generated by modernize-use-override caused syntax error when method
used try-statement as a body. `override` keyword was inserted after last
declaration token which happened to be a `try` keyword.

This fixes PR27119.


https://reviews.llvm.org/D30002

Files:
  clang-tidy/modernize/UseOverrideCheck.cpp
  test/clang-tidy/modernize-use-override.cpp


Index: test/clang-tidy/modernize-use-override.cpp
===
--- test/clang-tidy/modernize-use-override.cpp
+++ test/clang-tidy/modernize-use-override.cpp
@@ -288,3 +288,17 @@
 };
 template <> void MembersOfSpecializations<3>::a() {}
 void ff() { MembersOfSpecializations<3>().a(); };
+
+// In case try statement is used as a method body,
+// make sure that override fix is placed before try keyword.
+struct TryStmtAsBody : public Base {
+  void a() try
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this
+  // CHECK-FIXES: {{^}}  void a() override try
+  { b(); } catch(...) { c(); }
+
+  virtual void d() try
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+  // CHECK-FIXES: {{^}}  void d() override try
+  { e(); } catch(...) { f(); }
+};
Index: clang-tidy/modernize/UseOverrideCheck.cpp
===
--- clang-tidy/modernize/UseOverrideCheck.cpp
+++ clang-tidy/modernize/UseOverrideCheck.cpp
@@ -147,14 +147,13 @@
   // end of the declaration of the function, but prefer to put it on the
   // same line as the declaration if the beginning brace for the start of
   // the body falls on the next line.
-  Token LastNonCommentToken;
-  for (Token T : Tokens) {
-if (!T.is(tok::comment)) {
-  LastNonCommentToken = T;
-}
-  }
-  InsertLoc = LastNonCommentToken.getEndLoc();
   ReplacementText = " override";
+  auto LastTokenIter = std::prev(Tokens.end());
+  // When try statement is used instead of compound statement as
+  // method body - insert override keyword before it.
+  if (LastTokenIter->is(tok::kw_try))
+LastTokenIter = std::prev(LastTokenIter);
+  InsertLoc = LastTokenIter->getEndLoc();
 }
 
 if (!InsertLoc.isValid()) {


Index: test/clang-tidy/modernize-use-override.cpp
===
--- test/clang-tidy/modernize-use-override.cpp
+++ test/clang-tidy/modernize-use-override.cpp
@@ -288,3 +288,17 @@
 };
 template <> void MembersOfSpecializations<3>::a() {}
 void ff() { MembersOfSpecializations<3>().a(); };
+
+// In case try statement is used as a method body,
+// make sure that override fix is placed before try keyword.
+struct TryStmtAsBody : public Base {
+  void a() try
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this
+  // CHECK-FIXES: {{^}}  void a() override try
+  { b(); } catch(...) { c(); }
+
+  virtual void d() try
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+  // CHECK-FIXES: {{^}}  void d() override try
+  { e(); } catch(...) { f(); }
+};
Index: clang-tidy/modernize/UseOverrideCheck.cpp
===
--- clang-tidy/modernize/UseOverrideCheck.cpp
+++ clang-tidy/modernize/UseOverrideCheck.cpp
@@ -147,14 +147,13 @@
   // end of the declaration of the function, but prefer to put it on the
   // same line as the declaration if the beginning brace for the start of
   // the body falls on the next line.
-  Token LastNonCommentToken;
-  for (Token T : Tokens) {
-if (!T.is(tok::comment)) {
-  LastNonCommentToken = T;
-}
-  }
-  InsertLoc = LastNonCommentToken.getEndLoc();
   ReplacementText = " override";
+  auto LastTokenIter = std::prev(Tokens.end());
+  // When try statement is used instead of compound statement as
+  // method body - insert override keyword before it.
+  if (LastTokenIter->is(tok::kw_try))
+LastTokenIter = std::prev(LastTokenIter);
+  InsertLoc = LastTokenIter->getEndLoc();
 }
 
 if (!InsertLoc.isValid()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29778: Declare lgamma library builtins as never being const

2017-02-15 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: include/clang/Basic/Builtins.def:1091
+LIBBUILTIN(lgammaf, "ff", "fn", "math.h", ALL_LANGUAGES)
+LIBBUILTIN(lgammal, "LdLd", "fn", "math.h", ALL_LANGUAGES)
 

Please add a comment explaining why this doesn't have an "e" marking.


https://reviews.llvm.org/D29778



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


Re: r295149 - Fix assertion failure due to implicit special member lookup lacking a source location.

2017-02-15 Thread Hans Wennborg via cfe-commits
IIUC, this is a follow-up to r291955, which was merged to 4.0. Should
this one be merged also?

Cheers,
Hans

On Tue, Feb 14, 2017 at 8:18 PM, Richard Smith via cfe-commits
 wrote:
> Author: rsmith
> Date: Tue Feb 14 22:18:23 2017
> New Revision: 295149
>
> URL: http://llvm.org/viewvc/llvm-project?rev=295149&view=rev
> Log:
> Fix assertion failure due to implicit special member lookup lacking a source 
> location.
>
> Modified:
> cfe/trunk/lib/Sema/SemaLookup.cpp
> cfe/trunk/test/SemaCXX/cxx11-inheriting-ctors.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=295149&r1=295148&r2=295149&view=diff
> ==
> --- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue Feb 14 22:18:23 2017
> @@ -2838,6 +2838,9 @@ Sema::SpecialMemberOverloadResult *Sema:
>  assert((SM != CXXDefaultConstructor && SM != CXXDestructor) &&
> "parameter-less special members can't have qualified arguments");
>
> +  // FIXME: Get the caller to pass in a location for the lookup.
> +  SourceLocation LookupLoc = RD->getLocation();
> +
>llvm::FoldingSetNodeID ID;
>ID.AddPointer(RD);
>ID.AddInteger(SM);
> @@ -2919,7 +2922,7 @@ Sema::SpecialMemberOverloadResult *Sema:
>VK = VK_RValue;
>}
>
> -  OpaqueValueExpr FakeArg(SourceLocation(), ArgType, VK);
> +  OpaqueValueExpr FakeArg(LookupLoc, ArgType, VK);
>
>if (SM != CXXDefaultConstructor) {
>  NumArgs = 1;
> @@ -2933,13 +2936,13 @@ Sema::SpecialMemberOverloadResult *Sema:
>if (VolatileThis)
>  ThisTy.addVolatile();
>Expr::Classification Classification =
> -OpaqueValueExpr(SourceLocation(), ThisTy,
> +OpaqueValueExpr(LookupLoc, ThisTy,
>  RValueThis ? VK_RValue : VK_LValue).Classify(Context);
>
>// Now we perform lookup on the name we computed earlier and do overload
>// resolution. Lookup is only performed directly into the class since there
>// will always be a (possibly implicit) declaration to shadow any others.
> -  OverloadCandidateSet OCS(RD->getLocation(), 
> OverloadCandidateSet::CSK_Normal);
> +  OverloadCandidateSet OCS(LookupLoc, OverloadCandidateSet::CSK_Normal);
>DeclContext::lookup_result R = RD->lookup(Name);
>
>if (R.empty()) {
> @@ -2994,7 +2997,7 @@ Sema::SpecialMemberOverloadResult *Sema:
>}
>
>OverloadCandidateSet::iterator Best;
> -  switch (OCS.BestViableFunction(*this, SourceLocation(), Best)) {
> +  switch (OCS.BestViableFunction(*this, LookupLoc, Best)) {
>  case OR_Success:
>Result->setMethod(cast(Best->Function));
>Result->setKind(SpecialMemberOverloadResult::Success);
>
> Modified: cfe/trunk/test/SemaCXX/cxx11-inheriting-ctors.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx11-inheriting-ctors.cpp?rev=295149&r1=295148&r2=295149&view=diff
> ==
> --- cfe/trunk/test/SemaCXX/cxx11-inheriting-ctors.cpp (original)
> +++ cfe/trunk/test/SemaCXX/cxx11-inheriting-ctors.cpp Tue Feb 14 22:18:23 2017
> @@ -105,3 +105,31 @@ namespace PR31606 {
>// Note, we do *not* allow operator=='s argument to use the inherited 
> A::A(Base&&) constructor to construct from B{}.
>bool b = A{} == B{}; // expected-error {{invalid operands}}
>  }
> +
> +namespace implicit_member_srcloc {
> +  template
> +  struct S3 {
> +  };
> +
> +  template
> +  struct S2 {
> +S2(S3 &&);
> +  };
> +
> +  template
> +  struct S1 : S2 {
> +using S2::S2;
> +S1();
> +  };
> +
> +  template
> +  struct S0 {
> +S0();
> +S0(S0&&) = default;
> +S1 m1;
> +  };
> +
> +  void foo1() {
> +S0 s0;
> +  }
> +}
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29886: [clangd] Wire up ASTUnit and publish diagnostics with it.

2017-02-15 Thread Aleksey Shlyapnikov via Phabricator via cfe-commits
alekseyshl added a comment.

http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/2437 is 
broken by this revision.


Repository:
  rL LLVM

https://reviews.llvm.org/D29886



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


Re: r295150 - [Sema] Disallow returning a __block variable via a move.

2017-02-15 Thread Akira Hatanaka via cfe-commits
Hans,

Can this be merged to 4.0 too?

> On Feb 14, 2017, at 9:15 PM, Akira Hatanaka via cfe-commits 
>  wrote:
> 
> Author: ahatanak
> Date: Tue Feb 14 23:15:28 2017
> New Revision: 295150
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=295150&view=rev
> Log:
> [Sema] Disallow returning a __block variable via a move.
> 
> r274291 made changes to prefer calling a move constructor to calling a
> copy constructor when returning from a function. This caused programs to
> crash when a __block variable in the heap was moved out and used later.
> 
> This commit fixes the bug by disallowing moving out of __block variables
> implicitly.
> 
> rdar://problem/28181080
> 
> Differential Revision: https://reviews.llvm.org/D29908
> 
> Modified:
>cfe/trunk/lib/Sema/SemaStmt.cpp
>cfe/trunk/test/SemaObjCXX/blocks.mm
> 
> Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=295150&r1=295149&r2=295150&view=diff
> ==
> --- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaStmt.cpp Tue Feb 14 23:15:28 2017
> @@ -2743,15 +2743,17 @@ bool Sema::isCopyElisionCandidate(QualTy
>   // ...automatic...
>   if (!VD->hasLocalStorage()) return false;
> 
> +  // Return false if VD is a __block variable. We don't want to implicitly 
> move
> +  // out of a __block variable during a return because we cannot assume the
> +  // variable will no longer be used.
> +  if (VD->hasAttr()) return false;
> +
>   if (AllowParamOrMoveConstructible)
> return true;
> 
>   // ...non-volatile...
>   if (VD->getType().isVolatileQualified()) return false;
> 
> -  // __block variables can't be allocated in a way that permits NRVO.
> -  if (VD->hasAttr()) return false;
> -
>   // Variables with higher required alignment than their type's ABI
>   // alignment cannot use NRVO.
>   if (!VD->getType()->isDependentType() && VD->hasAttr() &&
> 
> Modified: cfe/trunk/test/SemaObjCXX/blocks.mm
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/blocks.mm?rev=295150&r1=295149&r2=295150&view=diff
> ==
> --- cfe/trunk/test/SemaObjCXX/blocks.mm (original)
> +++ cfe/trunk/test/SemaObjCXX/blocks.mm Tue Feb 14 23:15:28 2017
> @@ -1,4 +1,4 @@
> -// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -Wno-objc-root-class %s
> +// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -Wno-objc-root-class 
> -std=c++11 %s
> @protocol NSObject;
> 
> void bar(id(^)(void));
> @@ -144,3 +144,17 @@ namespace DependentReturn {
> 
>   template void f(X);
> }
> +
> +namespace MoveBlockVariable {
> +struct B0 {
> +};
> +
> +struct B1 { // expected-note 2 {{candidate constructor (the implicit}}
> +  B1(B0&&); // expected-note {{candidate constructor not viable}}
> +};
> +
> +B1 test_move() {
> +  __block B0 b;
> +  return b; // expected-error {{no viable conversion from returned value of 
> type 'MoveBlockVariable::B0' to function return type 'MoveBlockVariable::B1'}}
> +}
> +}
> 
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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


[PATCH] D30000: Fix for pr31836 - pp_nonportable_path on absolute paths: broken delimiters

2017-02-15 Thread Taewook Oh via Phabricator via cfe-commits
twoh updated this revision to Diff 88584.
twoh added a comment.

Make it explicit that the test doesn't support windows. @eric_niebler, my 
original intention was avoiding use of platform-dependent path separator, but 
now made it explicit that the test is not for windows, it should be okay to use 
'/'. Thanks for the comments!


https://reviews.llvm.org/D3

Files:
  lib/Lex/PPDirectives.cpp
  test/Lexer/case-insensitive-include-pr31836.sh


Index: test/Lexer/case-insensitive-include-pr31836.sh
===
--- /dev/null
+++ test/Lexer/case-insensitive-include-pr31836.sh
@@ -0,0 +1,9 @@
+// REQUIRES: case-insensitive-filesystem
+// UNSUPPORTED: system-windows
+
+// RUN: mkdir -p %T
+// RUN: touch %T/case-insensitive-include-pr31836.h
+// RUN: echo "#include \"%T/Case-Insensitive-Include-Pr31836.h\"" | %clang_cc1 
-E - 2>&1 | FileCheck %s
+
+// CHECK: warning: non-portable path to file
+// CHECK-SAME: /case-insensitive-include-pr31836.h
Index: lib/Lex/PPDirectives.cpp
===
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -1976,8 +1976,12 @@
   SmallString<128> Path;
   Path.reserve(Name.size()+2);
   Path.push_back(isAngled ? '<' : '"');
+  bool isLeadingSeparator = llvm::sys::path::is_absolute(Name);
   for (auto Component : Components) {
-Path.append(Component);
+if (isLeadingSeparator)
+  isLeadingSeparator = false;
+else
+  Path.append(Component);
 // Append the separator the user used, or the close quote
 Path.push_back(
   Path.size() <= Filename.size() ? Filename[Path.size()-1] :


Index: test/Lexer/case-insensitive-include-pr31836.sh
===
--- /dev/null
+++ test/Lexer/case-insensitive-include-pr31836.sh
@@ -0,0 +1,9 @@
+// REQUIRES: case-insensitive-filesystem
+// UNSUPPORTED: system-windows
+
+// RUN: mkdir -p %T
+// RUN: touch %T/case-insensitive-include-pr31836.h
+// RUN: echo "#include \"%T/Case-Insensitive-Include-Pr31836.h\"" | %clang_cc1 -E - 2>&1 | FileCheck %s
+
+// CHECK: warning: non-portable path to file
+// CHECK-SAME: /case-insensitive-include-pr31836.h
Index: lib/Lex/PPDirectives.cpp
===
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -1976,8 +1976,12 @@
   SmallString<128> Path;
   Path.reserve(Name.size()+2);
   Path.push_back(isAngled ? '<' : '"');
+  bool isLeadingSeparator = llvm::sys::path::is_absolute(Name);
   for (auto Component : Components) {
-Path.append(Component);
+if (isLeadingSeparator)
+  isLeadingSeparator = false;
+else
+  Path.append(Component);
 // Append the separator the user used, or the close quote
 Path.push_back(
   Path.size() <= Filename.size() ? Filename[Path.size()-1] :
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r295150 - [Sema] Disallow returning a __block variable via a move.

2017-02-15 Thread Hans Wennborg via cfe-commits
+Richard for risk/reward analysis.

r274291 was also in 3.9, so this isn't strictly speaking a regression.

On Wed, Feb 15, 2017 at 11:43 AM, Akira Hatanaka  wrote:
> Hans,
>
> Can this be merged to 4.0 too?
>
>> On Feb 14, 2017, at 9:15 PM, Akira Hatanaka via cfe-commits 
>>  wrote:
>>
>> Author: ahatanak
>> Date: Tue Feb 14 23:15:28 2017
>> New Revision: 295150
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=295150&view=rev
>> Log:
>> [Sema] Disallow returning a __block variable via a move.
>>
>> r274291 made changes to prefer calling a move constructor to calling a
>> copy constructor when returning from a function. This caused programs to
>> crash when a __block variable in the heap was moved out and used later.
>>
>> This commit fixes the bug by disallowing moving out of __block variables
>> implicitly.
>>
>> rdar://problem/28181080
>>
>> Differential Revision: https://reviews.llvm.org/D29908
>>
>> Modified:
>>cfe/trunk/lib/Sema/SemaStmt.cpp
>>cfe/trunk/test/SemaObjCXX/blocks.mm
>>
>> Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=295150&r1=295149&r2=295150&view=diff
>> ==
>> --- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaStmt.cpp Tue Feb 14 23:15:28 2017
>> @@ -2743,15 +2743,17 @@ bool Sema::isCopyElisionCandidate(QualTy
>>   // ...automatic...
>>   if (!VD->hasLocalStorage()) return false;
>>
>> +  // Return false if VD is a __block variable. We don't want to implicitly 
>> move
>> +  // out of a __block variable during a return because we cannot assume the
>> +  // variable will no longer be used.
>> +  if (VD->hasAttr()) return false;
>> +
>>   if (AllowParamOrMoveConstructible)
>> return true;
>>
>>   // ...non-volatile...
>>   if (VD->getType().isVolatileQualified()) return false;
>>
>> -  // __block variables can't be allocated in a way that permits NRVO.
>> -  if (VD->hasAttr()) return false;
>> -
>>   // Variables with higher required alignment than their type's ABI
>>   // alignment cannot use NRVO.
>>   if (!VD->getType()->isDependentType() && VD->hasAttr() &&
>>
>> Modified: cfe/trunk/test/SemaObjCXX/blocks.mm
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/blocks.mm?rev=295150&r1=295149&r2=295150&view=diff
>> ==
>> --- cfe/trunk/test/SemaObjCXX/blocks.mm (original)
>> +++ cfe/trunk/test/SemaObjCXX/blocks.mm Tue Feb 14 23:15:28 2017
>> @@ -1,4 +1,4 @@
>> -// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -Wno-objc-root-class %s
>> +// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -Wno-objc-root-class 
>> -std=c++11 %s
>> @protocol NSObject;
>>
>> void bar(id(^)(void));
>> @@ -144,3 +144,17 @@ namespace DependentReturn {
>>
>>   template void f(X);
>> }
>> +
>> +namespace MoveBlockVariable {
>> +struct B0 {
>> +};
>> +
>> +struct B1 { // expected-note 2 {{candidate constructor (the implicit}}
>> +  B1(B0&&); // expected-note {{candidate constructor not viable}}
>> +};
>> +
>> +B1 test_move() {
>> +  __block B0 b;
>> +  return b; // expected-error {{no viable conversion from returned value of 
>> type 'MoveBlockVariable::B0' to function return type 
>> 'MoveBlockVariable::B1'}}
>> +}
>> +}
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r295224 - PR24440: Do not silently discard a fold-expression appearing as the operand of a cast-expression.

2017-02-15 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed Feb 15 13:57:10 2017
New Revision: 295224

URL: http://llvm.org/viewvc/llvm-project?rev=295224&view=rev
Log:
PR24440: Do not silently discard a fold-expression appearing as the operand of 
a cast-expression.

Modified:
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
cfe/trunk/test/Parser/cxx1z-fold-expressions.cpp

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=295224&r1=295223&r2=295224&view=diff
==
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Wed Feb 15 13:57:10 2017
@@ -2409,7 +2409,7 @@ Parser::ParseParenExpression(ParenParseO
   // fold-expressions, we'll need to allow multiple ArgExprs here.
   if (ArgExprs.size() == 1 && isFoldOperator(Tok.getKind()) &&
   NextToken().is(tok::ellipsis))
-return ParseFoldExpression(Result, T);
+return ParseFoldExpression(ArgExprs[0], T);
 
   ExprType = SimpleExpr;
   Result = Actions.ActOnParenListExpr(OpenLoc, Tok.getLocation(),

Modified: cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp?rev=295224&r1=295223&r2=295224&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp Wed Feb 15 13:57:10 2017
@@ -1015,6 +1015,11 @@ ExprResult Sema::ActOnCXXFoldExpr(Source
   CheckFoldOperand(*this, LHS);
   CheckFoldOperand(*this, RHS);
 
+  auto DiscardOperands = [&] {
+CorrectDelayedTyposInExpr(LHS);
+CorrectDelayedTyposInExpr(RHS);
+  };
+
   // [expr.prim.fold]p3:
   //   In a binary fold, op1 and op2 shall be the same fold-operator, and
   //   either e1 shall contain an unexpanded parameter pack or e2 shall contain
@@ -1022,6 +1027,7 @@ ExprResult Sema::ActOnCXXFoldExpr(Source
   if (LHS && RHS &&
   LHS->containsUnexpandedParameterPack() ==
   RHS->containsUnexpandedParameterPack()) {
+DiscardOperands();
 return Diag(EllipsisLoc,
 LHS->containsUnexpandedParameterPack()
 ? diag::err_fold_expression_packs_both_sides
@@ -1035,6 +1041,7 @@ ExprResult Sema::ActOnCXXFoldExpr(Source
   if (!LHS || !RHS) {
 Expr *Pack = LHS ? LHS : RHS;
 assert(Pack && "fold expression with neither LHS nor RHS");
+DiscardOperands();
 if (!Pack->containsUnexpandedParameterPack())
   return Diag(EllipsisLoc, 
diag::err_pack_expansion_without_parameter_packs)
  << Pack->getSourceRange();

Modified: cfe/trunk/test/Parser/cxx1z-fold-expressions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx1z-fold-expressions.cpp?rev=295224&r1=295223&r2=295224&view=diff
==
--- cfe/trunk/test/Parser/cxx1z-fold-expressions.cpp (original)
+++ cfe/trunk/test/Parser/cxx1z-fold-expressions.cpp Wed Feb 15 13:57:10 2017
@@ -34,3 +34,12 @@ template int bad9() { return (
 template int bad10() { return (3 ? ... : N); } // expected-error 
+{{}} expected-note {{to match}}
 template int bad11() { return (N + ... 0); } // expected-error 
{{expected a foldable binary operator}} expected-error {{expected expression}}
 template int bad12() { return (... N); } // expected-error 
{{expected expression}}
+
+template void as_operand_of_cast(int a, T ...t) {
+  return
+(int)(a + ... + undeclared_junk) + // expected-error {{undeclared}} 
expected-error {{does not contain any unexpanded}}
+(int)(t + ... + undeclared_junk) + // expected-error {{undeclared}}
+(int)(... + undeclared_junk) + // expected-error {{undeclared}} 
expected-error {{does not contain any unexpanded}}
+(int)(undeclared_junk + ...) + // expected-error {{undeclared}}
+(int)(a + ...); // expected-error {{does not contain any unexpanded}}
+}


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


Re: r295149 - Fix assertion failure due to implicit special member lookup lacking a source location.

2017-02-15 Thread Richard Smith via cfe-commits
On 15 February 2017 at 11:39, Hans Wennborg  wrote:

> IIUC, this is a follow-up to r291955, which was merged to 4.0. Should
> this one be merged also?
>

Yes, please.


> Cheers,
> Hans
>
> On Tue, Feb 14, 2017 at 8:18 PM, Richard Smith via cfe-commits
>  wrote:
> > Author: rsmith
> > Date: Tue Feb 14 22:18:23 2017
> > New Revision: 295149
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=295149&view=rev
> > Log:
> > Fix assertion failure due to implicit special member lookup lacking a
> source location.
> >
> > Modified:
> > cfe/trunk/lib/Sema/SemaLookup.cpp
> > cfe/trunk/test/SemaCXX/cxx11-inheriting-ctors.cpp
> >
> > Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaLookup.cpp?rev=295149&r1=295148&r2=295149&view=diff
> > 
> ==
> > --- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
> > +++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue Feb 14 22:18:23 2017
> > @@ -2838,6 +2838,9 @@ Sema::SpecialMemberOverloadResult *Sema:
> >  assert((SM != CXXDefaultConstructor && SM != CXXDestructor) &&
> > "parameter-less special members can't have qualified
> arguments");
> >
> > +  // FIXME: Get the caller to pass in a location for the lookup.
> > +  SourceLocation LookupLoc = RD->getLocation();
> > +
> >llvm::FoldingSetNodeID ID;
> >ID.AddPointer(RD);
> >ID.AddInteger(SM);
> > @@ -2919,7 +2922,7 @@ Sema::SpecialMemberOverloadResult *Sema:
> >VK = VK_RValue;
> >}
> >
> > -  OpaqueValueExpr FakeArg(SourceLocation(), ArgType, VK);
> > +  OpaqueValueExpr FakeArg(LookupLoc, ArgType, VK);
> >
> >if (SM != CXXDefaultConstructor) {
> >  NumArgs = 1;
> > @@ -2933,13 +2936,13 @@ Sema::SpecialMemberOverloadResult *Sema:
> >if (VolatileThis)
> >  ThisTy.addVolatile();
> >Expr::Classification Classification =
> > -OpaqueValueExpr(SourceLocation(), ThisTy,
> > +OpaqueValueExpr(LookupLoc, ThisTy,
> >  RValueThis ? VK_RValue :
> VK_LValue).Classify(Context);
> >
> >// Now we perform lookup on the name we computed earlier and do
> overload
> >// resolution. Lookup is only performed directly into the class since
> there
> >// will always be a (possibly implicit) declaration to shadow any
> others.
> > -  OverloadCandidateSet OCS(RD->getLocation(), OverloadCandidateSet::CSK_
> Normal);
> > +  OverloadCandidateSet OCS(LookupLoc, OverloadCandidateSet::CSK_
> Normal);
> >DeclContext::lookup_result R = RD->lookup(Name);
> >
> >if (R.empty()) {
> > @@ -2994,7 +2997,7 @@ Sema::SpecialMemberOverloadResult *Sema:
> >}
> >
> >OverloadCandidateSet::iterator Best;
> > -  switch (OCS.BestViableFunction(*this, SourceLocation(), Best)) {
> > +  switch (OCS.BestViableFunction(*this, LookupLoc, Best)) {
> >  case OR_Success:
> >Result->setMethod(cast(Best->Function));
> >Result->setKind(SpecialMemberOverloadResult::Success);
> >
> > Modified: cfe/trunk/test/SemaCXX/cxx11-inheriting-ctors.cpp
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> SemaCXX/cxx11-inheriting-ctors.cpp?rev=295149&r1=
> 295148&r2=295149&view=diff
> > 
> ==
> > --- cfe/trunk/test/SemaCXX/cxx11-inheriting-ctors.cpp (original)
> > +++ cfe/trunk/test/SemaCXX/cxx11-inheriting-ctors.cpp Tue Feb 14
> 22:18:23 2017
> > @@ -105,3 +105,31 @@ namespace PR31606 {
> >// Note, we do *not* allow operator=='s argument to use the inherited
> A::A(Base&&) constructor to construct from B{}.
> >bool b = A{} == B{}; // expected-error {{invalid operands}}
> >  }
> > +
> > +namespace implicit_member_srcloc {
> > +  template
> > +  struct S3 {
> > +  };
> > +
> > +  template
> > +  struct S2 {
> > +S2(S3 &&);
> > +  };
> > +
> > +  template
> > +  struct S1 : S2 {
> > +using S2::S2;
> > +S1();
> > +  };
> > +
> > +  template
> > +  struct S0 {
> > +S0();
> > +S0(S0&&) = default;
> > +S1 m1;
> > +  };
> > +
> > +  void foo1() {
> > +S0 s0;
> > +  }
> > +}
> >
> >
> > ___
> > cfe-commits mailing list
> > cfe-commits@lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r295224 - PR24440: Do not silently discard a fold-expression appearing as the operand of a cast-expression.

2017-02-15 Thread Richard Smith via cfe-commits
Hans, this would be a good candidate for Clang 4. The bug in question is
not a regression, but it is an accepts-invalid / wrong-code bug.

On 15 February 2017 at 11:57, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rsmith
> Date: Wed Feb 15 13:57:10 2017
> New Revision: 295224
>
> URL: http://llvm.org/viewvc/llvm-project?rev=295224&view=rev
> Log:
> PR24440: Do not silently discard a fold-expression appearing as the
> operand of a cast-expression.
>
> Modified:
> cfe/trunk/lib/Parse/ParseExpr.cpp
> cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
> cfe/trunk/test/Parser/cxx1z-fold-expressions.cpp
>
> Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/
> ParseExpr.cpp?rev=295224&r1=295223&r2=295224&view=diff
> 
> ==
> --- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseExpr.cpp Wed Feb 15 13:57:10 2017
> @@ -2409,7 +2409,7 @@ Parser::ParseParenExpression(ParenParseO
>// fold-expressions, we'll need to allow multiple ArgExprs here.
>if (ArgExprs.size() == 1 && isFoldOperator(Tok.getKind()) &&
>NextToken().is(tok::ellipsis))
> -return ParseFoldExpression(Result, T);
> +return ParseFoldExpression(ArgExprs[0], T);
>
>ExprType = SimpleExpr;
>Result = Actions.ActOnParenListExpr(OpenLoc, Tok.getLocation(),
>
> Modified: cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaTemplateVariadic.cpp?rev=295224&r1=295223&r2=295224&view=diff
> 
> ==
> --- cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp Wed Feb 15 13:57:10 2017
> @@ -1015,6 +1015,11 @@ ExprResult Sema::ActOnCXXFoldExpr(Source
>CheckFoldOperand(*this, LHS);
>CheckFoldOperand(*this, RHS);
>
> +  auto DiscardOperands = [&] {
> +CorrectDelayedTyposInExpr(LHS);
> +CorrectDelayedTyposInExpr(RHS);
> +  };
> +
>// [expr.prim.fold]p3:
>//   In a binary fold, op1 and op2 shall be the same fold-operator, and
>//   either e1 shall contain an unexpanded parameter pack or e2 shall
> contain
> @@ -1022,6 +1027,7 @@ ExprResult Sema::ActOnCXXFoldExpr(Source
>if (LHS && RHS &&
>LHS->containsUnexpandedParameterPack() ==
>RHS->containsUnexpandedParameterPack()) {
> +DiscardOperands();
>  return Diag(EllipsisLoc,
>  LHS->containsUnexpandedParameterPack()
>  ? diag::err_fold_expression_packs_both_sides
> @@ -1035,6 +1041,7 @@ ExprResult Sema::ActOnCXXFoldExpr(Source
>if (!LHS || !RHS) {
>  Expr *Pack = LHS ? LHS : RHS;
>  assert(Pack && "fold expression with neither LHS nor RHS");
> +DiscardOperands();
>  if (!Pack->containsUnexpandedParameterPack())
>return Diag(EllipsisLoc, diag::err_pack_expansion_
> without_parameter_packs)
>   << Pack->getSourceRange();
>
> Modified: cfe/trunk/test/Parser/cxx1z-fold-expressions.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/
> cxx1z-fold-expressions.cpp?rev=295224&r1=295223&r2=295224&view=diff
> 
> ==
> --- cfe/trunk/test/Parser/cxx1z-fold-expressions.cpp (original)
> +++ cfe/trunk/test/Parser/cxx1z-fold-expressions.cpp Wed Feb 15 13:57:10
> 2017
> @@ -34,3 +34,12 @@ template int bad9() { return (
>  template int bad10() { return (3 ? ... : N); } //
> expected-error +{{}} expected-note {{to match}}
>  template int bad11() { return (N + ... 0); } // expected-error
> {{expected a foldable binary operator}} expected-error {{expected
> expression}}
>  template int bad12() { return (... N); } // expected-error
> {{expected expression}}
> +
> +template void as_operand_of_cast(int a, T ...t) {
> +  return
> +(int)(a + ... + undeclared_junk) + // expected-error {{undeclared}}
> expected-error {{does not contain any unexpanded}}
> +(int)(t + ... + undeclared_junk) + // expected-error {{undeclared}}
> +(int)(... + undeclared_junk) + // expected-error {{undeclared}}
> expected-error {{does not contain any unexpanded}}
> +(int)(undeclared_junk + ...) + // expected-error {{undeclared}}
> +(int)(a + ...); // expected-error {{does not contain any unexpanded}}
> +}
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r295150 - [Sema] Disallow returning a __block variable via a move.

2017-02-15 Thread Richard Smith via cfe-commits
On 15 February 2017 at 11:50, Hans Wennborg  wrote:

> +Richard for risk/reward analysis.
>

This is an extremely safe change, and fixes what amounts to a subtle
miscompile. I think we should take it.


> r274291 was also in 3.9, so this isn't strictly speaking a regression.
>
> On Wed, Feb 15, 2017 at 11:43 AM, Akira Hatanaka 
> wrote:
> > Hans,
> >
> > Can this be merged to 4.0 too?
> >
> >> On Feb 14, 2017, at 9:15 PM, Akira Hatanaka via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> >>
> >> Author: ahatanak
> >> Date: Tue Feb 14 23:15:28 2017
> >> New Revision: 295150
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=295150&view=rev
> >> Log:
> >> [Sema] Disallow returning a __block variable via a move.
> >>
> >> r274291 made changes to prefer calling a move constructor to calling a
> >> copy constructor when returning from a function. This caused programs to
> >> crash when a __block variable in the heap was moved out and used later.
> >>
> >> This commit fixes the bug by disallowing moving out of __block variables
> >> implicitly.
> >>
> >> rdar://problem/28181080
> >>
> >> Differential Revision: https://reviews.llvm.org/D29908
> >>
> >> Modified:
> >>cfe/trunk/lib/Sema/SemaStmt.cpp
> >>cfe/trunk/test/SemaObjCXX/blocks.mm
> >>
> >> Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
> >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaStmt.cpp?rev=295150&r1=295149&r2=295150&view=diff
> >> 
> ==
> >> --- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
> >> +++ cfe/trunk/lib/Sema/SemaStmt.cpp Tue Feb 14 23:15:28 2017
> >> @@ -2743,15 +2743,17 @@ bool Sema::isCopyElisionCandidate(QualTy
> >>   // ...automatic...
> >>   if (!VD->hasLocalStorage()) return false;
> >>
> >> +  // Return false if VD is a __block variable. We don't want to
> implicitly move
> >> +  // out of a __block variable during a return because we cannot
> assume the
> >> +  // variable will no longer be used.
> >> +  if (VD->hasAttr()) return false;
> >> +
> >>   if (AllowParamOrMoveConstructible)
> >> return true;
> >>
> >>   // ...non-volatile...
> >>   if (VD->getType().isVolatileQualified()) return false;
> >>
> >> -  // __block variables can't be allocated in a way that permits NRVO.
> >> -  if (VD->hasAttr()) return false;
> >> -
> >>   // Variables with higher required alignment than their type's ABI
> >>   // alignment cannot use NRVO.
> >>   if (!VD->getType()->isDependentType() && VD->hasAttr()
> &&
> >>
> >> Modified: cfe/trunk/test/SemaObjCXX/blocks.mm
> >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> SemaObjCXX/blocks.mm?rev=295150&r1=295149&r2=295150&view=diff
> >> 
> ==
> >> --- cfe/trunk/test/SemaObjCXX/blocks.mm (original)
> >> +++ cfe/trunk/test/SemaObjCXX/blocks.mm Tue Feb 14 23:15:28 2017
> >> @@ -1,4 +1,4 @@
> >> -// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -Wno-objc-root-class
> %s
> >> +// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -Wno-objc-root-class
> -std=c++11 %s
> >> @protocol NSObject;
> >>
> >> void bar(id(^)(void));
> >> @@ -144,3 +144,17 @@ namespace DependentReturn {
> >>
> >>   template void f(X);
> >> }
> >> +
> >> +namespace MoveBlockVariable {
> >> +struct B0 {
> >> +};
> >> +
> >> +struct B1 { // expected-note 2 {{candidate constructor (the implicit}}
> >> +  B1(B0&&); // expected-note {{candidate constructor not viable}}
> >> +};
> >> +
> >> +B1 test_move() {
> >> +  __block B0 b;
> >> +  return b; // expected-error {{no viable conversion from returned
> value of type 'MoveBlockVariable::B0' to function return type
> 'MoveBlockVariable::B1'}}
> >> +}
> >> +}
> >>
> >>
> >> ___
> >> cfe-commits mailing list
> >> cfe-commits@lists.llvm.org
> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
> >
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r295149 - Fix assertion failure due to implicit special member lookup lacking a source location.

2017-02-15 Thread Hans Wennborg via cfe-commits
On Wed, Feb 15, 2017 at 12:14 PM, Richard Smith  wrote:
> On 15 February 2017 at 11:39, Hans Wennborg  wrote:
>>
>> IIUC, this is a follow-up to r291955, which was merged to 4.0. Should
>> this one be merged also?
>
>
> Yes, please.

r295233.

>
>>
>> Cheers,
>> Hans
>>
>> On Tue, Feb 14, 2017 at 8:18 PM, Richard Smith via cfe-commits
>>  wrote:
>> > Author: rsmith
>> > Date: Tue Feb 14 22:18:23 2017
>> > New Revision: 295149
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=295149&view=rev
>> > Log:
>> > Fix assertion failure due to implicit special member lookup lacking a
>> > source location.
>> >
>> > Modified:
>> > cfe/trunk/lib/Sema/SemaLookup.cpp
>> > cfe/trunk/test/SemaCXX/cxx11-inheriting-ctors.cpp
>> >
>> > Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=295149&r1=295148&r2=295149&view=diff
>> >
>> > ==
>> > --- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
>> > +++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue Feb 14 22:18:23 2017
>> > @@ -2838,6 +2838,9 @@ Sema::SpecialMemberOverloadResult *Sema:
>> >  assert((SM != CXXDefaultConstructor && SM != CXXDestructor) &&
>> > "parameter-less special members can't have qualified
>> > arguments");
>> >
>> > +  // FIXME: Get the caller to pass in a location for the lookup.
>> > +  SourceLocation LookupLoc = RD->getLocation();
>> > +
>> >llvm::FoldingSetNodeID ID;
>> >ID.AddPointer(RD);
>> >ID.AddInteger(SM);
>> > @@ -2919,7 +2922,7 @@ Sema::SpecialMemberOverloadResult *Sema:
>> >VK = VK_RValue;
>> >}
>> >
>> > -  OpaqueValueExpr FakeArg(SourceLocation(), ArgType, VK);
>> > +  OpaqueValueExpr FakeArg(LookupLoc, ArgType, VK);
>> >
>> >if (SM != CXXDefaultConstructor) {
>> >  NumArgs = 1;
>> > @@ -2933,13 +2936,13 @@ Sema::SpecialMemberOverloadResult *Sema:
>> >if (VolatileThis)
>> >  ThisTy.addVolatile();
>> >Expr::Classification Classification =
>> > -OpaqueValueExpr(SourceLocation(), ThisTy,
>> > +OpaqueValueExpr(LookupLoc, ThisTy,
>> >  RValueThis ? VK_RValue :
>> > VK_LValue).Classify(Context);
>> >
>> >// Now we perform lookup on the name we computed earlier and do
>> > overload
>> >// resolution. Lookup is only performed directly into the class since
>> > there
>> >// will always be a (possibly implicit) declaration to shadow any
>> > others.
>> > -  OverloadCandidateSet OCS(RD->getLocation(),
>> > OverloadCandidateSet::CSK_Normal);
>> > +  OverloadCandidateSet OCS(LookupLoc,
>> > OverloadCandidateSet::CSK_Normal);
>> >DeclContext::lookup_result R = RD->lookup(Name);
>> >
>> >if (R.empty()) {
>> > @@ -2994,7 +2997,7 @@ Sema::SpecialMemberOverloadResult *Sema:
>> >}
>> >
>> >OverloadCandidateSet::iterator Best;
>> > -  switch (OCS.BestViableFunction(*this, SourceLocation(), Best)) {
>> > +  switch (OCS.BestViableFunction(*this, LookupLoc, Best)) {
>> >  case OR_Success:
>> >Result->setMethod(cast(Best->Function));
>> >Result->setKind(SpecialMemberOverloadResult::Success);
>> >
>> > Modified: cfe/trunk/test/SemaCXX/cxx11-inheriting-ctors.cpp
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx11-inheriting-ctors.cpp?rev=295149&r1=295148&r2=295149&view=diff
>> >
>> > ==
>> > --- cfe/trunk/test/SemaCXX/cxx11-inheriting-ctors.cpp (original)
>> > +++ cfe/trunk/test/SemaCXX/cxx11-inheriting-ctors.cpp Tue Feb 14
>> > 22:18:23 2017
>> > @@ -105,3 +105,31 @@ namespace PR31606 {
>> >// Note, we do *not* allow operator=='s argument to use the inherited
>> > A::A(Base&&) constructor to construct from B{}.
>> >bool b = A{} == B{}; // expected-error {{invalid operands}}
>> >  }
>> > +
>> > +namespace implicit_member_srcloc {
>> > +  template
>> > +  struct S3 {
>> > +  };
>> > +
>> > +  template
>> > +  struct S2 {
>> > +S2(S3 &&);
>> > +  };
>> > +
>> > +  template
>> > +  struct S1 : S2 {
>> > +using S2::S2;
>> > +S1();
>> > +  };
>> > +
>> > +  template
>> > +  struct S0 {
>> > +S0();
>> > +S0(S0&&) = default;
>> > +S1 m1;
>> > +  };
>> > +
>> > +  void foo1() {
>> > +S0 s0;
>> > +  }
>> > +}
>> >
>> >
>> > ___
>> > cfe-commits mailing list
>> > cfe-commits@lists.llvm.org
>> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r295150 - [Sema] Disallow returning a __block variable via a move.

2017-02-15 Thread Hans Wennborg via cfe-commits
On Wed, Feb 15, 2017 at 12:17 PM, Richard Smith  wrote:
> On 15 February 2017 at 11:50, Hans Wennborg  wrote:
>>
>> +Richard for risk/reward analysis.
>
>
> This is an extremely safe change, and fixes what amounts to a subtle
> miscompile. I think we should take it.

Very good; merged in r295234.

>
>>
>> r274291 was also in 3.9, so this isn't strictly speaking a regression.
>>
>> On Wed, Feb 15, 2017 at 11:43 AM, Akira Hatanaka 
>> wrote:
>> > Hans,
>> >
>> > Can this be merged to 4.0 too?
>> >
>> >> On Feb 14, 2017, at 9:15 PM, Akira Hatanaka via cfe-commits
>> >>  wrote:
>> >>
>> >> Author: ahatanak
>> >> Date: Tue Feb 14 23:15:28 2017
>> >> New Revision: 295150
>> >>
>> >> URL: http://llvm.org/viewvc/llvm-project?rev=295150&view=rev
>> >> Log:
>> >> [Sema] Disallow returning a __block variable via a move.
>> >>
>> >> r274291 made changes to prefer calling a move constructor to calling a
>> >> copy constructor when returning from a function. This caused programs
>> >> to
>> >> crash when a __block variable in the heap was moved out and used later.
>> >>
>> >> This commit fixes the bug by disallowing moving out of __block
>> >> variables
>> >> implicitly.
>> >>
>> >> rdar://problem/28181080
>> >>
>> >> Differential Revision: https://reviews.llvm.org/D29908
>> >>
>> >> Modified:
>> >>cfe/trunk/lib/Sema/SemaStmt.cpp
>> >>cfe/trunk/test/SemaObjCXX/blocks.mm
>> >>
>> >> Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
>> >> URL:
>> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=295150&r1=295149&r2=295150&view=diff
>> >>
>> >> ==
>> >> --- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
>> >> +++ cfe/trunk/lib/Sema/SemaStmt.cpp Tue Feb 14 23:15:28 2017
>> >> @@ -2743,15 +2743,17 @@ bool Sema::isCopyElisionCandidate(QualTy
>> >>   // ...automatic...
>> >>   if (!VD->hasLocalStorage()) return false;
>> >>
>> >> +  // Return false if VD is a __block variable. We don't want to
>> >> implicitly move
>> >> +  // out of a __block variable during a return because we cannot
>> >> assume the
>> >> +  // variable will no longer be used.
>> >> +  if (VD->hasAttr()) return false;
>> >> +
>> >>   if (AllowParamOrMoveConstructible)
>> >> return true;
>> >>
>> >>   // ...non-volatile...
>> >>   if (VD->getType().isVolatileQualified()) return false;
>> >>
>> >> -  // __block variables can't be allocated in a way that permits NRVO.
>> >> -  if (VD->hasAttr()) return false;
>> >> -
>> >>   // Variables with higher required alignment than their type's ABI
>> >>   // alignment cannot use NRVO.
>> >>   if (!VD->getType()->isDependentType() && VD->hasAttr()
>> >> &&
>> >>
>> >> Modified: cfe/trunk/test/SemaObjCXX/blocks.mm
>> >> URL:
>> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/blocks.mm?rev=295150&r1=295149&r2=295150&view=diff
>> >>
>> >> ==
>> >> --- cfe/trunk/test/SemaObjCXX/blocks.mm (original)
>> >> +++ cfe/trunk/test/SemaObjCXX/blocks.mm Tue Feb 14 23:15:28 2017
>> >> @@ -1,4 +1,4 @@
>> >> -// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -Wno-objc-root-class
>> >> %s
>> >> +// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -Wno-objc-root-class
>> >> -std=c++11 %s
>> >> @protocol NSObject;
>> >>
>> >> void bar(id(^)(void));
>> >> @@ -144,3 +144,17 @@ namespace DependentReturn {
>> >>
>> >>   template void f(X);
>> >> }
>> >> +
>> >> +namespace MoveBlockVariable {
>> >> +struct B0 {
>> >> +};
>> >> +
>> >> +struct B1 { // expected-note 2 {{candidate constructor (the implicit}}
>> >> +  B1(B0&&); // expected-note {{candidate constructor not viable}}
>> >> +};
>> >> +
>> >> +B1 test_move() {
>> >> +  __block B0 b;
>> >> +  return b; // expected-error {{no viable conversion from returned
>> >> value of type 'MoveBlockVariable::B0' to function return type
>> >> 'MoveBlockVariable::B1'}}
>> >> +}
>> >> +}
>> >>
>> >>
>> >> ___
>> >> cfe-commits mailing list
>> >> cfe-commits@lists.llvm.org
>> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>> >
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Patch for Bug 30413, including test case

2017-02-15 Thread Lobron, David via cfe-commits
Hi All,

I am re-submitting my patch for Bug 30413, this time with a test case included 
as well (ivar-type-encoding.m).  The test case file should be added to 
clang/test/CodeGenObjC.  The test verifies that correct metadata is emitted by 
clang for an object-valued instance variable.  I've verified that the test 
passes when the patch has been applied to ASTContext.cpp, and fails otherwise.

Please let me know if this looks OK, or if any additional information is needed.

Thanks,

David



ivar-type-encoding.m
Description: ivar-type-encoding.m


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


[PATCH] D29599: Clang Changes for alloc_align

2017-02-15 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 88602.
erichkeane added a comment.

I was able to get the templated versions working in response to the discussion 
with Akira.  Note the added test file which shows off all of the combos I could 
think of.

It required a little bit of surgery inside the SemaDeclAttr.cpp, since the 
SemaTemplateInstatiateDecl.cpp no longer has "AttributeList" info anymore, so 
getting the error messages in the existing functions required a little 
template-writing of my own!

I decided to explicitly forbid the following case, because I cannot see a valid 
usecase for this, or for making 'Which' below a dependent value.

  template
  void* foo(int a, int b, int c, int d) __attribute__((alloc_align(Which)));


https://reviews.llvm.org/D29599

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Sema/Sema.h
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/CodeGen/alloc-align-attr.c
  test/Sema/alloc-align-attr.c
  test/SemaCXX/alloc-align-attr.cpp

Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -4225,7 +4225,11 @@
   llvm::ConstantInt *AlignmentCI = cast(Alignment);
   EmitAlignmentAssumption(Ret.getScalarVal(), AlignmentCI->getZExtValue(),
   OffsetValue);
+} else if (const auto *AA = TargetDecl->getAttr()) {
+  llvm::Value *ParamVal = IRCallArgs[AA->getParamIndex() - 1];
+  EmitAlignmentAssumption(Ret.getScalarVal(), ParamVal);
 }
+
   }
 
   return Ret;
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -2412,6 +2412,12 @@
   PeepholeProtection protectFromPeepholes(RValue rvalue);
   void unprotectFromPeepholes(PeepholeProtection protection);
 
+  void EmitAlignmentAssumption(llvm::Value *PtrValue, llvm::Value *Alignment,
+   llvm::Value *OffsetValue = nullptr) {
+Builder.CreateAlignmentAssumption(CGM.getDataLayout(), PtrValue, Alignment,
+  OffsetValue);
+  }
+
   //======//
   // Statement Emission
   //======//
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -168,6 +168,16 @@
 Aligned->getSpellingListIndex());
 }
 
+static void instantiateDependentAllocAlignAttr(
+Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
+const AllocAlignAttr *Align, Decl *New) {
+  Expr *Param = IntegerLiteral::Create(
+  S.getASTContext(), llvm::APInt(64, Align->getParamIndex()),
+  S.getASTContext().UnsignedLongLongTy, Align->getLocation());
+  S.AddAllocAlignAttr(Align->getLocation(), New, Param,
+  Align->getSpellingListIndex());
+}
+
 static Expr *instantiateDependentFunctionAttrCondition(
 Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
 const Attr *A, Expr *OldCond, const Decl *Tmpl, FunctionDecl *New) {
@@ -352,6 +362,12 @@
   continue;
 }
 
+if (const auto *AllocAlign = dyn_cast(TmplAttr)) {
+  instantiateDependentAllocAlignAttr(*this, TemplateArgs, AllocAlign, New);
+  continue;
+}
+
+
 if (const auto *EnableIf = dyn_cast(TmplAttr)) {
   instantiateDependentEnableIfAttr(*this, TemplateArgs, EnableIf, Tmpl,
cast(New));
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -218,21 +218,42 @@
std::greater());
 }
 
+/// \brief A helper function to provide Attribute Location for the Attr types
+/// AND the AttributeList
+template  static typename
+std::enable_if::value, SourceLocation>::type
+getAttrLoc(const AttrInfo& Attr) {
+  return Attr.getLocation();
+}
+static SourceLocation getAttrLoc(const clang::AttributeList& Attr) {
+  return Attr.getLoc();
+}
+/// \brief A helper function to provide Attribute Name for the Attr types
+/// AND the AttributeList
+template  static typename
+std::enable_if::value, const AttrInfo*>::type
+getAttrName(const AttrInfo& Attr) {
+  return &Attr;
+}
+const IdentifierInfo* getAttrName(const clang::AttributeList &Attr) {
+  return Attr.getName();
+}
+
 /// \brief If Expr is a valid integer constant, get the value of the integer
 /// expression and return success or failure. May output an error.
-static bool checkUInt32Argument(Sema &S, const AttributeList &Attr,
-

[PATCH] D30000: Fix for pr31836 - pp_nonportable_path on absolute paths: broken delimiters

2017-02-15 Thread Eric Niebler via Phabricator via cfe-commits
eric_niebler added a comment.

My question was more about whether the code is correct for absolute paths on 
Windows, not about whether this particular test would pass or fail. Have you 
tested an incorrectly-cased absolute path on a Windows machine?


https://reviews.llvm.org/D3



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


[PATCH] D24812: Lit C++11 Compatibility Patch #11

2017-02-15 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: test/CodeGenCXX/static-init.cpp:14
+// CHECK98: @_ZZN5test414useStaticLocalEvE3obj = linkonce_odr global 
%"struct.test4::HasVTable" zeroinitializer, comdat, align 8
+// CHECK11: @_ZZN5test414useStaticLocalEvE3obj = linkonce_odr global { i8** } 
{ i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* 
@_ZTVN5test49HasVTableE, i32 0, inrange i32 0, i32 2) }, comdat, align 8
 

rjmccall wrote:
> Interesting.  It looks to me like the C++11 IR pattern is actually the only 
> one that would've exposed the bug that Reid was fixing in r242704.  Reid, do 
> you agree?
I'm not sure I follow exactly, but I think what's going on here is that, in 
C++11, the implicit default constructor is constexpr. I'm not sure how that 
feeds into what type we choose to use for the global.


https://reviews.llvm.org/D24812



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


[PATCH] D28297: [StaticAnalyzer] Fix crash in CastToStructChecker

2017-02-15 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

Please, make sure future reviews go through cfg-dev list. See 
http://llvm.org/docs/Phabricator.html.


Repository:
  rL LLVM

https://reviews.llvm.org/D28297



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


[PATCH] D28278: [StaticAnalyzer] dont show wrong 'garbage value' warning when there is array index out of bounds

2017-02-15 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

Does the code you added detects array out of bounds cases without false 
positives? Is it an option to just have this checkers produce a more precise 
error message in the specific case.

A lot of work will probably need to be done to implement a proper array out of 
bounds checking and no-one is working on that.


Repository:
  rL LLVM

https://reviews.llvm.org/D28278



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


r295245 - Fix the static build.

2017-02-15 Thread Rafael Espindola via cfe-commits
Author: rafael
Date: Wed Feb 15 16:19:04 2017
New Revision: 295245

URL: http://llvm.org/viewvc/llvm-project?rev=295245&view=rev
Log:
Fix the static build.

Modified:
cfe/trunk/tools/c-index-test/CMakeLists.txt

Modified: cfe/trunk/tools/c-index-test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/CMakeLists.txt?rev=295245&r1=295244&r2=295245&view=diff
==
--- cfe/trunk/tools/c-index-test/CMakeLists.txt (original)
+++ cfe/trunk/tools/c-index-test/CMakeLists.txt Wed Feb 15 16:19:04 2017
@@ -17,6 +17,7 @@ endif()
 if (LLVM_BUILD_STATIC)
   target_link_libraries(c-index-test
 libclang_static
+clangCodeGen
 clangIndex
   )
 else()


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


r295252 - [Modules] Consider enable_if attrs in isSameEntity.

2017-02-15 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Wed Feb 15 16:43:27 2017
New Revision: 295252

URL: http://llvm.org/viewvc/llvm-project?rev=295252&view=rev
Log:
[Modules] Consider enable_if attrs in isSameEntity.

Two functions that differ only in their enable_if attributes are
considered overloads, so we should check for those when we're trying to
figure out if two functions are mergeable.

We need to do the same thing for pass_object_size, as well. Looks like
that'll be a bit less trivial, since we sometimes do these merging
checks before we have pass_object_size attributes available (see the
merge checks in ASTDeclReader::VisitFunctionDecl that happen before we
read parameters, and merge checks in calls to ReadDeclAs<>()).

Added:
cfe/trunk/test/Modules/Inputs/overloadable-attrs/
cfe/trunk/test/Modules/Inputs/overloadable-attrs/a.h
cfe/trunk/test/Modules/Inputs/overloadable-attrs/module.modulemap
cfe/trunk/test/Modules/overloadable-attrs.cpp
Modified:
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=295252&r1=295251&r2=295252&view=diff
==
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Wed Feb 15 16:43:27 2017
@@ -2656,6 +2656,44 @@ static bool isSameTemplateParameterList(
   return true;
 }
 
+/// Determine whether the attributes we can overload on are identical for A and
+/// B. Expects A and B to (otherwise) have the same type.
+static bool hasSameOverloadableAttrs(const FunctionDecl *A,
+ const FunctionDecl *B) {
+  SmallVector AEnableIfs;
+  // Since this is an equality check, we can ignore that enable_if attrs show 
up
+  // in reverse order.
+  for (const auto *EIA : A->specific_attrs())
+AEnableIfs.push_back(EIA);
+
+  SmallVector BEnableIfs;
+  for (const auto *EIA : B->specific_attrs())
+BEnableIfs.push_back(EIA);
+
+  // Two very common cases: either we have 0 enable_if attrs, or we have an
+  // unequal number of enable_if attrs.
+  if (AEnableIfs.empty() && BEnableIfs.empty())
+return true;
+
+  if (AEnableIfs.size() != BEnableIfs.size())
+return false;
+
+  llvm::FoldingSetNodeID Cand1ID, Cand2ID;
+  for (unsigned I = 0, E = AEnableIfs.size(); I != E; ++I) {
+Cand1ID.clear();
+Cand2ID.clear();
+
+AEnableIfs[I]->getCond()->Profile(Cand1ID, A->getASTContext(), true);
+BEnableIfs[I]->getCond()->Profile(Cand2ID, B->getASTContext(), true);
+if (Cand1ID != Cand2ID)
+  return false;
+  }
+
+  // FIXME: This doesn't currently consider pass_object_size attributes, since
+  // we aren't guaranteed that A and B have valid parameter lists yet.
+  return true;
+}
+
 /// \brief Determine whether the two declarations refer to the same entity.
 static bool isSameEntity(NamedDecl *X, NamedDecl *Y) {
   assert(X->getDeclName() == Y->getDeclName() && "Declaration name mismatch!");
@@ -2711,8 +2749,10 @@ static bool isSameEntity(NamedDecl *X, N
 CtorY->getInheritedConstructor().getConstructor()))
 return false;
 }
-return (FuncX->getLinkageInternal() == FuncY->getLinkageInternal()) &&
-  FuncX->getASTContext().hasSameType(FuncX->getType(), FuncY->getType());
+return FuncX->getLinkageInternal() == FuncY->getLinkageInternal() &&
+   FuncX->getASTContext().hasSameType(FuncX->getType(),
+  FuncY->getType()) &&
+   hasSameOverloadableAttrs(FuncX, FuncY);
   }
 
   // Variables with the same type and linkage match.

Added: cfe/trunk/test/Modules/Inputs/overloadable-attrs/a.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/overloadable-attrs/a.h?rev=295252&view=auto
==
--- cfe/trunk/test/Modules/Inputs/overloadable-attrs/a.h (added)
+++ cfe/trunk/test/Modules/Inputs/overloadable-attrs/a.h Wed Feb 15 16:43:27 
2017
@@ -0,0 +1,16 @@
+namespace enable_if_attrs {
+constexpr int fn1() __attribute__((enable_if(0, ""))) { return 0; }
+constexpr int fn1() { return 1; }
+
+constexpr int fn2() { return 1; }
+constexpr int fn2() __attribute__((enable_if(0, ""))) { return 0; }
+
+constexpr int fn3(int i) __attribute__((enable_if(!i, ""))) { return 0; }
+constexpr int fn3(int i) __attribute__((enable_if(i, ""))) { return 1; }
+
+constexpr int fn4(int i) { return 0; }
+constexpr int fn4(int i) __attribute__((enable_if(i, ""))) { return 1; }
+
+constexpr int fn5(int i) __attribute__((enable_if(i, ""))) { return 1; }
+constexpr int fn5(int i) { return 0; }
+}

Added: cfe/trunk/test/Modules/Inputs/overloadable-attrs/module.modulemap
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/overloadable-attrs/module.modulemap?rev=295252&view=auto

[PATCH] D30009: Add support for '#pragma clang attribute'

2017-02-15 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.

This patch adds support for the `#pragma clang attribute` directive that was 
proposed recently at 
http://lists.llvm.org/pipermail/cfe-dev/2017-February/052689.html.

Initially it supports the `annotate`, `require_constant_initialization` and 
`objc_subclassing_restricted` attribute (I added support for the last two to 
verify that only those declarations that are specified in the Attr.td subject 
list can receive the attribute). The attributes are parsed immediately and are 
applied individually to each relevant declaration. The attribute application 
errors aren't reported more than once. The `annotate` attribute, which doesn't 
have the subject list, is applied only to those declarations that can receive 
explicit GNU-style attributes.

Thanks


Repository:
  rL LLVM

https://reviews.llvm.org/D30009

Files:
  docs/LanguageExtensions.rst
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TokenKinds.def
  include/clang/Parse/Parser.h
  include/clang/Sema/AttributeList.h
  include/clang/Sema/Sema.h
  lib/Parse/ParsePragma.cpp
  lib/Parse/ParseStmt.cpp
  lib/Parse/Parser.cpp
  lib/Sema/AttributeList.cpp
  lib/Sema/SemaAttr.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaDeclObjC.cpp
  lib/Sema/SemaObjCProperty.cpp
  test/Parser/pragma-attribute.cpp
  test/Sema/pragma-attribute.c
  test/SemaCXX/pragma-attribute.cpp
  test/SemaObjC/pragma-attribute.m
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -1522,6 +1522,20 @@
   OS << "#endif // CLANG_ATTR_LATE_PARSED_LIST\n\n";
 }
 
+// Emits the SupportsPragmaAttribute property for attributes.
+static void emitClangAttrPragmaAttributeSupportList(RecordKeeper &Records,
+raw_ostream &OS) {
+  OS << "#if defined(CLANG_ATTR_PRAGMA_ATTRIBUTE_SUPPORT_LIST)\n";
+  for (const auto *Attr : Records.getAllDerivedDefinitions("Attr")) {
+if (!Attr->getValueAsBit("SupportsPragmaAttribute"))
+  continue;
+std::vector Spellings = GetFlattenedSpellings(*Attr);
+for (const auto &I : Spellings)
+  OS << ".Case(\"" << I.name() << "\", 1)\n";
+  }
+  OS << "#endif // CLANG_ATTR_PRAGMA_ATTRIBUTE_SUPPORT_LIST\n\n";
+}
+
 template 
 static void forEachUniqueSpelling(const Record &Attr, Fn &&F) {
   std::vector Spellings = GetFlattenedSpellings(Attr);
@@ -2692,9 +2706,13 @@
   return B + "Decl";
 }
 
+static std::string functionNameForCustomAppertainsTo(const Record &Subject) {
+  return "is" + Subject.getName().str();
+}
+
 static std::string GenerateCustomAppertainsTo(const Record &Subject,
   raw_ostream &OS) {
-  std::string FnName = "is" + Subject.getName().str();
+  std::string FnName = functionNameForCustomAppertainsTo(Subject);
 
   // If this code has already been generated, simply return the previous
   // instance of it.
@@ -2779,6 +2797,51 @@
   return FnName;
 }
 
+static void GenerateDefaultAppliesTo(raw_ostream &OS) {
+  OS << "static bool defaultAttributeAppliesTo(Sema &, const Decl *) {\n";
+  OS << "  return true;\n";
+  OS << "}\n\n";
+}
+
+static std::string GenerateAppliesTo(const Record &Attr, raw_ostream &OS) {
+  // If the attribute doesn't support '#pragma clang attribute' or if it doesn't
+  // contain a subjects definition, then use the default appliedTo logic.
+  if (!Attr.getValueAsBit("SupportsPragmaAttribute") ||
+  Attr.isValueUnset("Subjects"))
+return "defaultAttributeAppliesTo";
+
+  const Record *SubjectObj = Attr.getValueAsDef("Subjects");
+  std::vector Subjects = SubjectObj->getValueAsListOfDefs("Subjects");
+
+  // If the list of subjects is empty, it is assumed that the attribute applies
+  // to everything.
+  if (Subjects.empty())
+return "defaultAttributeAppliesTo";
+
+  // Otherwise, generate an appliesTo check specific to this attribute which
+  // checks all of the given subjects against the Decl passed in. Return the
+  // name of that check to the caller.
+  std::string FnName = "check" + Attr.getName().str() + "AttributeAppliesTo";
+  std::stringstream SS;
+  SS << "static bool " << FnName << "(Sema &S, const Decl *D) {\n";
+  SS << "  return ";
+  for (auto I = Subjects.begin(), E = Subjects.end(); I != E; ++I) {
+// If the subject has custom code associated with it, use the function
+// that was generated for GenerateAppertainsTo to check if the declaration
+// is valid.
+if ((*I)->isSubClassOf("SubsetSubject"))
+  SS << functionNameForCustomAppertainsTo(**I) << "(D)";
+else
+  SS << "isa<" << GetSubjectWithSuffix(*I) << ">(D)";
+
+if (I + 1 != E)
+  SS << " || ";
+  }
+  SS << ";\n}\n\n";
+  OS << SS.str();
+  return FnName;
+}
+
 static void Generate

[PATCH] D29967: Get class property selectors from property decl if it exists

2017-02-15 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd requested changes to this revision.
compnerd added a comment.
This revision now requires changes to proceed.

Please add a test for this.




Comment at: lib/Sema/SemaExprObjC.cpp:1989
+  Selector SetterSel;
+  if (ObjCPropertyDecl *PD = IFace->FindPropertyDeclaration(
+  &propertyName, ObjCPropertyQueryKind::OBJC_PR_query_class)) {

Use `auto`.


https://reviews.llvm.org/D29967



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


[PATCH] D26654: [CMake] Add Fuchsia toolchain CMake cache files

2017-02-15 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a comment.

Thanks for all your work on these!


Repository:
  rL LLVM

https://reviews.llvm.org/D26654



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


[PATCH] D24812: Lit C++11 Compatibility Patch #11

2017-02-15 Thread Charles Li via Phabricator via cfe-commits
tigerleapgorge updated this revision to Diff 88617.
tigerleapgorge added a comment.

Changed "CHECK11" to "CHECK11-NEXT".


https://reviews.llvm.org/D24812

Files:
  test/CodeGenCXX/mangle-unnamed.cpp
  test/CodeGenCXX/static-init.cpp
  test/CodeGenCXX/volatile-1.cpp
  test/CodeGenCXX/volatile.cpp
  test/PCH/macro-undef.cpp

Index: test/PCH/macro-undef.cpp
===
--- test/PCH/macro-undef.cpp
+++ test/PCH/macro-undef.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -emit-pch -o %t %s
-// RUN: %clang_cc1 -fsyntax-only -include-pch %t %s -Wuninitialized -verify
-// RUN: %clang_cc1 -fsyntax-only -include-pch %t %s -Wuninitialized -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -std=c++98 -emit-pch -o %t %s
+// RUN: %clang_cc1 -std=c++98 -fsyntax-only -include-pch %t %s -Wuninitialized -verify
+// RUN: %clang_cc1 -std=c++98 -fsyntax-only -include-pch %t %s -Wuninitialized -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s
 
 #ifndef HEADER
 #define HEADER
Index: test/CodeGenCXX/volatile.cpp
===
--- test/CodeGenCXX/volatile.cpp
+++ test/CodeGenCXX/volatile.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -std=c++98 -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -std=c++11 -o - | FileCheck -check-prefix=CHECK -check-prefix=CHECK11 %s
 
 // Check that IR gen doesn't try to do an lvalue-to-rvalue conversion
 // on a volatile reference result.  rdar://problem/8338198
@@ -27,6 +28,7 @@
   // CHECK-LABEL: define void @_ZN5test14testEv()
   void test() {
 // CHECK:  [[TMP:%.*]] = load i32*, i32** @_ZN5test11xE, align 8
+// CHECK11-NEXT: {{%.*}} = load volatile i32, i32* [[TMP]], align 4
 // CHECK-NEXT: ret void
 *x;
   }
Index: test/CodeGenCXX/volatile-1.cpp
===
--- test/CodeGenCXX/volatile-1.cpp
+++ test/CodeGenCXX/volatile-1.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -Wno-unused-value -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -Wno-unused-value -triple %itanium_abi_triple -emit-llvm %s -std=c++98 -o - | FileCheck %s
+// RUN: %clang_cc1 -Wno-unused-value -triple %itanium_abi_triple -emit-llvm %s -std=c++11 -o - | FileCheck -check-prefix=CHECK -check-prefix=CHECK11 %s
 
 // CHECK: @i = global [[INT:i[0-9]+]] 0
 volatile int i, j, k;
@@ -22,18 +23,22 @@
 
   asm("nop"); // CHECK: call void asm
 
-  // should not load
+  // should not load in C++98
   i;
+  // CHECK11-NEXT: load volatile [[INT]], [[INT]]* @i
 
   (float)(ci);
   // CHECK-NEXT: load volatile [[INT]], [[INT]]* getelementptr inbounds ([[CINT]], [[CINT]]* @ci, i32 0, i32 0)
   // CHECK-NEXT: load volatile [[INT]], [[INT]]* getelementptr inbounds ([[CINT]], [[CINT]]* @ci, i32 0, i32 1)
   // CHECK-NEXT: sitofp [[INT]]
 
-  // These are not uses in C++:
+  // These are not uses in C++98:
   //   [expr.static.cast]p6:
   // The lvalue-to-rvalue . . . conversions are not applied to the expression.
   (void)ci;
+  // CHECK11-NEXT: load volatile [[INT]], [[INT]]* getelementptr inbounds ([[CINT]], [[CINT]]* @ci, i32 0, i32 0)
+  // CHECK11-NEXT: load volatile [[INT]], [[INT]]* getelementptr inbounds ([[CINT]], [[CINT]]* @ci, i32 0, i32 1)
+
   (void)a;
 
   (void)(ci=ci);
@@ -126,7 +131,8 @@
   // CHECK-NEXT: load volatile
   // CHECK-NEXT: sitofp
 
-  (void)i;
+  (void)i; // This is now a load in C++11
+  // CHECK11-NEXT: load volatile
 
   i=i;
   // CHECK-NEXT: load volatile
@@ -155,25 +161,30 @@
   // CHECK-NEXT: br label
   // CHECK:  phi
 
-  (void)(i,(i=i));
+  (void)(i,(i=i)); // first i is also a load in C++11
+  // CHECK11-NEXT: load volatile
   // CHECK-NEXT: load volatile
   // CHECK-NEXT: store volatile
 
-  i=i,k;
+  i=i,k; // k is also a load in C++11
   // CHECK-NEXT: load volatile [[INT]], [[INT]]* @i
   // CHECK-NEXT: store volatile {{.*}}, [[INT]]* @i
+  // CHECK11-NEXT: load volatile [[INT]], [[INT]]* @k
 
   (i=j,k=j);
   // CHECK-NEXT: load volatile [[INT]], [[INT]]* @j
   // CHECK-NEXT: store volatile {{.*}}, [[INT]]* @i
   // CHECK-NEXT: load volatile [[INT]], [[INT]]* @j
   // CHECK-NEXT: store volatile {{.*}}, [[INT]]* @k
 
-  (i=j,k);
+  (i=j,k); // k is also a load in C++11
   // CHECK-NEXT: load volatile [[INT]], [[INT]]* @j
   // CHECK-NEXT: store volatile {{.*}}, [[INT]]* @i
+  // CHECK11-NEXT: load volatile [[INT]], [[INT]]* @k
 
-  (i,j);
+  (i,j); // i and j both are loads in C++11
+  // CHECK11-NEXT: load volatile [[INT]], [[INT]]* @i
+  // CHECK11-NEXT: load volatile [[INT]], [[INT]]* @j
 
   // Extra load in C++.
   i=c=k;
@@ -190,7 +201,9 @@
   // CHECK-NEXT: add nsw [[INT]]
   // CHECK-NEXT: store volatile
 
-  ci;
+  ci; // ci is a load in C++11
+  // CHECK11-NEXT: load volatile {{.*}} @ci, i32 0, i32 0
+  // C

  1   2   >