[libcxx] r299625 - [libc++] Respect Windows Store app CRT restrictions

2017-04-05 Thread Shoaib Meenai via cfe-commits
Author: smeenai
Date: Wed Apr  5 23:47:49 2017
New Revision: 299625

URL: http://llvm.org/viewvc/llvm-project?rev=299625=rev
Log:
[libc++] Respect Windows Store app CRT restrictions

Some CRT APIs are unavailable for Windows Store apps [1]. Detect when
we're targeting the Windows Store and don't try to refer to non-existent
CRT functions in that case. (This would otherwise lead to a compile
error when using the libc++ headers and compiling for Windows Store.)

[1] 
https://docs.microsoft.com/en-us/cpp/cppcx/crt-functions-not-supported-in-universal-windows-platform-apps

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

Modified:
libcxx/trunk/include/__config
libcxx/trunk/include/cstdlib

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=299625=299624=299625=diff
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Wed Apr  5 23:47:49 2017
@@ -211,6 +211,16 @@
 # if defined(_LIBCPP_MSVCRT)
 #   define _LIBCPP_HAS_QUICK_EXIT
 # endif
+
+// Some CRT APIs are unavailable to store apps
+#if defined(WINAPI_FAMILY)
+#include 
+#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) &&  
\
+(!defined(WINAPI_PARTITION_SYSTEM) ||  
\
+ !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_SYSTEM))
+#define _LIBCPP_WINDOWS_STORE_APP
+#endif
+#endif
 #endif // defined(_WIN32)
 
 #ifdef __sun__

Modified: libcxx/trunk/include/cstdlib
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/cstdlib?rev=299625=299624=299625=diff
==
--- libcxx/trunk/include/cstdlib (original)
+++ libcxx/trunk/include/cstdlib Wed Apr  5 23:47:49 2017
@@ -130,8 +130,10 @@ using ::abort;
 using ::atexit;
 using ::exit;
 using ::_Exit;
+#ifndef _LIBCPP_WINDOWS_STORE_APP
 using ::getenv;
 using ::system;
+#endif
 using ::bsearch;
 using ::qsort;
 using ::abs;


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


[PATCH] D31737: [libc++] Respect Windows Store app CRT restrictions

2017-04-05 Thread Shoaib Meenai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL299625: [libc++] Respect Windows Store app CRT restrictions 
(authored by smeenai).

Changed prior to commit:
  https://reviews.llvm.org/D31737?vs=94308=94317#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D31737

Files:
  libcxx/trunk/include/__config
  libcxx/trunk/include/cstdlib


Index: libcxx/trunk/include/cstdlib
===
--- libcxx/trunk/include/cstdlib
+++ libcxx/trunk/include/cstdlib
@@ -130,8 +130,10 @@
 using ::atexit;
 using ::exit;
 using ::_Exit;
+#ifndef _LIBCPP_WINDOWS_STORE_APP
 using ::getenv;
 using ::system;
+#endif
 using ::bsearch;
 using ::qsort;
 using ::abs;
Index: libcxx/trunk/include/__config
===
--- libcxx/trunk/include/__config
+++ libcxx/trunk/include/__config
@@ -211,6 +211,16 @@
 # if defined(_LIBCPP_MSVCRT)
 #   define _LIBCPP_HAS_QUICK_EXIT
 # endif
+
+// Some CRT APIs are unavailable to store apps
+#if defined(WINAPI_FAMILY)
+#include 
+#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) &&  
\
+(!defined(WINAPI_PARTITION_SYSTEM) ||  
\
+ !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_SYSTEM))
+#define _LIBCPP_WINDOWS_STORE_APP
+#endif
+#endif
 #endif // defined(_WIN32)
 
 #ifdef __sun__


Index: libcxx/trunk/include/cstdlib
===
--- libcxx/trunk/include/cstdlib
+++ libcxx/trunk/include/cstdlib
@@ -130,8 +130,10 @@
 using ::atexit;
 using ::exit;
 using ::_Exit;
+#ifndef _LIBCPP_WINDOWS_STORE_APP
 using ::getenv;
 using ::system;
+#endif
 using ::bsearch;
 using ::qsort;
 using ::abs;
Index: libcxx/trunk/include/__config
===
--- libcxx/trunk/include/__config
+++ libcxx/trunk/include/__config
@@ -211,6 +211,16 @@
 # if defined(_LIBCPP_MSVCRT)
 #   define _LIBCPP_HAS_QUICK_EXIT
 # endif
+
+// Some CRT APIs are unavailable to store apps
+#if defined(WINAPI_FAMILY)
+#include 
+#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) &&  \
+(!defined(WINAPI_PARTITION_SYSTEM) ||  \
+ !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_SYSTEM))
+#define _LIBCPP_WINDOWS_STORE_APP
+#endif
+#endif
 #endif // defined(_WIN32)
 
 #ifdef __sun__
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] [PPC64]: Add support for Swift calling convention

2017-04-05 Thread Andrew Jeffery via cfe-commits
Ping - Is anyone happy to review or apply the patch?

If I've missed some process I should have followed, please let me know!

Andrew

On Wed, 2017-03-22 at 22:30 +1030, Andrew Jeffery wrote:
> Signed-off-by: Andrew Jeffery 
> ---
>  lib/Basic/Targets.cpp  | 11 +++
>  lib/CodeGen/TargetInfo.cpp | 14 --
>  2 files changed, 23 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp
> index fdedd91a3e15..6d7f37f2479a 100644
> --- a/lib/Basic/Targets.cpp
> +++ b/lib/Basic/Targets.cpp
> @@ -1708,6 +1708,17 @@ public:
>  }
>  return false;
>    }
> +
> +  CallingConvCheckResult checkCallingConvention(CallingConv CC)
> const override {
> +switch (CC) {
> +case CC_C:
> +case CC_Swift:
> +return CCCR_OK;
> +default:
> +break;
> +}
> +return CCCR_Warning;
> +  }
>  };
>  
>  class DarwinPPC32TargetInfo : public
> DarwinTargetInfo {
> diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp
> index d2fc3888ef29..6193f6c4ac29 100644
> --- a/lib/CodeGen/TargetInfo.cpp
> +++ b/lib/CodeGen/TargetInfo.cpp
> @@ -4175,7 +4175,7 @@
> PPC32TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunct
> ion ,
>  
>  namespace {
>  /// PPC64_SVR4_ABIInfo - The 64-bit PowerPC ELF (SVR4) ABI
> information.
> -class PPC64_SVR4_ABIInfo : public ABIInfo {
> +class PPC64_SVR4_ABIInfo : public SwiftABIInfo {
>  public:
>    enum ABIKind {
>  ELFv1 = 0,
> @@ -4219,7 +4219,7 @@ private:
>  public:
>    PPC64_SVR4_ABIInfo(CodeGen::CodeGenTypes , ABIKind Kind, bool
> HasQPX,
>   bool SoftFloatABI)
> -  : ABIInfo(CGT), Kind(Kind), HasQPX(HasQPX),
> +  : SwiftABIInfo(CGT), Kind(Kind), HasQPX(HasQPX),
>  IsSoftFloatABI(SoftFloatABI) {}
>  
>    bool isPromotableTypeForABI(QualType Ty) const;
> @@ -4262,6 +4262,16 @@ public:
>  
>    Address EmitVAArg(CodeGenFunction , Address VAListAddr,
>  QualType Ty) const override;
> +
> +  bool shouldPassIndirectlyForSwift(CharUnits totalSize,
> +ArrayRef scalars,
> +bool asReturnValue) const
> override {
> +return occupiesMoreThan(CGT, scalars, /*total*/ 4);
> +  }
> +
> +  bool isSwiftErrorInRegister() const override {
> +return true;
> +  }
>  };
>  
>  class PPC64_SVR4_TargetCodeGenInfo : public TargetCodeGenInfo {

signature.asc
Description: This is a digitally signed message part
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31667: [Sema] Extend GetSignedVectorType to deal with non ExtVector types

2017-04-05 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:9736
+  }
+
+  if (TypeSize == Context.getTypeSize(Context.LongLongTy))

This isn't particularly urgent, but can we use ASTContext 
::getIntTypeForBitwidth here rather than calling getVectorType or 
getExtVectorType in many places?



https://reviews.llvm.org/D31667



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


[libcxx] r299607 - Fix remote test execution in lit

2017-04-05 Thread Mehdi Amini via cfe-commits
Author: mehdi_amini
Date: Wed Apr  5 20:14:57 2017
New Revision: 299607

URL: http://llvm.org/viewvc/llvm-project?rev=299607=rev
Log:
Fix remote test execution in lit

Can be used as such:

  $ python /path/to/lit.py -sv /path/to/llvm/build/projects/libcxx/test/ \
--param=use_system_cxx_lib=true \
--param=executor='SSHExecutor("remote.domain", "username")'

Modified:
libcxx/trunk/utils/libcxx/test/executor.py

Modified: libcxx/trunk/utils/libcxx/test/executor.py
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/utils/libcxx/test/executor.py?rev=299607=299606=299607=diff
==
--- libcxx/trunk/utils/libcxx/test/executor.py (original)
+++ libcxx/trunk/utils/libcxx/test/executor.py Wed Apr  5 20:14:57 2017
@@ -196,7 +196,7 @@ class SSHExecutor(RemoteExecutor):
 # Not sure how to do suffix on osx yet
 dir_arg = '-d' if is_dir else ''
 cmd = 'mktemp -q {} /tmp/libcxx.XX'.format(dir_arg)
-temp_path, err, exitCode = self._execute_command_remote([cmd])
+_, temp_path, err, exitCode = self._execute_command_remote([cmd])
 temp_path = temp_path.strip()
 if exitCode != 0:
 raise RuntimeError(err)
@@ -219,4 +219,5 @@ class SSHExecutor(RemoteExecutor):
 remote_cmd = ' '.join(env_cmd + cmd)
 if remote_work_dir != '.':
 remote_cmd = 'cd ' + remote_work_dir + ' && ' + remote_cmd
-return self.local_run(ssh_cmd + [remote_cmd])
+out, err, rc = self.local_run(ssh_cmd + [remote_cmd])
+return (remote_cmd, out, err, rc)


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


[libcxx] r299606 - Use alternate string layout for ARMv7k

2017-04-05 Thread Mehdi Amini via cfe-commits
Author: mehdi_amini
Date: Wed Apr  5 20:10:22 2017
New Revision: 299606

URL: http://llvm.org/viewvc/llvm-project?rev=299606=rev
Log:
Use alternate string layout for ARMv7k

Modified:
libcxx/trunk/include/__config

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=299606=299605=299606=diff
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Wed Apr  5 20:10:22 2017
@@ -265,7 +265,7 @@
 // _LIBCPP_ALTERNATE_STRING_LAYOUT is an old name for
 // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT left here for backward compatibility.
 #if (defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) &&   
\
- !defined(__arm__)) || 
\
+ (!defined(__arm__) || __ARM_ARCH_7K__ >= 2)) ||   
\
 defined(_LIBCPP_ALTERNATE_STRING_LAYOUT)
 #define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
 #endif


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


[PATCH] D25866: [Sema] Support implicit scalar to vector conversions

2017-04-05 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:8024
+  bool RHSNatVec = RHS.get()->IgnoreImpCasts()->getType()->isVectorType();
+
+  if (LHSNatVec ^ RHSNatVec) {

I think "!=" is easier to understand than "^" here.



Comment at: lib/Sema/SemaExpr.cpp:8305
 
-  // If there's an ext-vector type and a scalar, try to convert the scalar to
+  // If there's an vector type and a scalar, try to convert the scalar to
   // the vector element type and splat.

"a vector"


https://reviews.llvm.org/D25866



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


[PATCH] D31737: [libc++] Respect Windows Store app CRT restrictions

2017-04-05 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai created this revision.

Some CRT APIs are unavailable for Windows Store apps [1]. Detect when
we're targeting the Windows Store and don't try to refer to non-existent
CRT functions in that case. (This would otherwise lead to a compile
error when using the libc++ headers and compiling for Windows Store.)

[1] 
https://docs.microsoft.com/en-us/cpp/cppcx/crt-functions-not-supported-in-universal-windows-platform-apps


https://reviews.llvm.org/D31737

Files:
  include/__config
  include/cstdlib


Index: include/cstdlib
===
--- include/cstdlib
+++ include/cstdlib
@@ -130,8 +130,10 @@
 using ::atexit;
 using ::exit;
 using ::_Exit;
+#ifndef _LIBCPP_WINDOWS_STORE_APP
 using ::getenv;
 using ::system;
+#endif
 using ::bsearch;
 using ::qsort;
 using ::abs;
Index: include/__config
===
--- include/__config
+++ include/__config
@@ -211,6 +211,16 @@
 # if defined(_LIBCPP_MSVCRT)
 #   define _LIBCPP_HAS_QUICK_EXIT
 # endif
+
+// Some CRT APIs are unavailable to store apps
+#if defined(WINAPI_FAMILY)
+#include 
+#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) &&  
\
+(!defined(WINAPI_PARTITION_SYSTEM) ||  
\
+ !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_SYSTEM))
+#define _LIBCPP_WINDOWS_STORE_APP
+#endif
+#endif
 #endif // defined(_WIN32)
 
 #ifdef __sun__


Index: include/cstdlib
===
--- include/cstdlib
+++ include/cstdlib
@@ -130,8 +130,10 @@
 using ::atexit;
 using ::exit;
 using ::_Exit;
+#ifndef _LIBCPP_WINDOWS_STORE_APP
 using ::getenv;
 using ::system;
+#endif
 using ::bsearch;
 using ::qsort;
 using ::abs;
Index: include/__config
===
--- include/__config
+++ include/__config
@@ -211,6 +211,16 @@
 # if defined(_LIBCPP_MSVCRT)
 #   define _LIBCPP_HAS_QUICK_EXIT
 # endif
+
+// Some CRT APIs are unavailable to store apps
+#if defined(WINAPI_FAMILY)
+#include 
+#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) &&  \
+(!defined(WINAPI_PARTITION_SYSTEM) ||  \
+ !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_SYSTEM))
+#define _LIBCPP_WINDOWS_STORE_APP
+#endif
+#endif
 #endif // defined(_WIN32)
 
 #ifdef __sun__
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31736: Implement _interlockedbittestandset as a builtin

2017-04-05 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:570
+llvm::AtomicOrdering::SequentiallyConsistent);
+llvm::Value *Shifted = Builder.CreateLShr(RMWI, Bit);
+llvm::Value *Truncated =

Can you comment that this shifts the relevant bit into the low bit, truncates 
to i8, and then tests the low bit? At first I was thinking "of course, we just 
do AND %old, $constant to test the bit".

Do we successfully pattern match this idiom to `lock bts`? Is there a pattern 
match we should target?


https://reviews.llvm.org/D31736



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


r299603 - [Sema] Update CheckOverload docs

2017-04-05 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Wed Apr  5 19:23:31 2017
New Revision: 299603

URL: http://llvm.org/viewvc/llvm-project?rev=299603=rev
Log:
[Sema] Update CheckOverload docs

- Replace documented return values (true/false) with what's actually
  returned
- Doxygenify the comment
- Reflow said comment to 80 cols

Not overly familiar with Doxygen, so nits are welcome. :)

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

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=299603=299602=299603=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Apr  5 19:23:31 2017
@@ -917,40 +917,39 @@ static bool checkArgPlaceholdersForOverl
   return false;
 }
 
-// IsOverload - Determine whether the given New declaration is an
-// overload of the declarations in Old. This routine returns false if
-// New and Old cannot be overloaded, e.g., if New has the same
-// signature as some function in Old (C++ 1.3.10) or if the Old
-// declarations aren't functions (or function templates) at all. When
-// it does return false, MatchedDecl will point to the decl that New
-// cannot be overloaded with.  This decl may be a UsingShadowDecl on
-// top of the underlying declaration.
-//
-// Example: Given the following input:
-//
-//   void f(int, float); // #1
-//   void f(int, int); // #2
-//   int f(int, int); // #3
-//
-// When we process #1, there is no previous declaration of "f",
-// so IsOverload will not be used.
-//
-// When we process #2, Old contains only the FunctionDecl for #1.  By
-// comparing the parameter types, we see that #1 and #2 are overloaded
-// (since they have different signatures), so this routine returns
-// false; MatchedDecl is unchanged.
-//
-// When we process #3, Old is an overload set containing #1 and #2. We
-// compare the signatures of #3 to #1 (they're overloaded, so we do
-// nothing) and then #3 to #2. Since the signatures of #3 and #2 are
-// identical (return types of functions are not part of the
-// signature), IsOverload returns false and MatchedDecl will be set to
-// point to the FunctionDecl for #2.
-//
-// 'NewIsUsingShadowDecl' indicates that 'New' is being introduced
-// into a class by a using declaration.  The rules for whether to hide
-// shadow declarations ignore some properties which otherwise figure
-// into a function template's signature.
+/// Determine whether the given New declaration is an overload of the
+/// declarations in Old. This routine returns Ovl_Match or Ovl_NonFunction if
+/// New and Old cannot be overloaded, e.g., if New has the same signature as
+/// some function in Old (C++ 1.3.10) or if the Old declarations aren't
+/// functions (or function templates) at all. When it does return Ovl_Match or
+/// Ovl_NonFunction, MatchedDecl will point to the decl that New cannot be
+/// overloaded with. This decl may be a UsingShadowDecl on top of the 
underlying
+/// declaration.
+///
+/// Example: Given the following input:
+///
+///   void f(int, float); // #1
+///   void f(int, int); // #2
+///   int f(int, int); // #3
+///
+/// When we process #1, there is no previous declaration of "f", so IsOverload
+/// will not be used.
+///
+/// When we process #2, Old contains only the FunctionDecl for #1. By comparing
+/// the parameter types, we see that #1 and #2 are overloaded (since they have
+/// different signatures), so this routine returns Ovl_Overload; MatchedDecl is
+/// unchanged.
+///
+/// When we process #3, Old is an overload set containing #1 and #2. We compare
+/// the signatures of #3 to #1 (they're overloaded, so we do nothing) and then
+/// #3 to #2. Since the signatures of #3 and #2 are identical (return types of
+/// functions are not part of the signature), IsOverload returns Ovl_Match and
+/// MatchedDecl will be set to point to the FunctionDecl for #2.
+///
+/// 'NewIsUsingShadowDecl' indicates that 'New' is being introduced into a 
class
+/// by a using declaration. The rules for whether to hide shadow declarations
+/// ignore some properties which otherwise figure into a function template's
+/// signature.
 Sema::OverloadKind
 Sema::CheckOverload(Scope *S, FunctionDecl *New, const LookupResult ,
 NamedDecl *, bool NewIsUsingDecl) {


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


r299601 - Simplify. NFC.

2017-04-05 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Wed Apr  5 19:08:35 2017
New Revision: 299601

URL: http://llvm.org/viewvc/llvm-project?rev=299601=rev
Log:
Simplify. NFC.

Two simplifications:
- We check `!Previous.empty()` above and only use `Previous` in const
  contexts after that check, so the `!Previous.empty()` check seems
  redundant.
- The null check looks pointless, as well: AFAICT, `LookupResults`
  should never contain null entries, and `OldDecl` should always be
  non-null if `Redeclaration` is true.

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=299601=299600=299601=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Apr  5 19:08:35 2017
@@ -9038,14 +9038,10 @@ bool Sema::CheckFunctionDeclaration(Scop
 // with that name must be marked "overloadable".
 Diag(NewFD->getLocation(), diag::err_attribute_overloadable_missing)
   << Redeclaration << NewFD;
-NamedDecl *OverloadedDecl = nullptr;
-if (Redeclaration)
-  OverloadedDecl = OldDecl;
-else if (!Previous.empty())
-  OverloadedDecl = Previous.getRepresentativeDecl();
-if (OverloadedDecl)
-  Diag(OverloadedDecl->getLocation(),
-   diag::note_attribute_overloadable_prev_overload);
+NamedDecl *OverloadedDecl =
+Redeclaration ? OldDecl : Previous.getRepresentativeDecl();
+Diag(OverloadedDecl->getLocation(),
+ diag::note_attribute_overloadable_prev_overload);
 NewFD->addAttr(OverloadableAttr::CreateImplicit(Context));
   }
 }


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


[PATCH] D31736: Implement _interlockedbittestandset as a builtin

2017-04-05 Thread Hans Wennborg via Phabricator via cfe-commits
hans created this revision.

It's used by MS headers in VS 2017 without including intrin.h, so we can't 
implement it in the header anymore.


https://reviews.llvm.org/D31736

Files:
  include/clang/Basic/Builtins.def
  lib/CodeGen/CGBuiltin.cpp
  lib/Headers/intrin.h
  test/CodeGen/ms-intrinsics.c

Index: test/CodeGen/ms-intrinsics.c
===
--- test/CodeGen/ms-intrinsics.c
+++ test/CodeGen/ms-intrinsics.c
@@ -434,6 +434,17 @@
 
 #endif
 
+unsigned char test_interlockedbittestandset(volatile long *ptr, long bit) {
+  return _interlockedbittestandset(ptr, bit);
+}
+// CHECK-LABEL: define{{.*}} i8 @test_interlockedbittestandset
+// CHECK: %0 = shl i32 1, %bit
+// CHECK: %1 = atomicrmw or i32* %ptr, i32 %0 seq_cst
+// CHECK: %2 = lshr i32 %1, %bit
+// CHECK: %3 = trunc i32 %2 to i8
+// CHECK: %4 = and i8 %3, 1
+// CHECK: ret i8 %4
+
 void test__fastfail() {
   __fastfail(42);
 }
Index: lib/Headers/intrin.h
===
--- lib/Headers/intrin.h
+++ lib/Headers/intrin.h
@@ -173,7 +173,6 @@
 void __cdecl _enable(void);
 long _InterlockedAddLargeStatistic(__int64 volatile *_Addend, long _Value);
 unsigned char _interlockedbittestandreset(long volatile *, long);
-static __inline__
 unsigned char _interlockedbittestandset(long volatile *, long);
 long _InterlockedCompareExchange_HLEAcquire(long volatile *, long, long);
 long _InterlockedCompareExchange_HLERelease(long volatile *, long, long);
@@ -369,11 +368,6 @@
   *_BitBase = *_BitBase | (1 << _BitPos);
   return _Res;
 }
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
-_interlockedbittestandset(long volatile *_BitBase, long _BitPos) {
-  long _PrevVal = __atomic_fetch_or(_BitBase, 1l << _BitPos, __ATOMIC_SEQ_CST);
-  return (_PrevVal >> _BitPos) & 1;
-}
 #if defined(__arm__) || defined(__aarch64__)
 static __inline__ unsigned char __DEFAULT_FN_ATTRS
 _interlockedbittestandset_acq(long volatile *_BitBase, long _BitPos) {
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -492,6 +492,7 @@
   _InterlockedIncrement,
   _InterlockedOr,
   _InterlockedXor,
+  _interlockedbittestandset,
   __fastfail,
 };
 
@@ -559,6 +560,20 @@
   case MSVCIntrin::_InterlockedXor:
 return MakeBinaryAtomicValue(*this, AtomicRMWInst::Xor, E);
 
+  case MSVCIntrin::_interlockedbittestandset: {
+llvm::Value *Addr = EmitScalarExpr(E->getArg(0));
+llvm::Value *Bit = EmitScalarExpr(E->getArg(1));
+AtomicRMWInst *RMWI = Builder.CreateAtomicRMW(
+AtomicRMWInst::Or, Addr,
+Builder.CreateShl(ConstantInt::get(Bit->getType(), 1), Bit),
+llvm::AtomicOrdering::SequentiallyConsistent);
+llvm::Value *Shifted = Builder.CreateLShr(RMWI, Bit);
+llvm::Value *Truncated =
+Builder.CreateTrunc(Shifted, ConvertType(E->getType()));
+return Builder.CreateAnd(Truncated,
+ ConstantInt::get(Truncated->getType(), 1));
+  }
+
   case MSVCIntrin::_InterlockedDecrement: {
 llvm::Type *IntTy = ConvertType(E->getType());
 AtomicRMWInst *RMWI = Builder.CreateAtomicRMW(
@@ -2238,6 +2253,9 @@
   case Builtin::BI_InterlockedXor16:
   case Builtin::BI_InterlockedXor:
 return RValue::get(EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedXor, E));
+  case Builtin::BI_interlockedbittestandset:
+return RValue::get(
+EmitMSVCBuiltinExpr(MSVCIntrin::_interlockedbittestandset, E));
 
   case Builtin::BI__exception_code:
   case Builtin::BI_exception_code:
@@ -2309,10 +2327,8 @@
 break;
   }
 
-  case Builtin::BI__fastfail: {
+  case Builtin::BI__fastfail:
 return RValue::get(EmitMSVCBuiltinExpr(MSVCIntrin::__fastfail, E));
-break;
-  }
 
   case Builtin::BI__builtin_coro_size: {
 auto & Context = getContext();
Index: include/clang/Basic/Builtins.def
===
--- include/clang/Basic/Builtins.def
+++ include/clang/Basic/Builtins.def
@@ -756,6 +756,7 @@
 LANGBUILTIN(_InterlockedXor8,  "ccD*c",   "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedXor16, "ssD*s",   "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedXor,   "LiLiD*Li","n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_interlockedbittestandset, "UcLiD*Li", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(__noop,   "i.",  "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(__popcnt16, "UsUs", "nc", ALL_MS_LANGUAGES)
 LANGBUILTIN(__popcnt,   "UiUi", "nc", ALL_MS_LANGUAGES)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2017-04-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: docs/LanguageExtensions.rst:2380
+
+The ``__declspec`` style syntax is also supported. A single push directive
+accepts only one attribute regardless of the syntax used.

Might as well add an example for __declspec (since the other two have it), and 
move the restriction about the number of attributes supplied to its own 
paragraph for greater clarity.



Comment at: include/clang/Basic/DiagnosticGroups.td:462
 def IgnoredPragmas : DiagGroup<"ignored-pragmas", [IgnoredPragmaIntrinsic]>;
 def Pragmas : DiagGroup<"pragmas", [UnknownPragmas, IgnoredPragmas]>;
+def PragmaClangAttribute : DiagGroup<"pragma-clang-attribute">;

Should `PragmaClangAttribute` be added here as well?


Repository:
  rL LLVM

https://reviews.llvm.org/D30009



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


LLVM buildmaster will be updated and restarted tonight

2017-04-05 Thread Galina Kistanova via cfe-commits
Hello everyone,

LLVM buildmaster will be updated and restarted after 7 PM Pacific time
today.

Thanks

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


[libcxx] r299599 - [CMake][libcxx] Use builtins rather than gcc_s when compiler-rt is requested

2017-04-05 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Wed Apr  5 17:53:05 2017
New Revision: 299599

URL: http://llvm.org/viewvc/llvm-project?rev=299599=rev
Log:
[CMake][libcxx] Use builtins rather than gcc_s when compiler-rt is requested

When compiler-rt is requested, we should attempt to link compiler-rt
builtins library rather than gcc_s.

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

Modified:
libcxx/trunk/cmake/Modules/HandleCompilerRT.cmake
libcxx/trunk/cmake/config-ix.cmake
libcxx/trunk/lib/CMakeLists.txt

Modified: libcxx/trunk/cmake/Modules/HandleCompilerRT.cmake
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/cmake/Modules/HandleCompilerRT.cmake?rev=299599=299598=299599=diff
==
--- libcxx/trunk/cmake/Modules/HandleCompilerRT.cmake (original)
+++ libcxx/trunk/cmake/Modules/HandleCompilerRT.cmake Wed Apr  5 17:53:05 2017
@@ -3,8 +3,11 @@ function(find_compiler_rt_library name d
 message(FATAL_ERROR "LIBCXX_COMPILE_FLAGS must be defined when using this 
function")
   endif()
   set(dest "" PARENT_SCOPE)
-  set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBCXX_COMPILE_FLAGS}
+  set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${TARGET_TRIPLE} 
${LIBCXX_COMPILE_FLAGS}
   "--rtlib=compiler-rt" "--print-libgcc-file-name")
+  if (CMAKE_CXX_COMPILER_ID MATCHES Clang AND CMAKE_CXX_COMPILER_TARGET)
+list(APPEND CLANG_COMMAND "--target=${CMAKE_CXX_COMPILER_TARGET}")
+  endif()
   execute_process(
   COMMAND ${CLANG_COMMAND}
   RESULT_VARIABLE HAD_ERROR

Modified: libcxx/trunk/cmake/config-ix.cmake
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/cmake/config-ix.cmake?rev=299599=299598=299599=diff
==
--- libcxx/trunk/cmake/config-ix.cmake (original)
+++ libcxx/trunk/cmake/config-ix.cmake Wed Apr  5 17:53:05 2017
@@ -31,7 +31,9 @@ if (LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG)
 list(APPEND CMAKE_REQUIRED_LIBRARIES c)
   endif ()
   if (LIBCXX_USE_COMPILER_RT)
-list(APPEND CMAKE_REQUIRED_LIBRARIES -rtlib=compiler-rt)
+list(APPEND CMAKE_REQUIRED_FLAGS -rtlib=compiler-rt)
+find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY)
+list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBCXX_BUILTINS_LIBRARY}")
   elseif (LIBCXX_HAS_GCC_S_LIB)
 list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s)
   endif ()

Modified: libcxx/trunk/lib/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/lib/CMakeLists.txt?rev=299599=299598=299599=diff
==
--- libcxx/trunk/lib/CMakeLists.txt (original)
+++ libcxx/trunk/lib/CMakeLists.txt Wed Apr  5 17:53:05 2017
@@ -83,7 +83,12 @@ add_library_flags_if(LIBCXX_HAS_PTHREAD_
 add_library_flags_if(LIBCXX_HAS_C_LIB c)
 add_library_flags_if(LIBCXX_HAS_M_LIB m)
 add_library_flags_if(LIBCXX_HAS_RT_LIB rt)
-add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
+if (LIBCXX_USE_COMPILER_RT)
+  find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY)
+  add_library_flags_if(LIBCXX_BUILTINS_LIBRARY "${LIBCXX_BUILTINS_LIBRARY}")
+else()
+  add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
+endif()
 add_library_flags_if(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB atomic)
 
 # Add the unwinder library.


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


r299597 - [Driver] Print a newline when invoking `-print-resource-dir`

2017-04-05 Thread Meador Inge via cfe-commits
Author: meadori
Date: Wed Apr  5 17:27:20 2017
New Revision: 299597

URL: http://llvm.org/viewvc/llvm-project?rev=299597=rev
Log:
[Driver] Print a newline when invoking `-print-resource-dir`

The commit yesterday (r299473) to add the `-print-resource-dir`
option was supposed to emit a newline after the resource dir.

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

Modified:
cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=299597=299596=299597=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Wed Apr  5 17:27:20 2017
@@ -1170,7 +1170,7 @@ bool Driver::HandleImmediateArgs(const C
 TC.printVerboseInfo(llvm::errs());
 
   if (C.getArgs().hasArg(options::OPT_print_resource_dir)) {
-llvm::outs() << ResourceDir;
+llvm::outs() << ResourceDir << '\n';
 return false;
   }
 


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


[PATCH] D29622: Add a batch query and replace tool based on AST matchers.

2017-04-05 Thread Julian Bangert via Phabricator via cfe-commits
jbangert updated this revision to Diff 94297.
jbangert added a comment.

Fix command line tool.


https://reviews.llvm.org/D29622

Files:
  clang-query/CMakeLists.txt
  clang-query/QueryReplace.cpp
  clang-query/QueryReplace.h
  clang-query/replace-tool/CMakeLists.txt
  clang-query/replace-tool/ClangQueryReplace.cpp
  test/CMakeLists.txt
  test/clang-query/replacement.c

Index: test/clang-query/replacement.c
===
--- /dev/null
+++ test/clang-query/replacement.c
@@ -0,0 +1,5 @@
+// RUN: cp %s %t.c
+// RUN: clang-query-replace --spec  '{Query: "varDecl(hasName(\"version\"), hasInitializer(integerLiteral().bind(\"init\"))).bind(\"decl\")", FromId: "decl", ToTemplate: "string version = \"$$-${init}\""}' %t.c --
+// RUN: FileCheck --match-full-lines %s < %t.c
+int version = 4;
+// CHECK: string version = "$-4";
Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -44,6 +44,7 @@
   clang-include-fixer
   clang-move
   clang-query
+  clang-query-replace
   clang-rename
   clang-reorder-fields
   clang-tidy
Index: clang-query/replace-tool/ClangQueryReplace.cpp
===
--- /dev/null
+++ clang-query/replace-tool/ClangQueryReplace.cpp
@@ -0,0 +1,85 @@
+//=== ClangQueryReplace.cpp - clang-query-replace tool ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This tool automatically modifies source files based on AST matchers.
+//
+// A given AST matcher is applied to the source, and a bound node in
+// this matcher is replaced by the result of substituting the text
+// corresponding to other bound nodes into a string template.
+//
+// For example:
+// clang-query-replace --spec <
+#include 
+#include 
+
+using namespace clang;
+using namespace clang::query;
+using namespace llvm;
+
+using std::error_code;
+using clang::tooling::CommonOptionsParser;
+
+static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
+static cl::OptionCategory ClangQueryCategory("clang-query-replace options");
+
+static cl::list Commands("spec",
+  cl::desc("YAML action specification"),
+  cl::value_desc("spec"),
+  cl::cat(ClangQueryCategory));
+
+int main(int argc, const char **argv) {
+  llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
+
+  CommonOptionsParser OptionsParser(argc, argv, ClangQueryCategory);
+  if (Commands.empty()) {
+llvm::errs() << "Must specify at least one --spec \n";
+return 1;
+  }
+
+  tooling::RefactoringTool Refactor(OptionsParser.getCompilations(),
+OptionsParser.getSourcePathList());
+
+  QueryReplaceTool Tool(Refactor.getReplacements());
+  for (auto  : Commands) {
+
+llvm::Expected Spec =
+QueryReplaceSpec::parseFromYAML(SpecYaml);
+if (llvm::Error Error = Spec.takeError())
+  llvm::report_fatal_error(std::move(Error), false);
+if (llvm::Error Error = Tool.addOperation(*Spec))
+  llvm::report_fatal_error(std::move(Error), false);
+  }
+
+  return Refactor.runAndSave(tooling::newFrontendActionFactory().get());
+}
Index: clang-query/replace-tool/CMakeLists.txt
===
--- /dev/null
+++ clang-query/replace-tool/CMakeLists.txt
@@ -0,0 +1,14 @@
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
+
+add_clang_executable(clang-query-replace ClangQueryReplace.cpp)
+target_link_libraries(clang-query-replace
+  clangAST
+  clangASTMatchers
+  clangBasic
+  clangDynamicASTMatchers
+  clangFrontend
+  clangQuery
+  clangTooling
+  )
+
+install(TARGETS clang-query-replace RUNTIME DESTINATION bin)
\ No newline at end of file
Index: clang-query/QueryReplace.h
===
--- /dev/null
+++ clang-query/QueryReplace.h
@@ -0,0 +1,58 @@
+//===--- QueryReplace.h - clang-query-replace --*- 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_QUERY_QUERYREPLACE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_QUERY_QUERYREPLACE_H
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/Dynamic/Parser.h"
+#include "clang/Tooling/RefactoringCallbacks.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+#include 
+

[PATCH] D29877: Warn about unused static file scope function template declarations.

2017-04-05 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: lib/Sema/SemaDecl.cpp:1496
 return false;
+  // 'static operator' functions are defined in headers; don't warn.
+  if (FD->isOverloadedOperator() &&

rsmith wrote:
> Why? Defining a static operator in a header sounds like a bug to me.
It seems we have some of these here:

include/llvm/ADT/PointerUnion.h:static bool operator==(PointerUnion 
lhs, PointerUnion rhs) {
include/llvm/ADT/PointerUnion.h:static bool operator!=(PointerUnion 
lhs, PointerUnion rhs) {
include/llvm/ADT/PointerUnion.h:static bool operator<(PointerUnion 
lhs, PointerUnion rhs) {
include/llvm/Transforms/Utils/ValueMapper.h:static inline RemapFlags 
operator|(RemapFlags LHS, RemapFlags RHS) {

If that's a bug, I will remove this check.



Comment at: lib/Sema/SemaDecl.cpp:6679
   NewTemplate->setInvalidDecl();
+MarkUnusedFileScopedDecl(NewVD);
 ActOnDocumentableDecl(NewTemplate);

@rsmith, this forces the linkage to be computed and for some invalid code such 
as:

```
namespace { struct Internal {}; }
template __declspec(dllimport) auto InternalAutoTypeVarTmpl = 
Internal();
```

we hit an assertion in (Sema::DeduceVariableDeclarationType, SemaDecl.cpp:9991) 
`assert(VDecl->isLinkageValid())` which assumes that the linkage wasn't 
computed. Should we relax/remove the assert there?


https://reviews.llvm.org/D29877



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


[PATCH] D29877: Warn about unused static file scope function template declarations.

2017-04-05 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 94294.
v.g.vassilev added a comment.

Attach the right diff.


https://reviews.llvm.org/D29877

Files:
  lib/Sema/Sema.cpp
  lib/Sema/SemaDecl.cpp
  test/SemaCXX/warn-unused-filescoped.cpp

Index: test/SemaCXX/warn-unused-filescoped.cpp
===
--- test/SemaCXX/warn-unused-filescoped.cpp
+++ test/SemaCXX/warn-unused-filescoped.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-unused-local-typedefs -Wno-c++11-extensions -std=c++98 %s
-// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-unused-local-typedefs -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-unused-local-typedefs -std=c++14 %s
 
 #ifdef HEADER
 
@@ -32,6 +32,14 @@
   inline void bar(int, int) { }
 };
 
+namespace test8 {
+// Should ignore overloaded operators.
+template 
+struct S {};
+template 
+static bool operator==(S lhs, S rhs) { }
+}
+
 namespace pr19713 {
 #if __cplusplus >= 201103L
   static constexpr int constexpr1() { return 1; }
@@ -65,7 +73,7 @@
   template <> void TS::m() { }  // expected-warning{{unused}}
 
   template 
-  void tf() { }
+  void tf() { }  // expected-warning{{unused}}
   template <> void tf() { }  // expected-warning{{unused}}
   
   struct VS {
@@ -200,6 +208,28 @@
 static void func() {}
 }
 
+namespace test9 {
+template
+static void completeRedeclChainForTemplateSpecialization() { } // expected-warning {{unused}}
+}
+
+namespace test10 {
+#if __cplusplus >= 201103L
+template
+constexpr T pi = T(3.14);
+#endif
+
+#if __cplusplus >=  201402L
+struct limits {
+template
+static const T min;
+};
+
+template
+const T limits::min = { };
+#endif
+}
+
 namespace pr19713 {
 #if __cplusplus >= 201103L
   // FIXME: We should warn on both of these.
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -1493,6 +1493,10 @@
   // 'static inline' functions are defined in headers; don't warn.
   if (FD->isInlined() && !isMainFileLoc(*this, FD->getLocation()))
 return false;
+  // 'static operator' functions are defined in headers; don't warn.
+  if (FD->isOverloadedOperator() &&
+  !isMainFileLoc(*this, FD->getLocation()))
+return false;
 }
 
 if (FD->doesThisDeclarationHaveABody() &&
@@ -6672,6 +6676,7 @@
   if (NewTemplate) {
 if (NewVD->isInvalidDecl())
   NewTemplate->setInvalidDecl();
+MarkUnusedFileScopedDecl(NewVD);
 ActOnDocumentableDecl(NewTemplate);
 return NewTemplate;
   }
@@ -8887,6 +8892,7 @@
 if (FunctionTemplate) {
   if (NewFD->isInvalidDecl())
 FunctionTemplate->setInvalidDecl();
+  MarkUnusedFileScopedDecl(NewFD);
   return FunctionTemplate;
 }
   }
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -470,6 +470,13 @@
 return true;
 
   if (const FunctionDecl *FD = dyn_cast(D)) {
+// If this is a function template and neither of its specs is unused we
+// should warn.
+if (FunctionTemplateDecl *Template = FD->getDescribedFunctionTemplate())
+  for (const auto *Spec : Template->specializations())
+if (ShouldRemoveFromUnused(SemaRef, Spec))
+  return true;
+
 // UnusedFileScopedDecls stores the first declaration.
 // The declaration may have become definition so check again.
 const FunctionDecl *DeclToCheck;
@@ -493,6 +500,11 @@
 VD->isUsableInConstantExpressions(SemaRef->Context))
   return true;
 
+if (VarTemplateDecl *Template = VD->getDescribedVarTemplate())
+  for (const auto *Spec : Template->specializations())
+if (ShouldRemoveFromUnused(SemaRef, Spec))
+  return true;
+
 // UnusedFileScopedDecls stores the first declaration.
 // The declaration may have become definition so check again.
 const VarDecl *DeclToCheck = VD->getDefinition();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29877: Warn about unused static file scope function template declarations.

2017-04-05 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 94293.
v.g.vassilev marked 2 inline comments as done.
v.g.vassilev added a comment.

Iterate over the specs. Diagnose unused variable templates.


https://reviews.llvm.org/D29877

Files:
  include/clang/Sema/Sema.h
  lib/Sema/Sema.cpp
  lib/Sema/SemaDecl.cpp
  test/SemaCXX/dllimport.cpp
  test/SemaCXX/warn-unused-filescoped.cpp

Index: test/SemaCXX/warn-unused-filescoped.cpp
===
--- test/SemaCXX/warn-unused-filescoped.cpp
+++ test/SemaCXX/warn-unused-filescoped.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-unused-local-typedefs -Wno-c++11-extensions -std=c++98 %s
-// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-unused-local-typedefs -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-unused-local-typedefs -std=c++14 %s
 
 #ifdef HEADER
 
@@ -32,6 +32,14 @@
   inline void bar(int, int) { }
 };
 
+namespace test8 {
+// Should ignore overloaded operators.
+template 
+struct S {};
+template 
+static bool operator==(S lhs, S rhs) { }
+}
+
 namespace pr19713 {
 #if __cplusplus >= 201103L
   static constexpr int constexpr1() { return 1; }
@@ -65,7 +73,7 @@
   template <> void TS::m() { }  // expected-warning{{unused}}
 
   template 
-  void tf() { }
+  void tf() { }  // expected-warning{{unused}}
   template <> void tf() { }  // expected-warning{{unused}}
   
   struct VS {
@@ -200,6 +208,28 @@
 static void func() {}
 }
 
+namespace test9 {
+template
+static void completeRedeclChainForTemplateSpecialization() { } // expected-warning {{unused}}
+}
+
+namespace test10 {
+#if __cplusplus >= 201103L
+template
+constexpr T pi = T(3.14);
+#endif
+
+#if __cplusplus >=  201402L
+struct limits {
+template
+static const T min;
+};
+
+template
+const T limits::min = { };
+#endif
+}
+
 namespace pr19713 {
 #if __cplusplus >= 201103L
   // FIXME: We should warn on both of these.
Index: test/SemaCXX/dllimport.cpp
===
--- test/SemaCXX/dllimport.cpp
+++ test/SemaCXX/dllimport.cpp
@@ -4,1532 +4,8 @@
 // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DGNU %s
 
 // Helper structs to make templates more expressive.
-struct ImplicitInst_Imported {};
-struct ExplicitDecl_Imported {};
-struct ExplicitInst_Imported {};
-struct ExplicitSpec_Imported {};
-struct ExplicitSpec_Def_Imported {};
-struct ExplicitSpec_InlineDef_Imported {};
-struct ExplicitSpec_NotImported {};
 namespace { struct Internal {}; }
 
 
-// Invalid usage.
-__declspec(dllimport) typedef int typedef1;
-// expected-warning@-1{{'dllimport' attribute only applies to variables, functions and classes}}
-typedef __declspec(dllimport) int typedef2;
-// expected-warning@-1{{'dllimport' attribute only applies to variables, functions and classes}}
-typedef int __declspec(dllimport) typedef3;
-// expected-warning@-1{{'dllimport' attribute only applies to variables, functions and classes}}
-typedef __declspec(dllimport) void (*FunTy)();
-// expected-warning@-1{{'dllimport' attribute only applies to variables, functions and classes}}
-enum __declspec(dllimport) Enum {};
-// expected-warning@-1{{'dllimport' attribute only applies to variables, functions and classes}}
-#if __has_feature(cxx_strong_enums)
-enum class __declspec(dllimport) EnumClass {};
-// expected-warning@-1{{'dllimport' attribute only applies to variables, functions and classes}}
-#endif
-
-
-
-//===--===//
-// Globals
-//===--===//
-
-// Import declaration.
-__declspec(dllimport) extern int ExternGlobalDecl;
-
-// dllimport implies a declaration.
-__declspec(dllimport) int GlobalDecl;
-int **__attribute__((dllimport))* GlobalDeclChunkAttr;
-int GlobalDeclAttr __attribute__((dllimport));
-
-// Not allowed on definitions.
-__declspec(dllimport) extern int ExternGlobalInit = 1; // expected-error{{definition of dllimport data}}
-__declspec(dllimport) int GlobalInit1 = 1; // expected-error{{definition of dllimport data}}
-int __declspec(dllimport) GlobalInit2 = 1; // expected-error{{definition of dllimport data}}
-
-// Declare, then reject definition.
-#ifdef GNU
-// expected-note@+2{{previous attribute is here}}
-#endif
-__declspec(dllimport) extern int ExternGlobalDeclInit; // expected-note{{previous declaration is here}}
-#ifdef MS
-// expected-warning@+4{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
-#else
-// expected-warning@+2{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
-#endif
-int ExternGlobalDeclInit = 1;
-
-#ifdef GNU
-// expected-note@+2{{previous attribute is here}}
-#endif

[libunwind] r299591 - AddressSpace: fix DWARF based unwinding handling on Android

2017-04-05 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Wed Apr  5 16:29:38 2017
New Revision: 299591

URL: http://llvm.org/viewvc/llvm-project?rev=299591=rev
Log:
AddressSpace: fix DWARF based unwinding handling on Android

It is possible that there are no program headers in the module.  Do not
attempt to dereference nullptr as a program header.

Modified:
libunwind/trunk/src/AddressSpace.hpp

Modified: libunwind/trunk/src/AddressSpace.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/AddressSpace.hpp?rev=299591=299590=299591=diff
==
--- libunwind/trunk/src/AddressSpace.hpp (original)
+++ libunwind/trunk/src/AddressSpace.hpp Wed Apr  5 16:29:38 2017
@@ -394,8 +394,11 @@ inline bool LocalAddressSpace::findUnwin
 size_t object_length;
 #if defined(__ANDROID__)
 Elf_Addr image_base =
-reinterpret_cast(pinfo->dlpi_phdr) -
-reinterpret_cast(pinfo->dlpi_phdr)->p_offset;
+pinfo->dlpi_phnum
+? reinterpret_cast(pinfo->dlpi_phdr) -
+  reinterpret_cast(pinfo->dlpi_phdr)
+  ->p_offset
+: 0;
 #endif
 
 for (Elf_Half i = 0; i < pinfo->dlpi_phnum; i++) {


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


[PATCH] D29621: Add ASTMatchRefactorer and ReplaceNodeWithTemplate to RefactoringCallbacks

2017-04-05 Thread Julian Bangert via Phabricator via cfe-commits
jbangert accepted this revision.
jbangert marked 2 inline comments as done.
jbangert added inline comments.



Comment at: unittests/Tooling/RefactoringCallbacksTest.cpp:101
+  std::string Expected = "void f() { FOO }";
+  ReplaceNodeWithTemplate Callback("id", "FOO");
+  expectRewritten(Code, Expected, id("id", declStmt()), Callback);

ioeric wrote:
> Have you rerun the tests? Does this still build?
ninja check-clang-tools works. 


https://reviews.llvm.org/D29621



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


[PATCH] D29621: Add ASTMatchRefactorer and ReplaceNodeWithTemplate to RefactoringCallbacks

2017-04-05 Thread Julian Bangert via Phabricator via cfe-commits
jbangert updated this revision to Diff 94282.
jbangert added a comment.

- Merge branch 'master' of http://llvm.org/git/clang into replace_template


https://reviews.llvm.org/D29621

Files:
  include/clang/Tooling/RefactoringCallbacks.h
  lib/Tooling/RefactoringCallbacks.cpp
  unittests/Tooling/RefactoringCallbacksTest.cpp

Index: unittests/Tooling/RefactoringCallbacksTest.cpp
===
--- unittests/Tooling/RefactoringCallbacksTest.cpp
+++ unittests/Tooling/RefactoringCallbacksTest.cpp
@@ -7,31 +7,30 @@
 //
 //===--===//
 
-#include "clang/Tooling/RefactoringCallbacks.h"
 #include "RewriterTestContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/RefactoringCallbacks.h"
 #include "gtest/gtest.h"
 
 namespace clang {
 namespace tooling {
 
 using namespace ast_matchers;
 
 template 
-void expectRewritten(const std::string ,
- const std::string ,
- const T ,
- RefactoringCallback ) {
-  MatchFinder Finder;
+void expectRewritten(const std::string , const std::string ,
+ const T , RefactoringCallback ) {
+  std::map FileToReplace;
+  ASTMatchRefactorer Finder(FileToReplace);
   Finder.addMatcher(AMatcher, );
   std::unique_ptr Factory(
   tooling::newFrontendActionFactory());
   ASSERT_TRUE(tooling::runToolOnCode(Factory->create(), Code))
   << "Parsing error in \"" << Code << "\"";
   RewriterTestContext Context;
   FileID ID = Context.createInMemoryFile("input.cc", Code);
-  EXPECT_TRUE(tooling::applyAllReplacements(Callback.getReplacements(),
+  EXPECT_TRUE(tooling::applyAllReplacements(FileToReplace["input.cc"],
 Context.Rewrite));
   EXPECT_EQ(Expected, Context.getRewrittenText(ID));
 }
@@ -61,40 +60,94 @@
   std::string Code = "void f() { int i = 1; }";
   std::string Expected = "void f() { int i = 2; }";
   ReplaceStmtWithText Callback("id", "2");
-  expectRewritten(Code, Expected, id("id", expr(integerLiteral())),
-  Callback);
+  expectRewritten(Code, Expected, id("id", expr(integerLiteral())), Callback);
 }
 
 TEST(RefactoringCallbacksTest, ReplacesStmtWithStmt) {
   std::string Code = "void f() { int i = false ? 1 : i * 2; }";
   std::string Expected = "void f() { int i = i * 2; }";
   ReplaceStmtWithStmt Callback("always-false", "should-be");
-  expectRewritten(Code, Expected,
-  id("always-false", conditionalOperator(
-  hasCondition(cxxBoolLiteral(equals(false))),
-  hasFalseExpression(id("should-be", expr(),
+  expectRewritten(
+  Code, Expected,
+  id("always-false",
+ conditionalOperator(hasCondition(cxxBoolLiteral(equals(false))),
+ hasFalseExpression(id("should-be", expr(),
   Callback);
 }
 
 TEST(RefactoringCallbacksTest, ReplacesIfStmt) {
   std::string Code = "bool a; void f() { if (a) f(); else a = true; }";
   std::string Expected = "bool a; void f() { f(); }";
   ReplaceIfStmtWithItsBody Callback("id", true);
-  expectRewritten(Code, Expected,
-  id("id", ifStmt(
-  hasCondition(implicitCastExpr(hasSourceExpression(
-  declRefExpr(to(varDecl(hasName("a"),
+  expectRewritten(
+  Code, Expected,
+  id("id", ifStmt(hasCondition(implicitCastExpr(hasSourceExpression(
+   declRefExpr(to(varDecl(hasName("a"),
   Callback);
 }
 
 TEST(RefactoringCallbacksTest, RemovesEntireIfOnEmptyElse) {
   std::string Code = "void f() { if (false) int i = 0; }";
   std::string Expected = "void f() {  }";
   ReplaceIfStmtWithItsBody Callback("id", false);
   expectRewritten(Code, Expected,
-  id("id", ifStmt(hasCondition(cxxBoolLiteral(equals(false),
-  Callback);
+  id("id", ifStmt(hasCondition(cxxBoolLiteral(equals(false),
+  Callback);
 }
 
+TEST(RefactoringCallbacksTest, TemplateJustText) {
+  std::string Code = "void f() { int i = 1; }";
+  std::string Expected = "void f() { FOO }";
+  auto Callback = ReplaceNodeWithTemplate::create("id", "FOO");
+  EXPECT_FALSE(Callback.takeError());
+  expectRewritten(Code, Expected, id("id", declStmt()), **Callback);
+}
+
+TEST(RefactoringCallbacksTest, TemplateSimpleSubst) {
+  std::string Code = "void f() { int i = 1; }";
+  std::string Expected = "void f() { long x = 1; }";
+  auto Callback = ReplaceNodeWithTemplate::create("decl", "long x = ${init}");
+  EXPECT_FALSE(Callback.takeError());
+  expectRewritten(Code, Expected,
+  id("decl", varDecl(hasInitializer(id("init", expr(),
+  **Callback);
+}
+
+TEST(RefactoringCallbacksTest, TemplateLiteral) {
+  std::string Code = "void f() { int i = 1; }";
+  std::string Expected = "void f() { string x = \"$-1\"; }";
+  auto 

[PATCH] D31725: [libc++] Add _LIBCPP_DISABLE_EXTERN_TEMPLATE config option

2017-04-05 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai created this revision.

When the libc++ extern template macros were added, the intent was for it
to be possible for consumers of the headers to disable extern templates
(via `-D_LIBCPP_EXTERN_TEMPLATE(...)=`). Unfortunately, support for
specifying function-like macros varies on the command line varies across
compilers (e.g. MSVC doesn't support it at all), and cmake doesn't allow
it for the same reason. Add a non-function macro for this purpose.

The intended use is for libraries which want to use the libc++ headers
without taking a dependency on the libc++ library itself. I can name the
macro something which reflects its intent rather than its behavior (e.g.
`_LIBCPP_HEADER_ONLY`) if desired.


https://reviews.llvm.org/D31725

Files:
  include/__config


Index: include/__config
===
--- include/__config
+++ include/__config
@@ -837,6 +837,11 @@
 # endif
 #endif
 
+#ifdef _LIBCPP_DISABLE_EXTERN_TEMPLATE
+#define _LIBCPP_EXTERN_TEMPLATE(...)
+#define _LIBCPP_EXTERN_TEMPLATE2(...)
+#endif
+
 #ifndef _LIBCPP_EXTERN_TEMPLATE
 #define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
 #endif


Index: include/__config
===
--- include/__config
+++ include/__config
@@ -837,6 +837,11 @@
 # endif
 #endif
 
+#ifdef _LIBCPP_DISABLE_EXTERN_TEMPLATE
+#define _LIBCPP_EXTERN_TEMPLATE(...)
+#define _LIBCPP_EXTERN_TEMPLATE2(...)
+#endif
+
 #ifndef _LIBCPP_EXTERN_TEMPLATE
 #define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29660: [OpenMP] Add flag for overwriting default PTX version for OpenMP targets

2017-04-05 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: lib/Driver/ToolChains/Cuda.cpp:495-506
+
+  StringRef PtxVersion = DriverArgs.getLastArgValue(
+options::OPT_fopenmp_ptx_EQ);
+
   CC1Args.push_back("+ptx42");
 
+  if (DeviceOffloadingKind == Action::OFK_OpenMP &&

I don't like this kind of code. It is better to make like this:
```
if (DeviceOffloadingKind == Action::OFK_OpenMP)
  CC1Args.push_back(DriverArgs.getLastArgValue(options::OPT_fopenmp_ptx_EQ, 
"+ptx42"));
else
  CC1Args.push_back("+ptx42");
```
or something like this


Repository:
  rL LLVM

https://reviews.llvm.org/D29660



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


[PATCH] D31401: [clangd] Extract FsPath from file:// uri

2017-04-05 Thread Stanislav Ionascu via Phabricator via cfe-commits
stanionascu marked 5 inline comments as done.
stanionascu added inline comments.



Comment at: clangd/Protocol.cpp:61
 if (KeyValue == "uri") {
-  Result.uri = Value->getValue(Storage);
+  Result.uri = Uri::parse(Value->getValue(Storage));
 } else if (KeyValue == "version") {

krasimir wrote:
> Hm, seems to me that here the uri should be kept as-is and the clients of 
> `Result.uri` should convert it to file when appropriate. Otherwise it's 
> confusing.
Implemented the "URI::parse" to store both representations.



Comment at: clangd/Protocol.h:32
 
+struct Uri {
+  static std::string parse(llvm::StringRef uri);

krasimir wrote:
> It's a little confusing: the `parse` method turns an `uri` to a `file` and 
> the `unparse` method does the opposite. Maybe we should use more descriptive 
> names, like `uriToFile` and `fileToUri`. This does not seem to be 
> inconsistent with the rest of the protocol since the protocol only cares 
> about uri-s, and file-s are an implementation detail of clangd I guess.
2nd try now, instead of actually storing a string based URI, store the object 
which both representations (uri and file).



Comment at: clangd/clients/clangd-vscode/src/extension.ts:28
+uriConverters: {
+// FIXME: implement percent decoding in clangd
+code2Protocol: (uri: vscode.Uri) : string => uri.toString(true),

krasimir wrote:
> By the way, what does this do? I'm not a typescript vs code guru.
Extended the FIXME, with the description, e.g. when vscode (on windows) sends 
the uri to clangd, it's represented as "file:///c%3A/path/tofile" which leads 
to:
- incorrect detection of the compilation database location.
- cannot find the actual unit in the database.

uri.toString(true) - skips the percent encoding and sends the uri parameter to 
clangd as "file:///c:/path/tofile"


https://reviews.llvm.org/D31401



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


[PATCH] D31401: [clangd] Extract FsPath from file:// uri

2017-04-05 Thread Stanislav Ionascu via Phabricator via cfe-commits
stanionascu updated this revision to Diff 94271.
stanionascu added a comment.

Refactored URI handling to make it more explicit, also updated the parts which 
expect a File parameter and not an URI.


https://reviews.llvm.org/D31401

Files:
  clangd/ASTManager.cpp
  clangd/ASTManager.h
  clangd/DocumentStore.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/ProtocolHandlers.cpp
  clangd/clients/clangd-vscode/src/extension.ts

Index: clangd/clients/clangd-vscode/src/extension.ts
===
--- clangd/clients/clangd-vscode/src/extension.ts
+++ clangd/clients/clangd-vscode/src/extension.ts
@@ -23,15 +23,23 @@
 
 const clientOptions: vscodelc.LanguageClientOptions = {
 // Register the server for C/C++ files
-documentSelector: ['c', 'cc', 'cpp', 'h', 'hh', 'hpp']
+documentSelector: ['c', 'cc', 'cpp', 'h', 'hh', 'hpp'],
+uriConverters: {
+// FIXME: by default the URI sent over the protocol will be percent encoded (see rfc3986#section-2.1)
+//the "workaround" below disables temporarily the encoding until decoding
+//is implemented properly in clangd
+code2Protocol: (uri: vscode.Uri) : string => uri.toString(true),
+protocol2Code: (uri: string) : vscode.Uri => undefined
+}
 };
 
 const clangdClient = new vscodelc.LanguageClient('Clang Language Server', serverOptions, clientOptions);
 
 function applyTextEdits(uri: string, edits: vscodelc.TextEdit[]) {
 let textEditor = vscode.window.activeTextEditor;
 
-if (textEditor && textEditor.document.uri.toString() === uri) {
+// FIXME: vscode expects that uri will be percent encoded
+if (textEditor && textEditor.document.uri.toString(true) === uri) {
 textEditor.edit(mutator => {
 for (const edit of edits) {
 mutator.replace(vscodelc.Protocol2Code.asRange(edit.range), edit.newText);
Index: clangd/ProtocolHandlers.cpp
===
--- clangd/ProtocolHandlers.cpp
+++ clangd/ProtocolHandlers.cpp
@@ -21,7 +21,7 @@
 Output.log("Failed to decode DidOpenTextDocumentParams!\n");
 return;
   }
-  Store.addDocument(DOTDP->textDocument.uri, DOTDP->textDocument.text);
+  Store.addDocument(DOTDP->textDocument.uri.file, DOTDP->textDocument.text);
 }
 
 void TextDocumentDidChangeHandler::handleNotification(
@@ -32,7 +32,7 @@
 return;
   }
   // We only support full syncing right now.
-  Store.addDocument(DCTDP->textDocument.uri, DCTDP->contentChanges[0].text);
+  Store.addDocument(DCTDP->textDocument.uri.file, DCTDP->contentChanges[0].text);
 }
 
 /// Turn a [line, column] pair into an offset in Code.
@@ -83,9 +83,6 @@
   // Call clang-format.
   // FIXME: Don't ignore style.
   format::FormatStyle Style = format::getLLVMStyle();
-  // On windows FileManager doesn't like file://. Just strip it, clang-format
-  // doesn't need it.
-  Filename.consume_front("file://");
   tooling::Replacements Replacements =
   format::reformat(Style, Code, Ranges, Filename);
 
@@ -102,12 +99,12 @@
 return;
   }
 
-  std::string Code = Store.getDocument(DRFP->textDocument.uri);
+  std::string Code = Store.getDocument(DRFP->textDocument.uri.file);
 
   size_t Begin = positionToOffset(Code, DRFP->range.start);
   size_t Len = positionToOffset(Code, DRFP->range.end) - Begin;
 
-  writeMessage(formatCode(Code, DRFP->textDocument.uri,
+  writeMessage(formatCode(Code, DRFP->textDocument.uri.file,
   {clang::tooling::Range(Begin, Len)}, ID));
 }
 
@@ -121,14 +118,14 @@
 
   // Look for the previous opening brace from the character position and format
   // starting from there.
-  std::string Code = Store.getDocument(DOTFP->textDocument.uri);
+  std::string Code = Store.getDocument(DOTFP->textDocument.uri.file);
   size_t CursorPos = positionToOffset(Code, DOTFP->position);
   size_t PreviousLBracePos = StringRef(Code).find_last_of('{', CursorPos);
   if (PreviousLBracePos == StringRef::npos)
 PreviousLBracePos = CursorPos;
   size_t Len = 1 + CursorPos - PreviousLBracePos;
 
-  writeMessage(formatCode(Code, DOTFP->textDocument.uri,
+  writeMessage(formatCode(Code, DOTFP->textDocument.uri.file,
   {clang::tooling::Range(PreviousLBracePos, Len)}, ID));
 }
 
@@ -141,8 +138,8 @@
   }
 
   // Format everything.
-  std::string Code = Store.getDocument(DFP->textDocument.uri);
-  writeMessage(formatCode(Code, DFP->textDocument.uri,
+  std::string Code = Store.getDocument(DFP->textDocument.uri.file);
+  writeMessage(formatCode(Code, DFP->textDocument.uri.file,
   {clang::tooling::Range(0, Code.size())}, ID));
 }
 
@@ -156,7 +153,7 @@
 
   // We provide a code action for each diagnostic at the requested location
   // which has FixIts available.
-  std::string Code = 

[PATCH] D30087: [Driver] Unify linking of OpenMP runtime

2017-04-05 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: lib/Driver/ToolChains/CommonArgs.cpp:430
+bool tools::addOpenMPRuntime(ArgStringList , const ToolChain ,
+ const ArgList , const JobAction ,
+ bool GompNeedsRT) {

Do you really need to pass a reference to `JobAction` here or it is enough to 
pass a bool value for `JA.isHostOffloading()`?



Comment at: lib/Driver/ToolChains/CommonArgs.cpp:443-445
+if (GompNeedsRT) {
+  CmdArgs.push_back("-lrt");
+}

Remove braces here


https://reviews.llvm.org/D30087



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


[PATCH] D31696: Automatically add include-what-you-use for when building in tree

2017-04-05 Thread Kim Gräsman via Phabricator via cfe-commits
kimgr added a comment.

As an include-what-you-use maintainer, I would very much welcome this. I've 
been too shy to suggest it myself ;-).


https://reviews.llvm.org/D31696



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


[PATCH] D31540: Prefer non-friend to friend in in redeclaration chain

2017-04-05 Thread Yaron Keren via Phabricator via cfe-commits
yaron.keren added a comment.

Thanks, I'll make a test.


Repository:
  rL LLVM

https://reviews.llvm.org/D31540



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


r299577 - [lit] Fix Analysis test format pickling error

2017-04-05 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Wed Apr  5 13:56:48 2017
New Revision: 299577

URL: http://llvm.org/viewvc/llvm-project?rev=299577=rev
Log:
[lit] Fix Analysis test format pickling error

Move the test format into a standalone .py file and add it to the site
module search path. This allows us to run the test on Windows, and it
makes it compatible with the multiprocessing.Pool lit test execution
strategy.

I think this test was only passing everywhere else because
multiprocessing uses 'fork' to spawn workers, so the test format never
needs to be pickled.

Added:
cfe/trunk/test/Analysis/analyzer_test.py
Modified:
cfe/trunk/test/Analysis/lit.local.cfg

Added: cfe/trunk/test/Analysis/analyzer_test.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/analyzer_test.py?rev=299577=auto
==
--- cfe/trunk/test/Analysis/analyzer_test.py (added)
+++ cfe/trunk/test/Analysis/analyzer_test.py Wed Apr  5 13:56:48 2017
@@ -0,0 +1,28 @@
+import lit.formats
+import lit.TestRunner
+
+# Custom format class for static analyzer tests
+class AnalyzerTest(lit.formats.ShTest):
+
+def execute(self, test, litConfig):
+result = self.executeWithAnalyzeSubstitution(
+test, litConfig, '-analyzer-constraints=range')
+
+if result.code == lit.Test.FAIL:
+return result
+
+# If z3 backend available, add an additional run line for it
+if test.config.clang_staticanalyzer_z3 == '1':
+result = self.executeWithAnalyzeSubstitution(
+test, litConfig, '-analyzer-constraints=z3 -DANALYZER_CM_Z3')
+
+return result
+
+def executeWithAnalyzeSubstitution(self, test, litConfig, substitution):
+saved_substitutions = list(test.config.substitutions)
+test.config.substitutions.append(('%analyze', substitution))
+result = lit.TestRunner.executeShTest(test, litConfig,
+  self.execute_external)
+test.config.substitutions = saved_substitutions
+
+return result

Modified: cfe/trunk/test/Analysis/lit.local.cfg
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/lit.local.cfg?rev=299577=299576=299577=diff
==
--- cfe/trunk/test/Analysis/lit.local.cfg (original)
+++ cfe/trunk/test/Analysis/lit.local.cfg Wed Apr  5 13:56:48 2017
@@ -1,34 +1,13 @@
-import lit.TestRunner
-import sys
+# -*- Python -*- vim: set ft=python ts=4 sw=4 expandtab tw=79:
 
-# Custom format class for static analyzer tests
-class AnalyzerTest(lit.formats.ShTest, object):
+import site
 
-def execute(self, test, litConfig):
-result = self.executeWithAnalyzeSubstitution(test, litConfig, 
'-analyzer-constraints=range')
-
-if result.code == lit.Test.FAIL:
-return result
-
-# If z3 backend available, add an additional run line for it
-if test.config.clang_staticanalyzer_z3 == '1':
-result = self.executeWithAnalyzeSubstitution(test, litConfig, 
'-analyzer-constraints=z3 -DANALYZER_CM_Z3')
-
-return result
-
-def executeWithAnalyzeSubstitution(self, test, litConfig, substitution):
-saved_substitutions = list(test.config.substitutions)
-test.config.substitutions.append(('%analyze', substitution))
-result = lit.TestRunner.executeShTest(test, litConfig, 
self.execute_external)
-test.config.substitutions = saved_substitutions
-
-return result
-
-# This results in a pickling-related failure on Windows
-if (not sys.platform in ['win32']):
-config.test_format = AnalyzerTest(config.test_format.execute_external)
-else:
-config.substitutions.append(('%analyze', '-analyzer-constraints=range'))
+# Load the custom analyzer test format, which runs the test again with Z3 if it
+# is available.
+site.addsitedir(os.path.dirname(__file__))
+import analyzer_test
+config.test_format = analyzer_test.AnalyzerTest(
+config.test_format.execute_external)
 
 if not config.root.clang_staticanalyzer:
 config.unsupported = True


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


[libunwind] r299575 - Fix invalid memory access on android x86

2017-04-05 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Wed Apr  5 13:33:23 2017
New Revision: 299575

URL: http://llvm.org/viewvc/llvm-project?rev=299575=rev
Log:
Fix invalid memory access on android x86

On certain versions of android x86, the main module `app_process` is not
built as PIE.  When accessing the PT_GNU_EH_FRAME_HDR in such a
scenario, the `dlpi_addr` is 0, but the virtual address is not
relocated.  Manually rebase the address to avoid an invalid memory
access.

Modified:
libunwind/trunk/src/AddressSpace.hpp

Modified: libunwind/trunk/src/AddressSpace.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/AddressSpace.hpp?rev=299575=299574=299575=diff
==
--- libunwind/trunk/src/AddressSpace.hpp (original)
+++ libunwind/trunk/src/AddressSpace.hpp Wed Apr  5 13:33:23 2017
@@ -383,16 +383,29 @@ inline bool LocalAddressSpace::findUnwin
 #if !defined(Elf_Phdr)
 typedef ElfW(Phdr) Elf_Phdr;
 #endif
+#if !defined(Elf_Addr)
+typedef ElfW(Addr) Elf_Addr;
+#endif
 
  #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
   #if !defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)
#error "_LIBUNWIND_SUPPORT_DWARF_UNWIND requires 
_LIBUNWIND_SUPPORT_DWARF_INDEX on this platform."
   #endif
 size_t object_length;
+#if defined(__ANDROID__)
+Elf_Addr image_base =
+reinterpret_cast(pinfo->dlpi_phdr) -
+reinterpret_cast(pinfo->dlpi_phdr)->p_offset;
+#endif
+
 for (Elf_Half i = 0; i < pinfo->dlpi_phnum; i++) {
   const Elf_Phdr *phdr = >dlpi_phdr[i];
   if (phdr->p_type == PT_LOAD) {
 uintptr_t begin = pinfo->dlpi_addr + phdr->p_vaddr;
+#if defined(__ANDROID__)
+if (pinfo->dlpi_addr == 0 && phdr->p_vaddr < image_base)
+  begin = begin + image_base;
+#endif
 uintptr_t end = begin + phdr->p_memsz;
 if (cbdata->targetAddr >= begin && cbdata->targetAddr < end) {
   cbdata->sects->dso_base = begin;
@@ -402,6 +415,10 @@ inline bool LocalAddressSpace::findUnwin
   } else if (phdr->p_type == PT_GNU_EH_FRAME) {
 EHHeaderParser::EHHeaderInfo hdrInfo;
 uintptr_t eh_frame_hdr_start = pinfo->dlpi_addr + phdr->p_vaddr;
+#if defined(__ANDROID__)
+if (pinfo->dlpi_addr == 0 && phdr->p_vaddr < image_base)
+  eh_frame_hdr_start = eh_frame_hdr_start + image_base;
+#endif
 cbdata->sects->dwarf_index_section = eh_frame_hdr_start;
 cbdata->sects->dwarf_index_section_length = phdr->p_memsz;
 EHHeaderParser::decodeEHHdr(


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


[PATCH] D31717: CodeGen: Emit lifetime intrinsics with pointer argument in alloca address space

2017-04-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In https://reviews.llvm.org/D31717#719362, @arsenm wrote:

> I had the part for non-0 alloca too, but not sure if I posted it. It's in my 
> GitHub branch


For that one we'd better stick to https://reviews.llvm.org/D31404 since the 
review is almost done. I will acknowledge your contribution and others in the 
commit message.


https://reviews.llvm.org/D31717



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


[PATCH] D30922: [Builtins] Synchronize the definition of fma/fmaf/fmal in Builtins.def with the implementation in CGBuiltins.cpp

2017-04-05 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Ping


https://reviews.llvm.org/D30922



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


r299574 - clang-format: Support formatting utf-8 character literals in C++11+ mode.

2017-04-05 Thread Nico Weber via cfe-commits
Author: nico
Date: Wed Apr  5 13:10:42 2017
New Revision: 299574

URL: http://llvm.org/viewvc/llvm-project?rev=299574=rev
Log:
clang-format: Support formatting utf-8 character literals in C++11+ mode.

clang-format `` instead of ``A``).
+Use features of C++11, C++14 and C++1z (e.g. ``A`` instead of 
+``A``).
 
   * ``LS_Auto`` (in configuration: ``Auto``)
 Automatic detection based on the input.

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=299574=299573=299574=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Wed Apr  5 13:10:42 2017
@@ -1256,7 +1256,8 @@ struct FormatStyle {
   enum LanguageStandard {
 /// Use C++03-compatible syntax.
 LS_Cpp03,
-/// Use features of C++11 (e.g. ``A`` instead of ``A``).
+/// Use features of C++11, C++14 and C++1z (e.g. ``A`` instead of
+/// ``A``).
 LS_Cpp11,
 /// Automatic detection based on the input.
 LS_Auto

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=299574=299573=299574=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Apr  5 13:10:42 2017
@@ -1894,6 +1894,7 @@ LangOptions getFormattingLangOpts(const
   LangOpts.CPlusPlus = 1;
   LangOpts.CPlusPlus11 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
   LangOpts.CPlusPlus14 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
+  LangOpts.CPlusPlus1z = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
   LangOpts.LineComment = 1;
   bool AlternativeOperators = Style.isCpp();
   LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=299574=299573=299574=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Apr  5 13:10:42 2017
@@ -10195,6 +10195,19 @@ TEST_F(ReplacementTest, SortIncludesAfte
   EXPECT_EQ(Expected, *Result);
 }
 
+TEST_F(FormatTest, UTF8CharacterLiteralCpp03) {
+  format::FormatStyle Style = format::getLLVMStyle();
+  Style.Standard = FormatStyle::LS_Cpp03;
+  // cpp03 recognize this string as identifier u8 and literal character 'a'
+  EXPECT_EQ("auto c = u8 'a';", format("auto c = u8'a';", Style));
+}
+
+TEST_F(FormatTest, UTF8CharacterLiteralCpp11) {
+  // u8'a' is a C++17 feature, utf8 literal character, LS_Cpp11 covers
+  // all modes, including C++11, C++14 and C++17
+  EXPECT_EQ("auto c = u8'a';", format("auto c = u8'a';"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang


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


[PATCH] D31717: CodeGen: Emit lifetime intrinsics with pointer argument in alloca address space

2017-04-05 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

I had the part for non-0 alloca too, but not sure if I posted it. It's in my 
GitHub branch


https://reviews.llvm.org/D31717



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


[PATCH] D31717: CodeGen: Emit lifetime intrinsics with pointer argument in alloca address space

2017-04-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In https://reviews.llvm.org/D31717#719316, @arsenm wrote:

> I already have https://reviews.llvm.org/D31043 which can be committed 
> independently of the alloca change


I did not know you already have a patch. Can you add reviewers to it?

The only difference is that I added AllocaInt8PtrTy to CodeGenModule and a lit 
test for non-zero alloca addr space.

I can rebase my patch on top of yours. Or I can drop this patch and add the lit 
test to your patch.


https://reviews.llvm.org/D31717



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


[PATCH] D31717: CodeGen: Emit lifetime intrinsics with pointer argument in alloca address space

2017-04-05 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

I already have https://reviews.llvm.org/D31043 which can be committed 
independently of the alloca change


https://reviews.llvm.org/D31717



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


[PATCH] D31717: CodeGen: Emit lifetime intrinsics with pointer argument in alloca address space

2017-04-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
Herald added a subscriber: wdng.

There is incoming LLVM changes for letting alloca return pointers to alloca 
address space specified by data layout and correspondingly letting lifetime 
intrinsics to accept pointer arguments in alloca address space.

https://reviews.llvm.org/D31041

https://reviews.llvm.org/D31042

This patch makes Clang to emit correct lifetime intrinsics following the above 
two changes in LLVM.

Basically lifetime intrinsics will be declared with pointer argument in alloca 
address space.


https://reviews.llvm.org/D31717

Files:
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenTypeCache.h
  test/CodeGen/cleanup-destslot-simple.c
  test/CodeGen/lifetime-asan.c
  test/CodeGen/lifetime.c
  test/CodeGen/lifetime2.c
  test/CodeGen/temporary-lifetime-exceptions.cpp
  test/CodeGen/temporary-lifetime.cpp
  test/CodeGenCXX/destructors.cpp
  test/CodeGenCXX/microsoft-abi-eh-cleanups.cpp
  test/CodeGenCXX/nrvo.cpp
  test/CodeGenCXX/stack-reuse-miscompile.cpp
  test/CodeGenCXX/stack-reuse.cpp
  test/CodeGenObjC/arc-blocks.m
  test/CodeGenObjC/arc-bridged-cast.m
  test/CodeGenObjC/arc-literals.m
  test/CodeGenObjC/arc-precise-lifetime.m
  test/CodeGenObjC/arc-ternary-op.m
  test/CodeGenObjC/arc.m
  test/CodeGenObjC/exceptions.m
  test/CodeGenObjCXX/arc-move.mm
  test/CodeGenObjCXX/arc-references.mm
  test/CodeGenObjCXX/arc.mm
  test/CodeGenObjCXX/literals.mm

Index: test/CodeGenObjCXX/literals.mm
===
--- test/CodeGenObjCXX/literals.mm
+++ test/CodeGenObjCXX/literals.mm
@@ -21,7 +21,7 @@
 
   // Initializing first element
   // CHECK: [[PTR1:%.*]] = bitcast i8** [[ARR]] to i8*
-  // CHECK-NEXT: call void @llvm.lifetime.start(i64 8, i8* [[PTR1]])
+  // CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 8, i8* [[PTR1]])
   // CHECK: [[ELEMENT0:%[a-zA-Z0-9.]+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS]], i64 0, i64 0
   // CHECK-NEXT: call void @_ZN1XC1Ev
   // CHECK-NEXT: [[OBJECT0:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1XcvP11objc_objectEv
@@ -51,7 +51,7 @@
   // CHECK-NOT: ret void
   // CHECK: call void @objc_release
   // CHECK-NEXT: [[PTR2:%.*]] = bitcast i8** [[ARR]] to i8*
-  // CHECK-NEXT: call void @llvm.lifetime.end(i64 8, i8* [[PTR2]])
+  // CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 8, i8* [[PTR2]])
   // CHECK-NEXT: ret void
 
   // Check cleanups
@@ -73,7 +73,7 @@
 
   // Initializing first element
   // CHECK:  [[PTR1:%.*]] = bitcast i8** [[ARR]] to i8*
-  // CHECK-NEXT: call void @llvm.lifetime.start(i64 8, i8* [[PTR1]])
+  // CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 8, i8* [[PTR1]])
   // CHECK: [[ELEMENT0:%[a-zA-Z0-9.]+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS]], i64 0, i64 0
   // CHECK-NEXT: call void @_ZN1XC1Ev
   // CHECK-NEXT: [[OBJECT0:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1XcvP11objc_objectEv
@@ -103,7 +103,7 @@
   // CHECK-NOT: ret void
   // CHECK: call void @objc_release
   // CHECK-NEXT: [[PTR2]] = bitcast i8** [[ARR]] to i8*
-  // CHECK-NEXT: call void @llvm.lifetime.end(i64 8, i8* [[PTR2]])
+  // CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 8, i8* [[PTR2]])
   // CHECK-NEXT: ret void
 
   // Check cleanups
Index: test/CodeGenObjCXX/arc.mm
===
--- test/CodeGenObjCXX/arc.mm
+++ test/CodeGenObjCXX/arc.mm
@@ -65,10 +65,10 @@
   // CHECK-NEXT: [[CONDCLEANUP:%.*]] = alloca i1
   // CHECK-NEXT: store i32
   // CHECK-NEXT: [[STRONGP:%.*]] = bitcast i8** [[STRONG]] to i8*
-  // CHECK-NEXT: call void @llvm.lifetime.start(i64 8, i8* [[STRONGP]])
+  // CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 8, i8* [[STRONGP]])
   // CHECK-NEXT: store i8* null, i8** [[STRONG]]
   // CHECK-NEXT: [[WEAKP:%.*]] = bitcast i8** [[WEAK]] to i8*
-  // CHECK-NEXT: call void @llvm.lifetime.start(i64 8, i8* [[WEAKP]])
+  // CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 8, i8* [[WEAKP]])
   // CHECK-NEXT: call i8* @objc_initWeak(i8** [[WEAK]], i8* null)
 
   // CHECK-NEXT: [[T0:%.*]] = load i32, i32* [[COND]]
@@ -124,77 +124,77 @@
 
 // CHECK-LABEL: define void @_Z6test3513Test35_HelperPS_
 void test35(Test35_Helper x0, Test35_Helper *x0p) {
-  // CHECK: call void @llvm.lifetime.start
+  // CHECK: call void @llvm.lifetime.start.p0i8
   // CHECK: call i8* @_ZN13Test35_Helper11makeObject1Ev
   // CHECK-NOT: call i8* @objc_retain
   id obj1 = Test35_Helper::makeObject1();
-  // CHECK: call void @llvm.lifetime.start
+  // CHECK: call void @llvm.lifetime.start.p0i8
   // CHECK: call i8* @_ZN13Test35_Helper11makeObject2Ev
   // CHECK-NOT: call i8* @objc_retain
   id obj2 = x0.makeObject2();
-  // CHECK: call void @llvm.lifetime.start
+  // CHECK: call void @llvm.lifetime.start.p0i8
   // CHECK: call i8* @_ZN13Test35_Helper11makeObject2Ev
   // CHECK-NOT: call i8* @objc_retain
   id obj3 = x0p->makeObject2();
   id (Test35_Helper::*pmf)() 

[PATCH] D25866: [Sema] Support implicit scalar to vector conversions

2017-04-05 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:8188
+  //type and then perform the rest of the checks here. GCC as of
+  //pre-release 7.0 does not accept this though.
+  if (VectorEltTy->isIntegralType(S.Context) &&

sdardis wrote:
> bruno wrote:
> > Is this something that GCC is going to support at some point? Regardless of 
> > GCC, do we want this behavior?
> > Is this something that GCC is going to support at some point?
> 
> I've reread GCC's source for conversions of scalar to vectors types and it 
> appears that GCC does attempt to convert constant real expressions to 
> integers but it appears to only work for C++. It's a little odd.
> 
> > Regardless of GCC, do we want this behavior?
> 
> Given my oversight of the support of implicit safe conversions of floating 
> point constants to integer types, I believe we should do this in general. 
> I'll rework the comment to be more accurate and add the necessary conversion 
> checks.
Ok, improving the FIXME sounds good to me. We can add this extra functionality 
in a future patch.



Comment at: lib/Sema/SemaExpr.cpp:10019
   isa(vType->getAs()) || getLangOpts().OpenCL;
+  if ((!getLangOpts().CPlusPlus && !getLangOpts().OpenCL) && !isExtVectorType)
+return InvalidVectorOperands(Loc, LHS, RHS);

sdardis wrote:
> bruno wrote:
> > Why `!getLangOpts().CPlusPlus` is a requirement here?
> GCC only supports the logical operators &&, ||, ! when compiling C++.
> 
> It's noted near the bottom half of this page: 
> https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html
Ok. It would be nice to find out if there's any actual good reason for it, 
otherwise we might as well support it for non C++. But no need to block on 
that; just make sure to annotate these places with FIXMEs so we can work on it 
in the future. 


https://reviews.llvm.org/D25866



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


[clang-tools-extra] r299561 - Fix -Wmissing-field-initializer warnings to unbreak the -Werror build

2017-04-05 Thread David Blaikie via cfe-commits
Author: dblaikie
Date: Wed Apr  5 11:50:19 2017
New Revision: 299561

URL: http://llvm.org/viewvc/llvm-project?rev=299561=rev
Log:
Fix -Wmissing-field-initializer warnings to unbreak the -Werror build

Modified:
clang-tools-extra/trunk/unittests/clang-rename/RenameClassTest.cpp

Modified: clang-tools-extra/trunk/unittests/clang-rename/RenameClassTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-rename/RenameClassTest.cpp?rev=299561=299560=299561=diff
==
--- clang-tools-extra/trunk/unittests/clang-rename/RenameClassTest.cpp 
(original)
+++ clang-tools-extra/trunk/unittests/clang-rename/RenameClassTest.cpp Wed Apr  
5 11:50:19 2017
@@ -50,71 +50,82 @@ INSTANTIATE_TEST_CASE_P(
 RenameClassTests, RenameClassTest,
 testing::ValuesIn(std::vector({
 // basic classes
-{"a::Foo f;", "b::Bar f;"},
-{"void f(a::Foo f) {}", "void f(b::Bar f) {}"},
-{"void f(a::Foo *f) {}", "void f(b::Bar *f) {}"},
-{"a::Foo f() { return a::Foo(); }", "b::Bar f() { return b::Bar(); }"},
+{"a::Foo f;", "b::Bar f;", "", ""},
+{"void f(a::Foo f) {}", "void f(b::Bar f) {}", "", ""},
+{"void f(a::Foo *f) {}", "void f(b::Bar *f) {}", "", ""},
+{"a::Foo f() { return a::Foo(); }", "b::Bar f() { return b::Bar(); }",
+ "", ""},
 {"namespace a {a::Foo f() { return Foo(); }}",
- "namespace a {b::Bar f() { return b::Bar(); }}"},
-{"void f(const a::Foo& a1) {}", "void f(const b::Bar& a1) {}"},
-{"void f(const a::Foo* a1) {}", "void f(const b::Bar* a1) {}"},
+ "namespace a {b::Bar f() { return b::Bar(); }}", "", ""},
+{"void f(const a::Foo& a1) {}", "void f(const b::Bar& a1) {}", "", ""},
+{"void f(const a::Foo* a1) {}", "void f(const b::Bar* a1) {}", "", ""},
 {"namespace a { void f(Foo a1) {} }",
- "namespace a { void f(b::Bar a1) {} }"},
-{"void f(MACRO(a::Foo) a1) {}", "void f(MACRO(b::Bar) a1) {}"},
-{"void f(MACRO(a::Foo a1)) {}", "void f(MACRO(b::Bar a1)) {}"},
-{"a::Foo::Nested ns;", "b::Bar::Nested ns;"},
-{"auto t = a::Foo::Constant;", "auto t = b::Bar::Constant;"},
+ "namespace a { void f(b::Bar a1) {} }", "", ""},
+{"void f(MACRO(a::Foo) a1) {}", "void f(MACRO(b::Bar) a1) {}", "", ""},
+{"void f(MACRO(a::Foo a1)) {}", "void f(MACRO(b::Bar a1)) {}", "", ""},
+{"a::Foo::Nested ns;", "b::Bar::Nested ns;", "", ""},
+{"auto t = a::Foo::Constant;", "auto t = b::Bar::Constant;", "", ""},
 {"a::Foo::Nested ns;", "a::Foo::Nested2 ns;", "a::Foo::Nested",
  "a::Foo::Nested2"},
 
 // use namespace and typedefs
-{"using a::Foo; Foo gA;", "using b::Bar; b::Bar gA;"},
-{"using a::Foo; void f(Foo gA) {}", "using b::Bar; void f(Bar gA) {}"},
+{"using a::Foo; Foo gA;", "using b::Bar; b::Bar gA;", "", ""},
+{"using a::Foo; void f(Foo gA) {}", "using b::Bar; void f(Bar gA) {}",
+ "", ""},
 {"using a::Foo; namespace x { Foo gA; }",
- "using b::Bar; namespace x { Bar gA; }"},
+ "using b::Bar; namespace x { Bar gA; }", "", ""},
 {"struct S { using T = a::Foo; T a_; };",
- "struct S { using T = b::Bar; T a_; };"},
-{"using T = a::Foo; T gA;", "using T = b::Bar; T gA;"},
-{"typedef a::Foo T; T gA;", "typedef b::Bar T; T gA;"},
-{"typedef MACRO(a::Foo) T; T gA;", "typedef MACRO(b::Bar) T; T gA;"},
+ "struct S { using T = b::Bar; T a_; };", "", ""},
+{"using T = a::Foo; T gA;", "using T = b::Bar; T gA;", "", ""},
+{"typedef a::Foo T; T gA;", "typedef b::Bar T; T gA;", "", ""},
+{"typedef MACRO(a::Foo) T; T gA;", "typedef MACRO(b::Bar) T; T gA;", 
"",
+ ""},
 
 // struct members and other oddities
-{"struct S : public a::Foo {};", "struct S : public b::Bar {};"},
+{"struct S : public a::Foo {};", "struct S : public b::Bar {};", "",
+ ""},
 {"struct F { void f(a::Foo a1) {} };",
- "struct F { void f(b::Bar a1) {} };"},
-{"struct F { a::Foo a_; };", "struct F { b::Bar a_; };"},
-{"struct F { ptr a_; };", "struct F { ptr a_; };"},
-
-{"void f() { a::Foo::Nested ne; }", "void f() { b::Bar::Nested ne; }"},
-{"void f() { a::Goo::Nested ne; }", "void f() { a::Goo::Nested ne; }"},
+ "struct F { void f(b::Bar a1) {} };", "", ""},
+{"struct F { a::Foo a_; };", "struct F { b::Bar a_; };", "", ""},
+{"struct F { ptr a_; };", "struct F { ptr a_; };", "",
+ ""},
+
+{"void f() { a::Foo::Nested ne; }", "void f() { b::Bar::Nested ne; }",
+ "", ""},
+{"void f() { a::Goo::Nested ne; }", "void f() { a::Goo::Nested ne; }",
+ "", ""},
 {"void f() { a::Foo::Nested::NestedEnum e; }",
- "void f() { 

[PATCH] D31667: [Sema] Extend GetSignedVectorType to deal with non ExtVector types

2017-04-05 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno added a comment.
This revision is now accepted and ready to land.

Thanks Simon! LGTM


https://reviews.llvm.org/D31667



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


[PATCH] D31428: [x86] fix AVX FP cmp intrinsic documentation (PR28110)

2017-04-05 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added a comment.

Ping.


https://reviews.llvm.org/D31428



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


[PATCH] D31713: [Basic] getColumnNumber returns location of CR+LF on Windows

2017-04-05 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh created this revision.

When fixing a Clang-Tidy bug in https://reviews.llvm.org/D31406,
http://bugs.llvm.org/show_bug.cgi?id=32402,
reuse of FileID enabled the missing highlightRange function.
Assertion in highlightRange failed because the end-of-range column
number was 2 + the last column of a line on Windows.
This fix is required to enable https://reviews.llvm.org/D31406.


Repository:
  rL LLVM

https://reviews.llvm.org/D31713

Files:
  lib/Basic/SourceManager.cpp


Index: lib/Basic/SourceManager.cpp
===
--- lib/Basic/SourceManager.cpp
+++ lib/Basic/SourceManager.cpp
@@ -1144,8 +1144,18 @@
 unsigned *SourceLineCache = LastLineNoContentCache->SourceLineCache;
 unsigned LineStart = SourceLineCache[LastLineNoResult - 1];
 unsigned LineEnd = SourceLineCache[LastLineNoResult];
-if (FilePos >= LineStart && FilePos < LineEnd)
+if (FilePos >= LineStart && FilePos < LineEnd) {
+  // LineEnd is the LineStart of the next line.
+  // A line ends with separator LF or CR+LF on Windows.
+  // FilePos might point to the last separator,
+  // but we need a column number at most 1 + the last column.
+  if (FilePos + 1 == LineEnd && FilePos > LineStart) {
+const char *Buf = MemBuf->getBufferStart();
+if (Buf[FilePos - 1] == '\r' || Buf[FilePos - 1] == '\n')
+  --FilePos;
+  }
   return FilePos - LineStart + 1;
+}
   }
 
   const char *Buf = MemBuf->getBufferStart();


Index: lib/Basic/SourceManager.cpp
===
--- lib/Basic/SourceManager.cpp
+++ lib/Basic/SourceManager.cpp
@@ -1144,8 +1144,18 @@
 unsigned *SourceLineCache = LastLineNoContentCache->SourceLineCache;
 unsigned LineStart = SourceLineCache[LastLineNoResult - 1];
 unsigned LineEnd = SourceLineCache[LastLineNoResult];
-if (FilePos >= LineStart && FilePos < LineEnd)
+if (FilePos >= LineStart && FilePos < LineEnd) {
+  // LineEnd is the LineStart of the next line.
+  // A line ends with separator LF or CR+LF on Windows.
+  // FilePos might point to the last separator,
+  // but we need a column number at most 1 + the last column.
+  if (FilePos + 1 == LineEnd && FilePos > LineStart) {
+const char *Buf = MemBuf->getBufferStart();
+if (Buf[FilePos - 1] == '\r' || Buf[FilePos - 1] == '\n')
+  --FilePos;
+  }
   return FilePos - LineStart + 1;
+}
   }
 
   const char *Buf = MemBuf->getBufferStart();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D23418: [analyzer] Added a reusable constraint system to the CloneDetector

2017-04-05 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added a comment.

In https://reviews.llvm.org/D23418#719139, @NoQ wrote:

> Hmm, reverted because i'm seeing crashes on some buildbots (works for me 
> though).
>
> It's crashing somewhere in `saveHash`, seems that some `Stmt`s are null. For 
> instance, 
> http://lab.llvm.org:8011/builders/clang-cmake-aarch64-42vma/builds/5998 :


Not sure if it helps, but there was this build warning:
/home/buildslave/buildslave/clang-cmake-aarch64-39vma/llvm/tools/clang/lib/Analysis/CloneDetection.cpp:395:36:
 warning: ‘S’ is used uninitialized in this function [-Wuninitialized]


Repository:
  rL LLVM

https://reviews.llvm.org/D23418



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


[PATCH] D15994: Allow for unfinished #if blocks in preambles.

2017-04-05 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Thanks for working on this! I have some comments below:




Comment at: include/clang/Lex/Preprocessor.h:291
+
+void setState(State s) { ConditionalStackState = s; }
+

`setState` is redundant IMHO, just assign to `ConditionalStackState` when you 
use `setState` below.



Comment at: include/clang/Lex/Preprocessor.h:301
+
+const ArrayRef getStack() const {
+  return ConditionalStack;

the `const` is redundant for the return type.



Comment at: include/clang/Lex/Preprocessor.h:310
+
+void setStack(const ArrayRef ) {
+  if (!isRecording() && !isReplaying())

You can pass `ArrayRef` by value.



Comment at: include/clang/Lex/Preprocessor.h:1974
+
+  const ArrayRef getPreambleConditionalStack() const
+  { return PreambleConditionalStack.getStack(); }

the `const` is redundant for the return type.



Comment at: include/clang/Lex/Preprocessor.h:1978
+  void setRecordedPreambleConditionalStack(
+  const SmallVector ) {
+PreambleConditionalStack.setStack(s);

Please use `ArrayRef` instead of `SmallVector` here and in the function below.



Comment at: include/clang/Lex/PreprocessorLexer.h:181
+
+  void setConditionalLevels(const ArrayRef )
+  {

`ArrayRef` can be passed by value.



Comment at: include/clang/Lex/PreprocessorOptions.h:87
+  /// When the lexer is done, one of the things that need to be preserved is 
the
+  /// conditional #if stack, so the ASTWriter/ASTReader can safe/restore it 
when
+  /// processing the rest of the file.

Typo: `save`



Comment at: lib/Serialization/ASTReader.cpp:2896
+for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) {
+  auto loc = ReadSourceLocation(F, Record, Idx);
+  bool WasSkipping = Record[Idx++];

`Loc` should be capitalized.



Comment at: lib/Serialization/ASTWriter.cpp:2269
+  if (PP.isRecordingPreamble() && PP.hasRecordedPreamble()) {
+for (const auto  : PP.getPreambleConditionalStack()) {
+  AddSourceLocation(Cond.IfLoc, Record);

I think you should add an assertion here that verifies that the ASTWriter isn't 
creating a module.


https://reviews.llvm.org/D15994



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


[PATCH] D31669: Fix lambda to block conversion in C++17 by avoiding copy elision for the lambda capture used by the created block

2017-04-05 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Looks good, thanks.


Repository:
  rL LLVM

https://reviews.llvm.org/D31669



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


[PATCH] D23418: [analyzer] Added a reusable constraint system to the CloneDetector

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

Hmm, reverted because i'm seeing crashes on some buildbots (works for me 
though).

It's crashing somewhere in `saveHash`, seems that some `Stmt`s are null. For 
instance, 
http://lab.llvm.org:8011/builders/clang-cmake-aarch64-42vma/builds/5998 :

  #0 0x015356f8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) 
(/home/buildslave/buildslave/clang-cmake-aarch64-42vma/stage1/./bin/clang+0x15356f8)
  #1 0x01533a58 llvm::sys::RunSignalHandlers() 
(/home/buildslave/buildslave/clang-cmake-aarch64-42vma/stage1/./bin/clang+0x1533a58)
  #2 0x01533d0c SignalHandler(int) 
(/home/buildslave/buildslave/clang-cmake-aarch64-42vma/stage1/./bin/clang+0x1533d0c)
  #3 0x03ffb5150510 (linux-vdso.so.1+0x510)
  #4 0x02b562f0 clang::Stmt::children() 
(/home/buildslave/buildslave/clang-cmake-aarch64-42vma/stage1/./bin/clang+0x2b562f0)
  #5 0x029772a4 
clang::RecursiveCloneTypeIIConstraint::saveHash(clang::Stmt const*, clang::Decl 
const*, std::vector >&) 
(/home/buildslave/buildslave/clang-cmake-aarch64-42vma/stage1/./bin/clang+0x29772a4)
  #6 0x029795a8 
clang::RecursiveCloneTypeIIConstraint::constrain(std::vector, std::allocator > >&) 
(/home/buildslave/buildslave/clang-cmake-aarch64-42vma/stage1/./bin/clang+0x29795a8)
  #7 0x026786b0 void 
clang::CloneDetector::findClones(std::vector, std::allocator > >&, 
clang::RecursiveCloneTypeIIConstraint, clang::MinComplexityConstraint, 
clang::MinGroupSizeConstraint, clang::OnlyLargestCloneConstraint) 
(/home/buildslave/buildslave/clang-cmake-aarch64-42vma/stage1/./bin/clang+0x26786b0)
  #8 0x02678b08 void 
clang::ento::check::EndOfTranslationUnit::_checkEndOfTranslationUnit<(anonymous 
namespace)::CloneChecker>(void*, clang::TranslationUnitDecl const*, 
clang::ento::AnalysisManager&, clang::ento::BugReporter&) 
(/home/buildslave/buildslave/clang-cmake-aarch64-42vma/stage1/./bin/clang+0x2678b08)
  #9 0x028a9394 
clang::ento::CheckerManager::runCheckersOnEndOfTranslationUnit(clang::TranslationUnitDecl
 const*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) 
(/home/buildslave/buildslave/clang-cmake-aarch64-42vma/stage1/./bin/clang+0x28a9394)
  #10 0x0204b62c (anonymous 
namespace)::AnalysisConsumer::HandleTranslationUnit(clang::ASTContext&) [clone 
.part.4452] [clone .constprop.4496] 
(/home/buildslave/buildslave/clang-cmake-aarch64-42vma/stage1/./bin/clang+0x204b62c)
  #11 0x0206de78 clang::ParseAST(clang::Sema&, bool, bool) 
(/home/buildslave/buildslave/clang-cmake-aarch64-42vma/stage1/./bin/clang+0x206de78)
  #12 0x019e96b4 clang::FrontendAction::Execute() 
(/home/buildslave/buildslave/clang-cmake-aarch64-42vma/stage1/./bin/clang+0x19e96b4)
  #13 0x019c2c70 
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) 
(/home/buildslave/buildslave/clang-cmake-aarch64-42vma/stage1/./bin/clang+0x19c2c70)
  #14 0x01a64f30 
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) 
(/home/buildslave/buildslave/clang-cmake-aarch64-42vma/stage1/./bin/clang+0x1a64f30)
  #15 0x00998420 cc1_main(llvm::ArrayRef, char const*, 
void*) 
(/home/buildslave/buildslave/clang-cmake-aarch64-42vma/stage1/./bin/clang+0x998420)
  #16 0x00963b94 main 
(/home/buildslave/buildslave/clang-cmake-aarch64-42vma/stage1/./bin/clang+0x963b94)
  #17 0x03ffb4bef68c __libc_start_main (/lib64/libc.so.6+0x1f68c)
  #18 0x009950e8 _start 
(/home/buildslave/buildslave/clang-cmake-aarch64-42vma/stage1/./bin/clang+0x9950e8)


Repository:
  rL LLVM

https://reviews.llvm.org/D23418



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


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

2017-04-05 Thread Duncan P. N. Exon Smith via cfe-commits

> On Apr 5, 2017, at 05:44, Alex L  wrote:
> 
> 
> 
> On 5 April 2017 at 13:38, Duncan Exon Smith  > wrote:
> 
> 
> > On Apr 5, 2017, at 05:13, Aaron Ballman via Phabricator 
> > > wrote:
> >
> > aaron.ballman added inline comments.
> >
> >
> > 
> > Comment at: lib/Sema/SemaAttr.cpp:578
> > +return;
> > +  Diag(PragmaAttributeStack.back().Loc, 
> > diag::warn_pragm_attribute_no_pop_eof);
> > +}
> > 
> > arphaman wrote:
> >> aaron.ballman wrote:
> >>> Perhaps adding a FixIt here would be a kindness?
> >> Where would the fix-it point to? I think only the user will know the 
> >> location at which they meant to insert `#pragma clang attribute pop`.
> > Given that it's a warning rather than an error, and our recovery mechanism 
> > is to effectively pop the pragma at the end of the TU, I was thinking it 
> > could be added at the end of the TU. However, you are correct that it's 
> > probably not where the programmer needs it,
> 
> What about at the end of the file the push is in?  This is likely to be used 
> in header files, and it's probably unintentional if it extends past the end 
> of the file of the push.
> 
> Then we'd have to take into account preprocessor directives, as we'd 
> obviously want to insert it before the '#endif'. Or if the user used `#pragma 
> once`  then the end of the file could probably work.
> IMHO the improvement can be done as a follow-up that improves this and other 
> pragmas like #pragma pack.
> 

SGTM.

> 
> I think we should consider the same thing for #pragma pack (although that's a 
> little off-topic).
> 
> > so a FixIt likely isn't appropriate. Does that suggest the warning should 
> > be an error instead?
> 
> Maybe it should be an error, but I still think a fixit would be nice if we 
> can find a spot.
> 
> >
> >
> > Repository:
> >  rL LLVM
> >
> > https://reviews.llvm.org/D30009 
> >
> >
> >

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


r299550 - Revert "[analyzer] Add a modular constraint system to the CloneDetector"

2017-04-05 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Apr  5 10:06:17 2017
New Revision: 299550

URL: http://llvm.org/viewvc/llvm-project?rev=299550=rev
Log:
Revert "[analyzer] Add a modular constraint system to the CloneDetector"

This reverts commit r299544.

Crashes on tests on some buildbots.

Removed:
cfe/trunk/unittests/Analysis/CloneDetectionTest.cpp
Modified:
cfe/trunk/include/clang/Analysis/CloneDetection.h
cfe/trunk/lib/Analysis/CloneDetection.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/CloneChecker.cpp
cfe/trunk/unittests/Analysis/CMakeLists.txt

Modified: cfe/trunk/include/clang/Analysis/CloneDetection.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CloneDetection.h?rev=299550=299549=299550=diff
==
--- cfe/trunk/include/clang/Analysis/CloneDetection.h (original)
+++ cfe/trunk/include/clang/Analysis/CloneDetection.h Wed Apr  5 10:06:17 2017
@@ -16,7 +16,9 @@
 #define LLVM_CLANG_AST_CLONEDETECTION_H
 
 #include "clang/Basic/SourceLocation.h"
-#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Hashing.h"
+#include "llvm/ADT/StringMap.h"
+
 #include 
 
 namespace clang {
@@ -27,7 +29,7 @@ class VarDecl;
 class ASTContext;
 class CompoundStmt;
 
-/// Identifies a list of statements.
+/// \brief Identifies a list of statements.
 ///
 /// Can either identify a single arbitrary Stmt object, a continuous sequence 
of
 /// child statements inside a CompoundStmt or no statements at all.
@@ -37,8 +39,8 @@ class StmtSequence {
   /// Stmt, then S is a pointer to this Stmt.
   const Stmt *S;
 
-  /// The declaration that contains the statements.
-  const Decl *D;
+  /// The related ASTContext for S.
+  ASTContext *Context;
 
   /// If EndIndex is non-zero, then S is a CompoundStmt and this StmtSequence
   /// instance is representing the CompoundStmt children inside the array
@@ -47,7 +49,7 @@ class StmtSequence {
   unsigned EndIndex;
 
 public:
-  /// Constructs a StmtSequence holding multiple statements.
+  /// \brief Constructs a StmtSequence holding multiple statements.
   ///
   /// The resulting StmtSequence identifies a continuous sequence of statements
   /// in the body of the given CompoundStmt. Which statements of the body 
should
@@ -55,20 +57,20 @@ public:
   /// that describe a non-empty sub-array in the body of the given 
CompoundStmt.
   ///
   /// \param Stmt A CompoundStmt that contains all statements in its body.
-  /// \param Decl The Decl containing this Stmt.
+  /// \param Context The ASTContext for the given CompoundStmt.
   /// \param StartIndex The inclusive start index in the children array of
   ///   \p Stmt
   /// \param EndIndex The exclusive end index in the children array of \p Stmt.
-  StmtSequence(const CompoundStmt *Stmt, const Decl *D, unsigned StartIndex,
-   unsigned EndIndex);
+  StmtSequence(const CompoundStmt *Stmt, ASTContext ,
+   unsigned StartIndex, unsigned EndIndex);
 
-  /// Constructs a StmtSequence holding a single statement.
+  /// \brief Constructs a StmtSequence holding a single statement.
   ///
   /// \param Stmt An arbitrary Stmt.
-  /// \param Decl The Decl containing this Stmt.
-  StmtSequence(const Stmt *Stmt, const Decl *D);
+  /// \param Context The ASTContext for the given Stmt.
+  StmtSequence(const Stmt *Stmt, ASTContext );
 
-  /// Constructs an empty StmtSequence.
+  /// \brief Constructs an empty StmtSequence.
   StmtSequence();
 
   typedef const Stmt *const *iterator;
@@ -108,12 +110,9 @@ public:
   bool empty() const { return size() == 0; }
 
   /// Returns the related ASTContext for the stored Stmts.
-  ASTContext () const;
-
-  /// Returns the declaration that contains the stored Stmts.
-  const Decl *getContainingDecl() const {
-assert(D);
-return D;
+  ASTContext () const {
+assert(Context);
+return *Context;
   }
 
   /// Returns true if this objects holds a list of statements.
@@ -151,214 +150,106 @@ public:
   bool contains(const StmtSequence ) const;
 };
 
-/// Searches for similar subtrees in the AST.
+/// \brief Searches for clones in source code.
 ///
-/// First, this class needs several declarations with statement bodies which
-/// can be passed via analyzeCodeBody. Afterwards all statements can be
-/// searched for clones by calling findClones with a given list of constraints
-/// that should specify the wanted properties of the clones.
-///
-/// The result of findClones can be further constrained with the 
constrainClones
-/// method.
+/// First, this class needs a translation unit which is passed via
+/// \p analyzeTranslationUnit . It will then generate and store search data
+/// for all statements inside the given translation unit.
+/// Afterwards the generated data can be used to find code clones by calling
+/// \p findClones .
 ///
 /// This class only searches for clones in exectuable source code
 /// (e.g. function bodies). Other clones (e.g. cloned comments or 

[PATCH] D31496: Make -defsym a driver option

2017-04-05 Thread Sanne Wouda via Phabricator via cfe-commits
sanwou01 added reviewers: rnk, rsmith.
sanwou01 added a comment.

Hi Salman,

This essentially looks good to me. I don't think I'm the right person to LGTM 
this however, so I've added some reviewers who might be able to have a look.

Thanks,
Sanne


https://reviews.llvm.org/D31496



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


[PATCH] D23418: [analyzer] Added a reusable constraint system to the CloneDetector

2017-04-05 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL299544: [analyzer] Add a modular constraint system to the 
CloneDetector (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D23418?vs=93503=94227#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23418

Files:
  cfe/trunk/include/clang/Analysis/CloneDetection.h
  cfe/trunk/lib/Analysis/CloneDetection.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/CloneChecker.cpp
  cfe/trunk/unittests/Analysis/CMakeLists.txt
  cfe/trunk/unittests/Analysis/CloneDetectionTest.cpp

Index: cfe/trunk/include/clang/Analysis/CloneDetection.h
===
--- cfe/trunk/include/clang/Analysis/CloneDetection.h
+++ cfe/trunk/include/clang/Analysis/CloneDetection.h
@@ -16,9 +16,7 @@
 #define LLVM_CLANG_AST_CLONEDETECTION_H
 
 #include "clang/Basic/SourceLocation.h"
-#include "llvm/ADT/Hashing.h"
-#include "llvm/ADT/StringMap.h"
-
+#include "llvm/ADT/SmallVector.h"
 #include 
 
 namespace clang {
@@ -29,7 +27,7 @@
 class ASTContext;
 class CompoundStmt;
 
-/// \brief Identifies a list of statements.
+/// Identifies a list of statements.
 ///
 /// Can either identify a single arbitrary Stmt object, a continuous sequence of
 /// child statements inside a CompoundStmt or no statements at all.
@@ -39,38 +37,38 @@
   /// Stmt, then S is a pointer to this Stmt.
   const Stmt *S;
 
-  /// The related ASTContext for S.
-  ASTContext *Context;
+  /// The declaration that contains the statements.
+  const Decl *D;
 
   /// If EndIndex is non-zero, then S is a CompoundStmt and this StmtSequence
   /// instance is representing the CompoundStmt children inside the array
   /// [StartIndex, EndIndex).
   unsigned StartIndex;
   unsigned EndIndex;
 
 public:
-  /// \brief Constructs a StmtSequence holding multiple statements.
+  /// Constructs a StmtSequence holding multiple statements.
   ///
   /// The resulting StmtSequence identifies a continuous sequence of statements
   /// in the body of the given CompoundStmt. Which statements of the body should
   /// be identified needs to be specified by providing a start and end index
   /// that describe a non-empty sub-array in the body of the given CompoundStmt.
   ///
   /// \param Stmt A CompoundStmt that contains all statements in its body.
-  /// \param Context The ASTContext for the given CompoundStmt.
+  /// \param Decl The Decl containing this Stmt.
   /// \param StartIndex The inclusive start index in the children array of
   ///   \p Stmt
   /// \param EndIndex The exclusive end index in the children array of \p Stmt.
-  StmtSequence(const CompoundStmt *Stmt, ASTContext ,
-   unsigned StartIndex, unsigned EndIndex);
+  StmtSequence(const CompoundStmt *Stmt, const Decl *D, unsigned StartIndex,
+   unsigned EndIndex);
 
-  /// \brief Constructs a StmtSequence holding a single statement.
+  /// Constructs a StmtSequence holding a single statement.
   ///
   /// \param Stmt An arbitrary Stmt.
-  /// \param Context The ASTContext for the given Stmt.
-  StmtSequence(const Stmt *Stmt, ASTContext );
+  /// \param Decl The Decl containing this Stmt.
+  StmtSequence(const Stmt *Stmt, const Decl *D);
 
-  /// \brief Constructs an empty StmtSequence.
+  /// Constructs an empty StmtSequence.
   StmtSequence();
 
   typedef const Stmt *const *iterator;
@@ -110,9 +108,12 @@
   bool empty() const { return size() == 0; }
 
   /// Returns the related ASTContext for the stored Stmts.
-  ASTContext () const {
-assert(Context);
-return *Context;
+  ASTContext () const;
+
+  /// Returns the declaration that contains the stored Stmts.
+  const Decl *getContainingDecl() const {
+assert(D);
+return D;
   }
 
   /// Returns true if this objects holds a list of statements.
@@ -150,106 +151,214 @@
   bool contains(const StmtSequence ) const;
 };
 
-/// \brief Searches for clones in source code.
+/// Searches for similar subtrees in the AST.
 ///
-/// First, this class needs a translation unit which is passed via
-/// \p analyzeTranslationUnit . It will then generate and store search data
-/// for all statements inside the given translation unit.
-/// Afterwards the generated data can be used to find code clones by calling
-/// \p findClones .
+/// First, this class needs several declarations with statement bodies which
+/// can be passed via analyzeCodeBody. Afterwards all statements can be
+/// searched for clones by calling findClones with a given list of constraints
+/// that should specify the wanted properties of the clones.
+///
+/// The result of findClones can be further constrained with the constrainClones
+/// method.
 ///
 /// This class only searches for clones in exectuable source code
 /// (e.g. function bodies). Other clones (e.g. cloned comments or declarations)
 /// are not supported.
 class CloneDetector {
+
 public:
-  typedef unsigned DataPiece;
+  /// A collection of 

r299544 - [analyzer] Add a modular constraint system to the CloneDetector

2017-04-05 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Apr  5 09:17:36 2017
New Revision: 299544

URL: http://llvm.org/viewvc/llvm-project?rev=299544=rev
Log:
[analyzer] Add a modular constraint system to the CloneDetector

A big part of the clone detection code is functionality for filtering clones and
clone groups based on different criteria. So far this filtering process was
hardcoded into the CloneDetector class, which made it hard to understand and,
ultimately, to extend.

This patch splits the CloneDetector's logic into a sequence of reusable
constraints that are used for filtering clone groups. These constraints
can be turned on and off and reodreder at will, and new constraints are easy
to implement if necessary.

Unit tests are added for the new constraint interface.

This is a refactoring patch - no functional change intended.

Patch by Raphael Isemann!

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

Added:
cfe/trunk/unittests/Analysis/CloneDetectionTest.cpp
Modified:
cfe/trunk/include/clang/Analysis/CloneDetection.h
cfe/trunk/lib/Analysis/CloneDetection.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/CloneChecker.cpp
cfe/trunk/unittests/Analysis/CMakeLists.txt

Modified: cfe/trunk/include/clang/Analysis/CloneDetection.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CloneDetection.h?rev=299544=299543=299544=diff
==
--- cfe/trunk/include/clang/Analysis/CloneDetection.h (original)
+++ cfe/trunk/include/clang/Analysis/CloneDetection.h Wed Apr  5 09:17:36 2017
@@ -16,9 +16,7 @@
 #define LLVM_CLANG_AST_CLONEDETECTION_H
 
 #include "clang/Basic/SourceLocation.h"
-#include "llvm/ADT/Hashing.h"
-#include "llvm/ADT/StringMap.h"
-
+#include "llvm/ADT/SmallVector.h"
 #include 
 
 namespace clang {
@@ -29,7 +27,7 @@ class VarDecl;
 class ASTContext;
 class CompoundStmt;
 
-/// \brief Identifies a list of statements.
+/// Identifies a list of statements.
 ///
 /// Can either identify a single arbitrary Stmt object, a continuous sequence 
of
 /// child statements inside a CompoundStmt or no statements at all.
@@ -39,8 +37,8 @@ class StmtSequence {
   /// Stmt, then S is a pointer to this Stmt.
   const Stmt *S;
 
-  /// The related ASTContext for S.
-  ASTContext *Context;
+  /// The declaration that contains the statements.
+  const Decl *D;
 
   /// If EndIndex is non-zero, then S is a CompoundStmt and this StmtSequence
   /// instance is representing the CompoundStmt children inside the array
@@ -49,7 +47,7 @@ class StmtSequence {
   unsigned EndIndex;
 
 public:
-  /// \brief Constructs a StmtSequence holding multiple statements.
+  /// Constructs a StmtSequence holding multiple statements.
   ///
   /// The resulting StmtSequence identifies a continuous sequence of statements
   /// in the body of the given CompoundStmt. Which statements of the body 
should
@@ -57,20 +55,20 @@ public:
   /// that describe a non-empty sub-array in the body of the given 
CompoundStmt.
   ///
   /// \param Stmt A CompoundStmt that contains all statements in its body.
-  /// \param Context The ASTContext for the given CompoundStmt.
+  /// \param Decl The Decl containing this Stmt.
   /// \param StartIndex The inclusive start index in the children array of
   ///   \p Stmt
   /// \param EndIndex The exclusive end index in the children array of \p Stmt.
-  StmtSequence(const CompoundStmt *Stmt, ASTContext ,
-   unsigned StartIndex, unsigned EndIndex);
+  StmtSequence(const CompoundStmt *Stmt, const Decl *D, unsigned StartIndex,
+   unsigned EndIndex);
 
-  /// \brief Constructs a StmtSequence holding a single statement.
+  /// Constructs a StmtSequence holding a single statement.
   ///
   /// \param Stmt An arbitrary Stmt.
-  /// \param Context The ASTContext for the given Stmt.
-  StmtSequence(const Stmt *Stmt, ASTContext );
+  /// \param Decl The Decl containing this Stmt.
+  StmtSequence(const Stmt *Stmt, const Decl *D);
 
-  /// \brief Constructs an empty StmtSequence.
+  /// Constructs an empty StmtSequence.
   StmtSequence();
 
   typedef const Stmt *const *iterator;
@@ -110,9 +108,12 @@ public:
   bool empty() const { return size() == 0; }
 
   /// Returns the related ASTContext for the stored Stmts.
-  ASTContext () const {
-assert(Context);
-return *Context;
+  ASTContext () const;
+
+  /// Returns the declaration that contains the stored Stmts.
+  const Decl *getContainingDecl() const {
+assert(D);
+return D;
   }
 
   /// Returns true if this objects holds a list of statements.
@@ -150,106 +151,214 @@ public:
   bool contains(const StmtSequence ) const;
 };
 
-/// \brief Searches for clones in source code.
+/// Searches for similar subtrees in the AST.
 ///
-/// First, this class needs a translation unit which is passed via
-/// \p analyzeTranslationUnit . It will then generate and store search data
-/// for all statements inside the given translation unit.

[PATCH] D31709: [NFC] Refactor DiagnosticRenderer to use FullSourceLoc

2017-04-05 Thread Sanne Wouda via Phabricator via cfe-commits
sanwou01 created this revision.

Move the DiagnosticRenderer and its dependents to using FullSourceLocs
instead of a SourceLocation and SourceManager pointer.  The changeset is
rather large but entirely mechanical.

This is step one to allow DiagnosticRenderer to take either
llvmn::SMLocs or clang::SourceLocations. The end goal is 
https://reviews.llvm.org/D31501.


https://reviews.llvm.org/D31709

Files:
  include/clang/Basic/SourceLocation.h
  include/clang/Frontend/DiagnosticRenderer.h
  include/clang/Frontend/TextDiagnostic.h
  lib/Basic/SourceLocation.cpp
  lib/Frontend/DiagnosticRenderer.cpp
  lib/Frontend/SerializedDiagnosticPrinter.cpp
  lib/Frontend/TextDiagnostic.cpp
  lib/Frontend/TextDiagnosticPrinter.cpp
  tools/libclang/CIndexDiagnostic.cpp

Index: tools/libclang/CIndexDiagnostic.cpp
===
--- tools/libclang/CIndexDiagnostic.cpp
+++ tools/libclang/CIndexDiagnostic.cpp
@@ -110,40 +110,36 @@
   CurrentSet = ();
   }
 
-  void emitDiagnosticMessage(SourceLocation Loc, PresumedLoc PLoc,
+  void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc,
  DiagnosticsEngine::Level Level,
  StringRef Message,
  ArrayRef Ranges,
- const SourceManager *SM,
  DiagOrStoredDiag D) override {
 if (!D.isNull())
   return;
 
 CXSourceLocation L;
-if (SM)
-  L = translateSourceLocation(*SM, LangOpts, Loc);
+if (Loc.hasManager())
+  L = translateSourceLocation(Loc.getManager(), LangOpts, Loc);
 else
   L = clang_getNullLocation();
 CurrentSet->appendDiagnostic(
 llvm::make_unique(Message, L));
   }
 
-  void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
+  void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
  DiagnosticsEngine::Level Level,
- ArrayRef Ranges,
- const SourceManager ) override {}
+ ArrayRef Ranges) override {}
 
-  void emitCodeContext(SourceLocation Loc,
+  void emitCodeContext(FullSourceLoc Loc,
DiagnosticsEngine::Level Level,
SmallVectorImpl& Ranges,
-   ArrayRef Hints,
-   const SourceManager ) override {}
+   ArrayRef Hints) override {}
 
-  void emitNote(SourceLocation Loc, StringRef Message,
-const SourceManager *SM) override {
+  void emitNote(FullSourceLoc Loc, StringRef Message) override {
 CXSourceLocation L;
-if (SM)
-  L = translateSourceLocation(*SM, LangOpts, Loc);
+if (Loc.hasManager())
+  L = translateSourceLocation(Loc.getManager(), LangOpts, Loc);
 else
   L = clang_getNullLocation();
 CurrentSet->appendDiagnostic(
Index: lib/Frontend/TextDiagnosticPrinter.cpp
===
--- lib/Frontend/TextDiagnosticPrinter.cpp
+++ lib/Frontend/TextDiagnosticPrinter.cpp
@@ -150,10 +150,9 @@
  "Unexpected diagnostic with no source manager");
   assert(TextDiag && "Unexpected diagnostic outside source file processing");
 
-  TextDiag->emitDiagnostic(Info.getLocation(), Level, DiagMessageStream.str(),
+  TextDiag->emitDiagnostic(FullSourceLoc(Info.getLocation(), Info.getSourceManager()), Level, DiagMessageStream.str(),
Info.getRanges(),
-   Info.getFixItHints(),
-   ());
+   Info.getFixItHints());
 
   OS.flush();
 }
Index: lib/Frontend/TextDiagnostic.cpp
===
--- lib/Frontend/TextDiagnostic.cpp
+++ lib/Frontend/TextDiagnostic.cpp
@@ -673,18 +673,17 @@
 TextDiagnostic::~TextDiagnostic() {}
 
 void
-TextDiagnostic::emitDiagnosticMessage(SourceLocation Loc,
+TextDiagnostic::emitDiagnosticMessage(FullSourceLoc Loc,
   PresumedLoc PLoc,
   DiagnosticsEngine::Level Level,
   StringRef Message,
   ArrayRef Ranges,
-  const SourceManager *SM,
   DiagOrStoredDiag D) {
   uint64_t StartOfLocationInfo = OS.tell();
 
   // Emit the location of this particular diagnostic.
   if (Loc.isValid())
-emitDiagnosticLoc(Loc, PLoc, Level, Ranges, *SM);
+emitDiagnosticLoc(Loc, PLoc, Level, Ranges);
   
   if (DiagOpts->ShowColors)
 OS.resetColor();
@@ -787,17 +786,16 @@
 /// This includes extracting as much location information as is present for
 /// the diagnostic and printing it, as well as any include stack or source
 /// ranges necessary.
-void TextDiagnostic::emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
+void 

r299543 - clang-format-vsix: Add "Format on Save" feature

2017-04-05 Thread Antonio Maiorano via cfe-commits
Author: amaiorano
Date: Wed Apr  5 09:13:45 2017
New Revision: 299543

URL: http://llvm.org/viewvc/llvm-project?rev=299543=rev
Log:
clang-format-vsix: Add "Format on Save" feature

This change adds a feature to the clang-format VS extension that optionally
enables the automatic formatting of documents when saving. Since developers
always need to save their files, this eases the workflow of making sure source
files are properly formatted.

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

Added:

cfe/trunk/tools/clang-format-vs/ClangFormat/RunningDocTableEventsDispatcher.cs
cfe/trunk/tools/clang-format-vs/ClangFormat/Vsix.cs
Modified:
cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormat.csproj
cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs

Modified: cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormat.csproj
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormat.csproj?rev=299543=299542=299543=diff
==
--- cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormat.csproj (original)
+++ cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormat.csproj Wed Apr  5 
09:13:45 2017
@@ -214,6 +214,8 @@
 
 
 
+
+
   
   
 

Modified: cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs?rev=299543=299542=299543=diff
==
--- cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs (original)
+++ cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs Wed Apr  
5 09:13:45 2017
@@ -12,12 +12,11 @@
 //
 
//===--===//
 
-using Microsoft.VisualStudio.Editor;
+using EnvDTE;
 using Microsoft.VisualStudio.Shell;
 using Microsoft.VisualStudio.Shell.Interop;
 using Microsoft.VisualStudio.Text;
 using Microsoft.VisualStudio.Text.Editor;
-using Microsoft.VisualStudio.TextManager.Interop;
 using System;
 using System.Collections;
 using System.ComponentModel;
@@ -25,6 +24,7 @@ using System.ComponentModel.Design;
 using System.IO;
 using System.Runtime.InteropServices;
 using System.Xml.Linq;
+using System.Linq;
 
 namespace LLVM.ClangFormat
 {
@@ -36,6 +36,17 @@ namespace LLVM.ClangFormat
 private string fallbackStyle = "LLVM";
 private bool sortIncludes = false;
 private string style = "file";
+private bool formatOnSave = false;
+private string formatOnSaveFileExtensions =
+".c;.cpp;.cxx;.cc;.tli;.tlh;.h;.hh;.hpp;.hxx;.hh;.inl" +
+".java;.js;.ts;.m;.mm;.proto;.protodevel;.td";
+
+public OptionPageGrid Clone()
+{
+// Use MemberwiseClone to copy value types.
+var clone = (OptionPageGrid)MemberwiseClone();
+return clone;
+}
 
 public class StyleConverter : TypeConverter
 {
@@ -74,7 +85,7 @@ namespace LLVM.ClangFormat
 }
 }
 
-[Category("LLVM/Clang")]
+[Category("Format Options")]
 [DisplayName("Style")]
 [Description("Coding style, currently supports:\n" +
  "  - Predefined styles ('LLVM', 'Google', 'Chromium', 
'Mozilla', 'WebKit').\n" +
@@ -121,7 +132,7 @@ namespace LLVM.ClangFormat
 }
 }
 
-[Category("LLVM/Clang")]
+[Category("Format Options")]
 [DisplayName("Assume Filename")]
 [Description("When reading from stdin, clang-format assumes this " +
  "filename to look for a style config file (with 'file' 
style) " +
@@ -142,7 +153,7 @@ namespace LLVM.ClangFormat
 }
 }
 
-[Category("LLVM/Clang")]
+[Category("Format Options")]
 [DisplayName("Fallback Style")]
 [Description("The name of the predefined style used as a fallback in 
case clang-format " +
  "is invoked with 'file' style, but can not find the 
configuration file.\n" +
@@ -154,7 +165,7 @@ namespace LLVM.ClangFormat
 set { fallbackStyle = value; }
 }
 
-[Category("LLVM/Clang")]
+[Category("Format Options")]
 [DisplayName("Sort includes")]
 [Description("Sort touched include lines.\n\n" +
  "See also: http://clang.llvm.org/docs/ClangFormat.html.;)]
@@ -163,20 +174,48 @@ namespace LLVM.ClangFormat
 get { return sortIncludes; }
 set { sortIncludes = value; }
 }
+
+[Category("Format On Save")]
+[DisplayName("Enable")]
+[Description("Enable running clang-format when modified files are 
saved. " +
+ "Will only format if Style is found (ignores Fallback 
Style)."
+)]
+public bool FormatOnSave
+{
+

[PATCH] D29221: clang-format-vsix: "format on save" feature

2017-04-05 Thread Antonio Maiorano via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL299543: clang-format-vsix: Add "Format on Save" feature 
(authored by amaiorano).

Changed prior to commit:
  https://reviews.llvm.org/D29221?vs=89815=94225#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29221

Files:
  cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormat.csproj
  cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs
  cfe/trunk/tools/clang-format-vs/ClangFormat/RunningDocTableEventsDispatcher.cs
  cfe/trunk/tools/clang-format-vs/ClangFormat/Vsix.cs

Index: cfe/trunk/tools/clang-format-vs/ClangFormat/RunningDocTableEventsDispatcher.cs
===
--- cfe/trunk/tools/clang-format-vs/ClangFormat/RunningDocTableEventsDispatcher.cs
+++ cfe/trunk/tools/clang-format-vs/ClangFormat/RunningDocTableEventsDispatcher.cs
@@ -0,0 +1,79 @@
+using EnvDTE;
+using Microsoft.VisualStudio;
+using Microsoft.VisualStudio.Shell;
+using Microsoft.VisualStudio.Shell.Interop;
+using System.Linq;
+
+namespace LLVM.ClangFormat
+{
+// Exposes event sources for IVsRunningDocTableEvents3 events.
+internal sealed class RunningDocTableEventsDispatcher : IVsRunningDocTableEvents3
+{
+private RunningDocumentTable _runningDocumentTable;
+private DTE _dte;
+
+public delegate void OnBeforeSaveHander(object sender, Document document);
+public event OnBeforeSaveHander BeforeSave;
+
+public RunningDocTableEventsDispatcher(Package package)
+{
+_runningDocumentTable = new RunningDocumentTable(package);
+_runningDocumentTable.Advise(this);
+_dte = (DTE)Package.GetGlobalService(typeof(DTE));
+}
+
+public int OnAfterAttributeChange(uint docCookie, uint grfAttribs)
+{
+return VSConstants.S_OK;
+}
+
+public int OnAfterAttributeChangeEx(uint docCookie, uint grfAttribs, IVsHierarchy pHierOld, uint itemidOld, string pszMkDocumentOld, IVsHierarchy pHierNew, uint itemidNew, string pszMkDocumentNew)
+{
+return VSConstants.S_OK;
+}
+
+public int OnAfterDocumentWindowHide(uint docCookie, IVsWindowFrame pFrame)
+{
+return VSConstants.S_OK;
+}
+
+public int OnAfterFirstDocumentLock(uint docCookie, uint dwRDTLockType, uint dwReadLocksRemaining, uint dwEditLocksRemaining)
+{
+return VSConstants.S_OK;
+}
+
+public int OnAfterSave(uint docCookie)
+{
+return VSConstants.S_OK;
+}
+
+public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame pFrame)
+{
+return VSConstants.S_OK;
+}
+
+public int OnBeforeLastDocumentUnlock(uint docCookie, uint dwRDTLockType, uint dwReadLocksRemaining, uint dwEditLocksRemaining)
+{
+return VSConstants.S_OK;
+}
+
+public int OnBeforeSave(uint docCookie)
+{
+if (BeforeSave != null)
+{
+var document = FindDocumentByCookie(docCookie);
+if (document != null) // Not sure why this happens sometimes
+{
+BeforeSave(this, FindDocumentByCookie(docCookie));
+}
+}
+return VSConstants.S_OK;
+}
+
+private Document FindDocumentByCookie(uint docCookie)
+{
+var documentInfo = _runningDocumentTable.GetDocumentInfo(docCookie);
+return _dte.Documents.Cast().FirstOrDefault(doc => doc.FullName == documentInfo.Moniker);
+}
+}
+}
Index: cfe/trunk/tools/clang-format-vs/ClangFormat/Vsix.cs
===
--- cfe/trunk/tools/clang-format-vs/ClangFormat/Vsix.cs
+++ cfe/trunk/tools/clang-format-vs/ClangFormat/Vsix.cs
@@ -0,0 +1,96 @@
+using EnvDTE;
+using Microsoft.VisualStudio.Editor;
+using Microsoft.VisualStudio.Shell;
+using Microsoft.VisualStudio.Shell.Interop;
+using Microsoft.VisualStudio.Text;
+using Microsoft.VisualStudio.Text.Editor;
+using Microsoft.VisualStudio.TextManager.Interop;
+using System;
+using System.IO;
+
+namespace LLVM.ClangFormat
+{
+internal sealed class Vsix
+{
+/// 
+/// Returns the currently active view if it is a IWpfTextView.
+/// 
+public static IWpfTextView GetCurrentView()
+{
+// The SVsTextManager is a service through which we can get the active view.
+var textManager = (IVsTextManager)Package.GetGlobalService(typeof(SVsTextManager));
+IVsTextView textView;
+textManager.GetActiveView(1, null, out textView);
+
+// Now we have the active view as IVsTextView, but the text interfaces we need
+// are in the IWpfTextView.
+return VsToWpfTextView(textView);
+}
+
+public 

r299541 - -Wunreachable-code: 'true' and 'false' should not be treated as configuration

2017-04-05 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Wed Apr  5 09:07:21 2017
New Revision: 299541

URL: http://llvm.org/viewvc/llvm-project?rev=299541=rev
Log:
-Wunreachable-code: 'true' and 'false' should not be treated as configuration
macros

Clang should emit -Wunreachable-code warnings in C mode for code that's
unreachable because of a 'false' or '!true' condition.

Modified:
cfe/trunk/lib/Analysis/ReachableCode.cpp
cfe/trunk/test/Sema/warn-unreachable.c

Modified: cfe/trunk/lib/Analysis/ReachableCode.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ReachableCode.cpp?rev=299541=299540=299541=diff
==
--- cfe/trunk/lib/Analysis/ReachableCode.cpp (original)
+++ cfe/trunk/lib/Analysis/ReachableCode.cpp Wed Apr  5 09:07:21 2017
@@ -132,15 +132,21 @@ static bool isExpandedFromConfigurationM
   // so that we can refine it later.
   SourceLocation L = S->getLocStart();
   if (L.isMacroID()) {
+SourceManager  = PP.getSourceManager();
 if (IgnoreYES_NO) {
   // The Objective-C constant 'YES' and 'NO'
   // are defined as macros.  Do not treat them
   // as configuration values.
-  SourceManager  = PP.getSourceManager();
   SourceLocation TopL = getTopMostMacro(L, SM);
   StringRef MacroName = PP.getImmediateMacroName(TopL);
   if (MacroName == "YES" || MacroName == "NO")
 return false;
+} else if (!PP.getLangOpts().CPlusPlus) {
+  // Do not treat C 'false' and 'true' macros as configuration values.
+  SourceLocation TopL = getTopMostMacro(L, SM);
+  StringRef MacroName = PP.getImmediateMacroName(TopL);
+  if (MacroName == "false" || MacroName == "true")
+return false;
 }
 return true;
   }

Modified: cfe/trunk/test/Sema/warn-unreachable.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-unreachable.c?rev=299541=299540=299541=diff
==
--- cfe/trunk/test/Sema/warn-unreachable.c (original)
+++ cfe/trunk/test/Sema/warn-unreachable.c Wed Apr  5 09:07:21 2017
@@ -451,3 +451,13 @@ void unaryOpFixitCastSubExpr(int x) {
 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:15-[[@LINE-2]]:15}:")"
   unaryOpFixitCastSubExpr(x); // expected-warning {{code will never be 
executed}}
 }
+
+#define false 0
+#define true 1
+
+void testTrueFalseMacros() {
+  if (false) // expected-note {{silence by adding parentheses to mark code as 
explicitly dead}}
+testTrueFalseMacros(); // expected-warning {{code will never be executed}}
+  if (!true) // expected-note {{silence by adding parentheses to mark code as 
explicitly dead}}
+testTrueFalseMacros(); // expected-warning {{code will never be executed}}
+}


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


[PATCH] D25866: [Sema] Support implicit scalar to vector conversions

2017-04-05 Thread Simon Dardis via Phabricator via cfe-commits
sdardis marked an inline comment as done.
sdardis added a comment.

Thanks for sticking with this.

I've held off updating the diff until https://reviews.llvm.org/D31667 (not 
https://reviews.llvm.org/D31337 as previously posted) is finished. Responses 
inlined.




Comment at: lib/Sema/SemaExpr.cpp:8188
+  //type and then perform the rest of the checks here. GCC as of
+  //pre-release 7.0 does not accept this though.
+  if (VectorEltTy->isIntegralType(S.Context) &&

bruno wrote:
> Is this something that GCC is going to support at some point? Regardless of 
> GCC, do we want this behavior?
> Is this something that GCC is going to support at some point?

I've reread GCC's source for conversions of scalar to vectors types and it 
appears that GCC does attempt to convert constant real expressions to integers 
but it appears to only work for C++. It's a little odd.

> Regardless of GCC, do we want this behavior?

Given my oversight of the support of implicit safe conversions of floating 
point constants to integer types, I believe we should do this in general. I'll 
rework the comment to be more accurate and add the necessary conversion checks.



Comment at: lib/Sema/SemaExpr.cpp:10019
   isa(vType->getAs()) || getLangOpts().OpenCL;
+  if ((!getLangOpts().CPlusPlus && !getLangOpts().OpenCL) && !isExtVectorType)
+return InvalidVectorOperands(Loc, LHS, RHS);

bruno wrote:
> Why `!getLangOpts().CPlusPlus` is a requirement here?
GCC only supports the logical operators &&, ||, ! when compiling C++.

It's noted near the bottom half of this page: 
https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html



Comment at: test/Sema/vector-g++-compat.cpp:155
+   unsigned long long d) { // expected-warning {{'long 
long' is incompatible with C++98}}
+
+  v4f32 v4f32_a = {0.4f, 0.4f, 0.4f, 0.4f};

bruno wrote:
> Remove all these extra new lines after the function signature here, in the 
> functions below and in the other added test file for c++.
Will do.


https://reviews.llvm.org/D25866



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


[PATCH] D31650: [Analyzer] Detect when function pointer is freed

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

> void *p = malloc(sizeof(fnptr));

sorry ... I guess that should be something like "void *p = malloc(100);"


Repository:
  rL LLVM

https://reviews.llvm.org/D31650



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


[PATCH] D31650: [Analyzer] Detect when function pointer is freed

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

In https://reviews.llvm.org/D31650#717691, @NoQ wrote:

> Is freeing function pointers always undefined?


I guess not.. however I don't personally see why it would be useful to allocate 
function pointers with malloc.

>   I wonder what happens if we take some JIT-enabled javascript engine, maybe 
> with some on-stack replacement of theirs, it may `malloc()` a memory and use 
> it as a function, and then eventually it'd need to free it by design. 
> However, because we're analyzing a small part of the program, we may fail to 
> see in the analyzer that the symbolic pointer originally comes from 
> `malloc()`. Would such rare but important users be able to avoid/suppress the 
> warning?

Maybe when writing JIT there is some usecase, I don't know. The code could be 
rewritten like:

  void *malloc(unsigned long);
  void free(void*);
  
  typedef void (*fnptr)(int);
  
  void allocatedFunctionPointer() {
void *p = malloc(sizeof(fnptr));
fnptr p2 = (fnptr)p;
free(p);
  }

no warning is written about this code.


Repository:
  rL LLVM

https://reviews.llvm.org/D31650



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


[PATCH] D31706: [clang-format] Handle NSString literals by merging tokens.

2017-04-05 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh created this revision.
Herald added a subscriber: klimek.

This fixes a couple of outstanding bugs:

- incorrect breaking of NSString literals containing double-width characters;
- inconsistent formatting of ObjC dictionary literals containing NSString 
literals;
- AlwaysBreakBeforeMultilineStrings ignoring implicitly-concatenated NSString 
literals.


https://reviews.llvm.org/D31706

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/ContinuationIndenter.cpp
  lib/Format/FormatTokenLexer.cpp
  lib/Format/FormatTokenLexer.h
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -4090,9 +4090,9 @@
"c\";",
Break));
 
-  // Exempt ObjC strings for now.
-  EXPECT_EQ("NSString *const kString = @\"\"\n"
-"  @\"\";",
+  EXPECT_EQ("NSString *const kString =\n"
+"@\"\"\n"
+"@\"\";",
 format("NSString *const kString = @\"\"\n"
"@\"\";",
Break));
@@ -6460,6 +6460,7 @@
   EXPECT_EQ("@\"NSString \"\n"
 "@\"literal\";",
 format("@\"NSString literal\";", getGoogleStyleWithColumns(19)));
+  verifyFormat(R"(NSString *s = @"";)", getLLVMStyleWithColumns(26));
 
   // This input makes clang-format try to split the incomplete unicode escape
   // sequence, which used to lead to a crasher.
@@ -8301,7 +8302,14 @@
   // .. or dict literals.
   verifyFormat("void f()\n"
"{\n"
-   "  [object someMethod:@{ @\"a\" : @\"b\" }];\n"
+   "  // ...\n"
+   "  [object someMethod:@{@\"a\" : @\"b\"}];\n"
+   "}",
+   AllmanBraceStyle);
+  verifyFormat("void f()\n"
+   "{\n"
+   "  // ...\n"
+   "  [object someMethod:@{a : @\"b\"}];\n"
"}",
AllmanBraceStyle);
   verifyFormat("int f()\n"
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -907,7 +907,7 @@
TT_FunctionLBrace, TT_ImplicitStringLiteral,
TT_InlineASMBrace, TT_JsFatArrow, TT_LambdaArrow,
TT_OverloadedOperator, TT_RegexLiteral,
-   TT_TemplateString))
+   TT_TemplateString, TT_ObjCStringLiteral))
   CurrentToken->Type = TT_Unknown;
 CurrentToken->Role.reset();
 CurrentToken->MatchingParen = nullptr;
@@ -1120,21 +1120,17 @@
   }
 }
 } else if (Current.is(tok::at) && Current.Next) {
-  if (Current.Next->isStringLiteral()) {
-Current.Type = TT_ObjCStringLiteral;
-  } else {
-switch (Current.Next->Tok.getObjCKeywordID()) {
-case tok::objc_interface:
-case tok::objc_implementation:
-case tok::objc_protocol:
-  Current.Type = TT_ObjCDecl;
-  break;
-case tok::objc_property:
-  Current.Type = TT_ObjCProperty;
-  break;
-default:
-  break;
-}
+  switch (Current.Next->Tok.getObjCKeywordID()) {
+  case tok::objc_interface:
+  case tok::objc_implementation:
+  case tok::objc_protocol:
+Current.Type = TT_ObjCDecl;
+break;
+  case tok::objc_property:
+Current.Type = TT_ObjCProperty;
+break;
+  default:
+break;
   }
 } else if (Current.is(tok::period)) {
   FormatToken *PreviousNoComment = Current.getPreviousNonComment();
@@ -2457,8 +2453,7 @@
   } else if (Style.Language == FormatStyle::LK_Cpp ||
  Style.Language == FormatStyle::LK_ObjC ||
  Style.Language == FormatStyle::LK_Proto) {
-if (Left.isStringLiteral() &&
-(Right.isStringLiteral() || Right.is(TT_ObjCStringLiteral)))
+if (Left.isStringLiteral() && Right.isStringLiteral())
   return true;
   }
 
Index: lib/Format/FormatTokenLexer.h
===
--- lib/Format/FormatTokenLexer.h
+++ lib/Format/FormatTokenLexer.h
@@ -47,6 +47,7 @@
   void tryMergePreviousTokens();
 
   bool tryMergeLessLess();
+  bool tryMergeNSStringLiteral();
 
   bool tryMergeTokens(ArrayRef Kinds, TokenType NewType);
 
Index: lib/Format/FormatTokenLexer.cpp
===
--- lib/Format/FormatTokenLexer.cpp
+++ lib/Format/FormatTokenLexer.cpp
@@ -64,6 +64,8 @@
 return;
   if (tryMergeLessLess())
 return;
+  if (tryMergeNSStringLiteral())
+return;
 
   if (Style.Language == FormatStyle::LK_JavaScript) {
 static const tok::TokenKind JSIdentity[] = {tok::equalequal, 

r299537 - [OpenCL] Extended diagnostics for atomic initialization

2017-04-05 Thread Egor Churaev via cfe-commits
Author: echuraev
Date: Wed Apr  5 07:47:10 2017
New Revision: 299537

URL: http://llvm.org/viewvc/llvm-project?rev=299537=rev
Log:
[OpenCL] Extended diagnostics for atomic initialization

Summary:
I saw the same changes in the following review: https://reviews.llvm.org/D17438

I don't know in that way I could determine that atomic variable was initialized 
by macro ATOMIC_VAR_INIT. Anyway I added check that atomic variables can be 
initialize only in global scope.
I think that we can discuss this change.

Reviewers: Anastasia, cfe-commits

Reviewed By: Anastasia

Subscribers: bader, yaxunl

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

Added:
cfe/trunk/test/SemaOpenCL/atomic-init.cl
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/Parser/opencl-atomics-cl20.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=299537=299536=299537=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Apr  5 07:47:10 
2017
@@ -8286,9 +8286,9 @@ def err_opencl_return_value_with_address
   "return value cannot be qualified with address space">;
 def err_opencl_constant_no_init : Error<
   "variable in constant address space must be initialized">;
-def err_atomic_init_constant : Error<
-  "atomic variable can only be assigned to a compile time constant"
-  " in the declaration statement in the program scope">;
+def err_opencl_atomic_init: Error<
+  "atomic variable can be %select{assigned|initialized}0 to a variable only "
+  "in global address space">;
 def err_opencl_implicit_vector_conversion : Error<
   "implicit conversions between vector types (%0 and %1) are not permitted">;
 def err_opencl_invalid_type_array : Error<

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=299537=299536=299537=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Apr  5 07:47:10 2017
@@ -11121,7 +11121,7 @@ ExprResult Sema::CreateBuiltinBinOp(Sour
 if (LHSTy->isAtomicType() || RHSTy->isAtomicType()) {
   SourceRange SR(LHSExpr->getLocStart(), RHSExpr->getLocEnd());
   if (BO_Assign == Opc)
-Diag(OpLoc, diag::err_atomic_init_constant) << SR;
+Diag(OpLoc, diag::err_opencl_atomic_init) << 0 << SR;
   else
 ResultTy = InvalidOperands(OpLoc, LHS, RHS);
   return ExprError();

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=299537=299536=299537=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Apr  5 07:47:10 2017
@@ -6502,6 +6502,20 @@ InitializationSequence::Perform(Sema ,
   << Init->getSourceRange();
   }
 
+  // OpenCL v2.0 s6.13.11.1. atomic variables can be initialized in global 
scope
+  QualType ETy = Entity.getType();
+  Qualifiers TyQualifiers = ETy.getQualifiers();
+  bool HasGlobalAS = TyQualifiers.hasAddressSpace() &&
+ TyQualifiers.getAddressSpace() == LangAS::opencl_global;
+
+  if (S.getLangOpts().OpenCLVersion >= 200 &&
+  ETy->isAtomicType() && !HasGlobalAS &&
+  Entity.getKind() == InitializedEntity::EK_Variable && Args.size() > 0) {
+S.Diag(Args[0]->getLocStart(), diag::err_opencl_atomic_init) << 1 <<
+SourceRange(Entity.getDecl()->getLocStart(), Args[0]->getLocEnd());
+return ExprError();
+  }
+
   // Diagnose cases where we initialize a pointer to an array temporary, and 
the
   // pointer obviously outlives the temporary.
   if (Args.size() == 1 && Args[0]->getType()->isArrayType() &&

Modified: cfe/trunk/test/Parser/opencl-atomics-cl20.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/opencl-atomics-cl20.cl?rev=299537=299536=299537=diff
==
--- cfe/trunk/test/Parser/opencl-atomics-cl20.cl (original)
+++ cfe/trunk/test/Parser/opencl-atomics-cl20.cl Wed Apr  5 07:47:10 2017
@@ -67,7 +67,7 @@ void atomic_ops_test() {
   foo();
 // OpenCL v2.0 s6.13.11.8, arithemtic operations are not permitted on atomic 
types.
   i++; // expected-error {{invalid argument type 'atomic_int' (aka 
'_Atomic(int)') to unary expression}}
-  i = 1; // expected-error {{atomic variable can only be assigned to a compile 
time constant in the declaration statement in the program scope}}
+  i = 1; // expected-error {{atomic variable can be assigned to a variable 
only in global address space}}
   i += 1; // 

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

2017-04-05 Thread Alex L via cfe-commits
On 5 April 2017 at 13:38, Duncan Exon Smith  wrote:

>
>
> > On Apr 5, 2017, at 05:13, Aaron Ballman via Phabricator <
> revi...@reviews.llvm.org> wrote:
> >
> > aaron.ballman added inline comments.
> >
> >
> > 
> > Comment at: lib/Sema/SemaAttr.cpp:578
> > +return;
> > +  Diag(PragmaAttributeStack.back().Loc, diag::warn_pragm_attribute_no_
> pop_eof);
> > +}
> > 
> > arphaman wrote:
> >> aaron.ballman wrote:
> >>> Perhaps adding a FixIt here would be a kindness?
> >> Where would the fix-it point to? I think only the user will know the
> location at which they meant to insert `#pragma clang attribute pop`.
> > Given that it's a warning rather than an error, and our recovery
> mechanism is to effectively pop the pragma at the end of the TU, I was
> thinking it could be added at the end of the TU. However, you are correct
> that it's probably not where the programmer needs it,
>
> What about at the end of the file the push is in?  This is likely to be
> used in header files, and it's probably unintentional if it extends past
> the end of the file of the push.
>

Then we'd have to take into account preprocessor directives, as we'd
obviously want to insert it before the '#endif'. Or if the user used
`#pragma once`  then the end of the file could probably work.
IMHO the improvement can be done as a follow-up that improves this and
other pragmas like #pragma pack.


> I think we should consider the same thing for #pragma pack (although
> that's a little off-topic).
>
> > so a FixIt likely isn't appropriate. Does that suggest the warning
> should be an error instead?
>
> Maybe it should be an error, but I still think a fixit would be nice if we
> can find a spot.
>
> >
> >
> > Repository:
> >  rL LLVM
> >
> > https://reviews.llvm.org/D30009
> >
> >
> >
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2017-04-05 Thread Duncan Exon Smith via cfe-commits


> On Apr 5, 2017, at 05:13, Aaron Ballman via Phabricator 
>  wrote:
> 
> aaron.ballman added inline comments.
> 
> 
> 
> Comment at: lib/Sema/SemaAttr.cpp:578
> +return;
> +  Diag(PragmaAttributeStack.back().Loc, 
> diag::warn_pragm_attribute_no_pop_eof);
> +}
> 
> arphaman wrote:
>> aaron.ballman wrote:
>>> Perhaps adding a FixIt here would be a kindness?
>> Where would the fix-it point to? I think only the user will know the 
>> location at which they meant to insert `#pragma clang attribute pop`.
> Given that it's a warning rather than an error, and our recovery mechanism is 
> to effectively pop the pragma at the end of the TU, I was thinking it could 
> be added at the end of the TU. However, you are correct that it's probably 
> not where the programmer needs it,

What about at the end of the file the push is in?  This is likely to be used in 
header files, and it's probably unintentional if it extends past the end of the 
file of the push. 

I think we should consider the same thing for #pragma pack (although that's a 
little off-topic).

> so a FixIt likely isn't appropriate. Does that suggest the warning should be 
> an error instead?

Maybe it should be an error, but I still think a fixit would be nice if we can 
find a spot. 

> 
> 
> Repository:
>  rL LLVM
> 
> https://reviews.llvm.org/D30009
> 
> 
> 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31667: [Sema] Extend GetSignedVectorType to deal with non ExtVector types

2017-04-05 Thread Simon Dardis via Phabricator via cfe-commits
sdardis updated this revision to Diff 94205.
sdardis marked 5 inline comments as done.
sdardis added a comment.

Addressed review comments, added more tests.


https://reviews.llvm.org/D31667

Files:
  lib/Sema/SemaExpr.cpp
  test/Sema/vector-ops.c

Index: test/Sema/vector-ops.c
===
--- test/Sema/vector-ops.c
+++ test/Sema/vector-ops.c
@@ -13,9 +13,9 @@
   (void)(~v2fa); // expected-error{{invalid argument type 'v2f' (vector of 2 'float' values) to unary}}
 
   // Comparison operators
-  v2ua = (v2ua==v2sa); // expected-warning{{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from 'int __attribute__((ext_vector_type(2)))' (vector of 2 'int' values)}}
+  v2ua = (v2ua==v2sa); // expected-warning{{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from '__attribute__((__vector_size__(2 * sizeof(int int' (vector of 2 'int' values)}}
   v2sa = (v2ua==v2sa);
-  
+
   // Arrays
   int array1[v2ua]; // expected-error{{size of array has non-integer type 'v2u' (vector of 2 'unsigned int' values)}}
   int array2[17];
@@ -26,4 +26,110 @@
   v2s *v2s_ptr;
   v2s_ptr = v2u_ptr; // expected-warning{{converts between pointers to integer types with different sign}}
 }
- 
+
+void testLogicalVecVec(v2u v2ua, v2s v2sa, v2f v2fa) {
+
+  // Logical operators
+  v2ua = v2ua && v2ua; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from '__attribute__((__vector_size__(2 * sizeof(int int' (vector of 2 'int' values)}}
+  v2ua = v2ua || v2ua; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from '__attribute__((__vector_size__(2 * sizeof(int int' (vector of 2 'int' values)}}
+
+  v2ua = v2sa && v2ua; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from '__attribute__((__vector_size__(2 * sizeof(int int' (vector of 2 'int' values)}}
+  v2ua = v2sa || v2ua; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from '__attribute__((__vector_size__(2 * sizeof(int int' (vector of 2 'int' values)}}
+
+  v2ua = v2ua && v2fa; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from '__attribute__((__vector_size__(2 * sizeof(int int' (vector of 2 'int' values)}}
+  v2ua = v2ua || v2fa; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from '__attribute__((__vector_size__(2 * sizeof(int int' (vector of 2 'int' values)}}
+
+  v2ua = v2sa && v2fa; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from '__attribute__((__vector_size__(2 * sizeof(int int' (vector of 2 'int' values)}}
+  v2ua = v2sa || v2fa; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from '__attribute__((__vector_size__(2 * sizeof(int int' (vector of 2 'int' values)}}
+
+  v2sa = v2sa && v2sa;
+  v2sa = v2sa || v2sa;
+
+  v2sa = v2ua && v2ua;
+  v2sa = v2ua || v2ua;
+
+  v2sa = v2sa && v2ua;
+  v2sa = v2sa || v2ua;
+
+  v2sa = v2sa && v2fa;
+  v2sa = v2sa || v2fa;
+
+  v2sa = v2ua && v2fa;
+  v2sa = v2ua || v2fa;
+
+  v2fa = v2fa && v2fa; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from '__attribute__((__vector_size__(2 * sizeof(int int' (vector of 2 'int' values)}}
+  v2fa = v2fa || v2fa; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from '__attribute__((__vector_size__(2 * sizeof(int int' (vector of 2 'int' values)}}
+
+  v2fa = v2sa && v2fa; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from '__attribute__((__vector_size__(2 * sizeof(int int' (vector of 2 'int' values)}}
+  v2fa = v2sa || v2fa; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from '__attribute__((__vector_size__(2 * sizeof(int int' (vector of 2 'int' values)}}
+
+  v2fa = v2ua && v2fa; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from '__attribute__((__vector_size__(2 * sizeof(int int' (vector of 2 'int' values)}}
+  v2fa = v2ua || v2fa; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from '__attribute__((__vector_size__(2 * sizeof(int int' (vector of 2 'int' values)}}
+
+  v2fa = v2ua && v2ua; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from '__attribute__((__vector_size__(2 * sizeof(int int' (vector of 2 'int' values)}}
+  v2fa = v2ua || v2ua; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from 

[PATCH] D31591: Fix a bug which access nullptr and cause segmentation fault

2017-04-05 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

@yamaguchi, I'd support Akira's comment. Could you place the minimal test 
example in the suggested file?


https://reviews.llvm.org/D31591



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


[PATCH] D30909: [Analyzer] Finish taint propagation to derived symbols of tainted regions

2017-04-05 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:494
+  SymbolManager  = C.getSymbolManager();
+  return SM.getDerivedSymbol(Sym, LCV.getRegion());
 }

vlad.tsyrklevich wrote:
> NoQ wrote:
> > I'd think about this a bit more and come back.
> > 
> > I need to understand how come that constructing a symbol manually is the 
> > right thing to do; that doesn't happen very often, but it seems correct 
> > here.
> Indeed it is odd. The best justification I could come up with: LCVs are meant 
> to be optimizations, their 'purpose' is to expose an SVal that hides 
> SymbolRef values so that we can have a split store. We don't have to copy all 
> of a compound values SymbolRef mappings because LCVs are kept distinct. Hence 
> to set/query/constrain region values you use SVals so that RegionStore can 
> differentiate between LCVs and SymbolRef backed SVals for the two different 
> stores it contains.
> 
> The taint interface however requires you taint a SymbolRef, not an SVal. If 
> we wanted, instead of doing this logic here, we could change 
> getPointedToSymbol() to return an SVal and update usages of it accordingly 
> since that value is only passed on to 
> ProgramState.isTainted()/ProgramState.addTaint() anyway. Then we could update 
> addTaint/isTainted to perform this logic, hiding it from the checker.
> 
> This still requires manually constructing a symbol, now it's just performed 
> in the analyzer instead of in a checker. Not sure if that addresses the issue 
> you were considering, but the idea that we need to 'undo' the LCV 
> optimization hiding the SymbolRef to have a value to taint seems somewhat 
> convincing to me. What do you think?
Hmm (!) I suggest adding a new function to the program state, that we'd call 
`addPartialTaint()` or something like that, and this function would accept a 
symbol and a region and would act identically to passing a derived symbol (from 
this symbol and that region) to `addTaint()` (but we wouldn't need to actually 
construct a derived symbol here).

Such API would be easier to understand and use than the current approach that 
forces the user to construct a derived symbol manually in the checker code. 
Unfortunately, this checker's `getLCVSymbol()` would become a bit more 
complicated (having various return types depending on circumstances), but this 
misfortune seems more random than systematic to me.

Since we're having this new kind of partial taint, why don't we expose it in 
the API.



Comment at: test/Analysis/taint-generic.c:210
+  read(sock, , sizeof(tainted.st));
+  __builtin_memcpy(buffer, tainted.buf, tainted.st[0].length); // 
expected-warning {{Untrusted data is used to specify the buffer size}}
 }

vlad.tsyrklevich wrote:
> NoQ wrote:
> > Are we already supporting the case when we're tainting some elements of an 
> > array but not all of them, and this works as expected? Could we add such 
> > tests (regardless of whether we already handle them)?
> It does work in that case. If you taint element X of region Y the current 
> logic will be conservative and only mark element X as tainted, not X-i or 
> X+i. This is also true for element 0, so if a programmer passes [0] but 
> reads sizeof(array) bytes it will not correctly mark that. This is also a 
> short coming of the invalidation code so I don't think there's much to do 
> until there's more general support for dealing with region extents.
\o/


https://reviews.llvm.org/D30909



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


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

2017-04-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: lib/Sema/SemaAttr.cpp:578
+return;
+  Diag(PragmaAttributeStack.back().Loc, diag::warn_pragm_attribute_no_pop_eof);
+}

arphaman wrote:
> aaron.ballman wrote:
> > Perhaps adding a FixIt here would be a kindness?
> Where would the fix-it point to? I think only the user will know the location 
> at which they meant to insert `#pragma clang attribute pop`.
Given that it's a warning rather than an error, and our recovery mechanism is 
to effectively pop the pragma at the end of the TU, I was thinking it could be 
added at the end of the TU. However, you are correct that it's probably not 
where the programmer needs it, so a FixIt likely isn't appropriate. Does that 
suggest the warning should be an error instead?


Repository:
  rL LLVM

https://reviews.llvm.org/D30009



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


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

2017-04-05 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: lib/Sema/SemaAttr.cpp:578
+return;
+  Diag(PragmaAttributeStack.back().Loc, diag::warn_pragm_attribute_no_pop_eof);
+}

aaron.ballman wrote:
> Perhaps adding a FixIt here would be a kindness?
Where would the fix-it point to? I think only the user will know the location 
at which they meant to insert `#pragma clang attribute pop`.


Repository:
  rL LLVM

https://reviews.llvm.org/D30009



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


[PATCH] D31698: clang-format: [JS] fix whitespace around "of" operator.

2017-04-05 Thread Martin Probst via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL299533: clang-format: [JS] fix whitespace around "of" 
operator. (authored by mprobst).

Changed prior to commit:
  https://reviews.llvm.org/D31698?vs=94188=94189#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D31698

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTestJS.cpp


Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -132,6 +132,8 @@
   verifyFormat("x.interface = 1;");
   verifyFormat("x.for = 1;");
   verifyFormat("x.of() = 1;");
+  verifyFormat("of(null);");
+  verifyFormat("import {of} from 'x';");
   verifyFormat("x.in() = 1;");
   verifyFormat("x.let() = 1;");
   verifyFormat("x.var() = 1;");
Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2270,8 +2270,12 @@
 if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
 Left.Tok.getIdentifierInfo())
   return false;
-if (Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
- Keywords.kw_of, tok::kw_const) &&
+if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
+  tok::kw_const) ||
+ // "of" is only a keyword if it appears after another identifier
+ // (e.g. as "const x of y" in a for loop).
+ (Left.is(Keywords.kw_of) && Left.Previous &&
+  Left.Previous->Tok.getIdentifierInfo())) &&
 (!Left.Previous || !Left.Previous->is(tok::period)))
   return true;
 if (Left.isOneOf(tok::kw_for, Keywords.kw_as) && Left.Previous &&


Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -132,6 +132,8 @@
   verifyFormat("x.interface = 1;");
   verifyFormat("x.for = 1;");
   verifyFormat("x.of() = 1;");
+  verifyFormat("of(null);");
+  verifyFormat("import {of} from 'x';");
   verifyFormat("x.in() = 1;");
   verifyFormat("x.let() = 1;");
   verifyFormat("x.var() = 1;");
Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2270,8 +2270,12 @@
 if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
 Left.Tok.getIdentifierInfo())
   return false;
-if (Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
- Keywords.kw_of, tok::kw_const) &&
+if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
+  tok::kw_const) ||
+ // "of" is only a keyword if it appears after another identifier
+ // (e.g. as "const x of y" in a for loop).
+ (Left.is(Keywords.kw_of) && Left.Previous &&
+  Left.Previous->Tok.getIdentifierInfo())) &&
 (!Left.Previous || !Left.Previous->is(tok::period)))
   return true;
 if (Left.isOneOf(tok::kw_for, Keywords.kw_as) && Left.Previous &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r299533 - clang-format: [JS] fix whitespace around "of" operator.

2017-04-05 Thread Martin Probst via cfe-commits
Author: mprobst
Date: Wed Apr  5 05:56:07 2017
New Revision: 299533

URL: http://llvm.org/viewvc/llvm-project?rev=299533=rev
Log:
clang-format: [JS] fix whitespace around "of" operator.

Summary:
Previously:
import {of } from 'x';
of (null);

Now:
import {of} from 'x';
of(null);

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=299533=299532=299533=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Apr  5 05:56:07 2017
@@ -2270,8 +2270,12 @@ bool TokenAnnotator::spaceRequiredBefore
 if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
 Left.Tok.getIdentifierInfo())
   return false;
-if (Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
- Keywords.kw_of, tok::kw_const) &&
+if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
+  tok::kw_const) ||
+ // "of" is only a keyword if it appears after another identifier
+ // (e.g. as "const x of y" in a for loop).
+ (Left.is(Keywords.kw_of) && Left.Previous &&
+  Left.Previous->Tok.getIdentifierInfo())) &&
 (!Left.Previous || !Left.Previous->is(tok::period)))
   return true;
 if (Left.isOneOf(tok::kw_for, Keywords.kw_as) && Left.Previous &&

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=299533=299532=299533=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Wed Apr  5 05:56:07 2017
@@ -132,6 +132,8 @@ TEST_F(FormatTestJS, ReservedWords) {
   verifyFormat("x.interface = 1;");
   verifyFormat("x.for = 1;");
   verifyFormat("x.of() = 1;");
+  verifyFormat("of(null);");
+  verifyFormat("import {of} from 'x';");
   verifyFormat("x.in() = 1;");
   verifyFormat("x.let() = 1;");
   verifyFormat("x.var() = 1;");


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


[PATCH] D31698: clang-format: [JS] fix whitespace around "of" operator.

2017-04-05 Thread Martin Probst via Phabricator via cfe-commits
mprobst updated this revision to Diff 94188.
mprobst added a comment.

- improve comment


https://reviews.llvm.org/D31698

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestJS.cpp


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -132,6 +132,8 @@
   verifyFormat("x.interface = 1;");
   verifyFormat("x.for = 1;");
   verifyFormat("x.of() = 1;");
+  verifyFormat("of(null);");
+  verifyFormat("import {of} from 'x';");
   verifyFormat("x.in() = 1;");
   verifyFormat("x.let() = 1;");
   verifyFormat("x.var() = 1;");
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2270,8 +2270,12 @@
 if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
 Left.Tok.getIdentifierInfo())
   return false;
-if (Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
- Keywords.kw_of, tok::kw_const) &&
+if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
+  tok::kw_const) ||
+ // "of" is only a keyword if it appears after another identifier
+ // (e.g. as "const x of y" in a for loop).
+ (Left.is(Keywords.kw_of) && Left.Previous &&
+  Left.Previous->Tok.getIdentifierInfo())) &&
 (!Left.Previous || !Left.Previous->is(tok::period)))
   return true;
 if (Left.isOneOf(tok::kw_for, Keywords.kw_as) && Left.Previous &&


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -132,6 +132,8 @@
   verifyFormat("x.interface = 1;");
   verifyFormat("x.for = 1;");
   verifyFormat("x.of() = 1;");
+  verifyFormat("of(null);");
+  verifyFormat("import {of} from 'x';");
   verifyFormat("x.in() = 1;");
   verifyFormat("x.let() = 1;");
   verifyFormat("x.var() = 1;");
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2270,8 +2270,12 @@
 if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
 Left.Tok.getIdentifierInfo())
   return false;
-if (Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
- Keywords.kw_of, tok::kw_const) &&
+if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
+  tok::kw_const) ||
+ // "of" is only a keyword if it appears after another identifier
+ // (e.g. as "const x of y" in a for loop).
+ (Left.is(Keywords.kw_of) && Left.Previous &&
+  Left.Previous->Tok.getIdentifierInfo())) &&
 (!Left.Previous || !Left.Previous->is(tok::period)))
   return true;
 if (Left.isOneOf(tok::kw_for, Keywords.kw_as) && Left.Previous &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31540: Prefer non-friend to friend in in redeclaration chain

2017-04-05 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

Could you also add the testcase where the friend declaration has some 
attributes?


Repository:
  rL LLVM

https://reviews.llvm.org/D31540



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


[PATCH] D31702: Append -w when LLVM_ENABLE_WARNINGS is Off.

2017-04-05 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 94180.
v.g.vassilev marked an inline comment as done.
v.g.vassilev added a comment.

Ah good point. Thanks!


https://reviews.llvm.org/D31702

Files:
  cmake/modules/HandleLLVMOptions.cmake


Index: cmake/modules/HandleLLVMOptions.cmake
===
--- cmake/modules/HandleLLVMOptions.cmake
+++ cmake/modules/HandleLLVMOptions.cmake
@@ -561,6 +561,10 @@
   add_flag_if_supported("-Wstring-conversion" STRING_CONVERSION_FLAG)
 endif (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
 
+if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND NOT LLVM_ENABLE_WARNINGS)
+  append("-w" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+endif()
+
 macro(append_common_sanitizer_flags)
   if (NOT MSVC)
 # Append -fno-omit-frame-pointer and turn on debug info to get better


Index: cmake/modules/HandleLLVMOptions.cmake
===
--- cmake/modules/HandleLLVMOptions.cmake
+++ cmake/modules/HandleLLVMOptions.cmake
@@ -561,6 +561,10 @@
   add_flag_if_supported("-Wstring-conversion" STRING_CONVERSION_FLAG)
 endif (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
 
+if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND NOT LLVM_ENABLE_WARNINGS)
+  append("-w" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+endif()
+
 macro(append_common_sanitizer_flags)
   if (NOT MSVC)
 # Append -fno-omit-frame-pointer and turn on debug info to get better
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31702: Append -w when LLVM_ENABLE_WARNINGS is Off.

2017-04-05 Thread Yaron Keren via Phabricator via cfe-commits
yaron.keren added inline comments.



Comment at: cmake/modules/HandleLLVMOptions.cmake:562
   add_flag_if_supported("-Wstring-conversion" STRING_CONVERSION_FLAG)
+else()
+  append("-w" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)

note this is an else to 
if (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
so for non-gcc non-clang_cl compilers you'd also end up here.

shouldn't the condition be
if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND NOT LLVM_ENABLE_WARNINGS)



Repository:
  rL LLVM

https://reviews.llvm.org/D31702



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


[PATCH] D31702: Append -w when LLVM_ENABLE_WARNINGS is Off.

2017-04-05 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev created this revision.
Herald added a subscriber: mgorny.

This is very useful for projects which embed LLVM in their codebases.


Repository:
  rL LLVM

https://reviews.llvm.org/D31702

Files:
  cmake/modules/HandleLLVMOptions.cmake


Index: cmake/modules/HandleLLVMOptions.cmake
===
--- cmake/modules/HandleLLVMOptions.cmake
+++ cmake/modules/HandleLLVMOptions.cmake
@@ -559,6 +559,8 @@
 
   # Enable -Wstring-conversion to catch misuse of string literals.
   add_flag_if_supported("-Wstring-conversion" STRING_CONVERSION_FLAG)
+else()
+  append("-w" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
 endif (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
 
 macro(append_common_sanitizer_flags)


Index: cmake/modules/HandleLLVMOptions.cmake
===
--- cmake/modules/HandleLLVMOptions.cmake
+++ cmake/modules/HandleLLVMOptions.cmake
@@ -559,6 +559,8 @@
 
   # Enable -Wstring-conversion to catch misuse of string literals.
   add_flag_if_supported("-Wstring-conversion" STRING_CONVERSION_FLAG)
+else()
+  append("-w" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
 endif (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
 
 macro(append_common_sanitizer_flags)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31669: Fix lambda to block conversion in C++17 by avoiding copy elision for the lambda capture used by the created block

2017-04-05 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 94177.
arphaman marked 2 inline comments as done.
arphaman added a comment.

Use a new EntityKind and improve test.


Repository:
  rL LLVM

https://reviews.llvm.org/D31669

Files:
  include/clang/Sema/Initialization.h
  lib/Sema/SemaInit.cpp
  lib/Sema/SemaLambda.cpp
  test/CodeGenObjCXX/lambda-to-block.mm

Index: test/CodeGenObjCXX/lambda-to-block.mm
===
--- /dev/null
+++ test/CodeGenObjCXX/lambda-to-block.mm
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -x objective-c++ -fblocks -triple x86_64-apple-darwin10 -fobjc-runtime=macosx-fragile-10.5 -std=c++1z -emit-llvm -o - %s | FileCheck %s
+
+// rdar://31385153
+// Shouldn't crash!
+
+void takesBlock(void (^)(void));
+
+struct Copyable {
+  Copyable(const Copyable );
+};
+
+void hasLambda(Copyable x) {
+  takesBlock([x] () { });
+}
+// CHECK-LABEL: define internal void @__copy_helper_block_
+// CHECK: call void @"_ZZ9hasLambda8CopyableEN3$_0C1ERKS0_"
+// CHECK-LABEL: define internal void @"_ZZ9hasLambda8CopyableEN3$_0C2ERKS0_"
+// CHECK: call void @_ZN8CopyableC1ERKS_
Index: lib/Sema/SemaLambda.cpp
===
--- lib/Sema/SemaLambda.cpp
+++ lib/Sema/SemaLambda.cpp
@@ -1649,10 +1649,9 @@
   CallOperator->markUsed(Context);
 
   ExprResult Init = PerformCopyInitialization(
-  InitializedEntity::InitializeBlock(ConvLocation, 
- Src->getType(), 
- /*NRVO=*/false),
-  CurrentLocation, Src);
+  InitializedEntity::InitializeLambdaToBlock(ConvLocation, Src->getType(),
+ /*NRVO=*/false),
+  CurrentLocation, Src);
   if (!Init.isInvalid())
 Init = ActOnFinishFullExpr(Init.get());
   
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -950,6 +950,7 @@
   case InitializedEntity::EK_Base:
   case InitializedEntity::EK_Delegating:
   case InitializedEntity::EK_BlockElement:
+  case InitializedEntity::EK_LambdaToBlockConversionBlockElement:
   case InitializedEntity::EK_Binding:
 llvm_unreachable("unexpected braced scalar init");
   }
@@ -2934,6 +2935,7 @@
   case EK_VectorElement:
   case EK_ComplexElement:
   case EK_BlockElement:
+  case EK_LambdaToBlockConversionBlockElement:
   case EK_CompoundLiteralInit:
   case EK_RelatedResult:
 return DeclarationName();
@@ -2963,6 +2965,7 @@
   case EK_VectorElement:
   case EK_ComplexElement:
   case EK_BlockElement:
+  case EK_LambdaToBlockConversionBlockElement:
   case EK_LambdaCapture:
   case EK_CompoundLiteralInit:
   case EK_RelatedResult:
@@ -2992,6 +2995,7 @@
   case EK_VectorElement:
   case EK_ComplexElement:
   case EK_BlockElement:
+  case EK_LambdaToBlockConversionBlockElement:
   case EK_LambdaCapture:
   case EK_RelatedResult:
 break;
@@ -3025,6 +3029,9 @@
   case EK_VectorElement: OS << "VectorElement " << Index; break;
   case EK_ComplexElement: OS << "ComplexElement " << Index; break;
   case EK_BlockElement: OS << "Block"; break;
+  case EK_LambdaToBlockConversionBlockElement:
+OS << "Block (lambda)";
+break;
   case EK_LambdaCapture:
 OS << "LambdaCapture ";
 OS << DeclarationName(Capture.VarID);
@@ -3622,9 +3629,13 @@
   //   destination object.
   // Per DR (no number yet), this does not apply when initializing a base
   // class or delegating to another constructor from a mem-initializer.
+  // ObjC++: Lambda captured by the block in the lambda to block conversion
+  // should avoid copy elision.
   if (S.getLangOpts().CPlusPlus1z &&
   Entity.getKind() != InitializedEntity::EK_Base &&
   Entity.getKind() != InitializedEntity::EK_Delegating &&
+  Entity.getKind() !=
+  InitializedEntity::EK_LambdaToBlockConversionBlockElement &&
   UnwrappedArgs.size() == 1 && UnwrappedArgs[0]->isRValue() &&
   S.Context.hasSameUnqualifiedType(UnwrappedArgs[0]->getType(), DestType)) {
 // Convert qualifications if necessary.
@@ -5488,6 +5499,7 @@
   case InitializedEntity::EK_VectorElement:
   case InitializedEntity::EK_ComplexElement:
   case InitializedEntity::EK_BlockElement:
+  case InitializedEntity::EK_LambdaToBlockConversionBlockElement:
   case InitializedEntity::EK_LambdaCapture:
   case InitializedEntity::EK_CompoundLiteralInit:
 return Sema::AA_Initializing;
@@ -5511,6 +5523,7 @@
   case InitializedEntity::EK_ComplexElement:
   case InitializedEntity::EK_Exception:
   case InitializedEntity::EK_BlockElement:
+  case InitializedEntity::EK_LambdaToBlockConversionBlockElement:
   case InitializedEntity::EK_LambdaCapture:
   case InitializedEntity::EK_CompoundLiteralInit:
 return false;
@@ -5537,6 +5550,7 @@
 case InitializedEntity::EK_VectorElement:
 case 

r299524 - [OpenCL] Enables passing sampler initializer to function argument

2017-04-05 Thread Egor Churaev via cfe-commits
Author: echuraev
Date: Wed Apr  5 04:02:56 2017
New Revision: 299524

URL: http://llvm.org/viewvc/llvm-project?rev=299524=rev
Log:
[OpenCL] Enables passing sampler initializer to function argument

Reviewers: Anastasia, cfe-commits

Reviewed By: Anastasia

Subscribers: yaxunl, bader

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

Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/CodeGenOpenCL/sampler.cl
cfe/trunk/test/SemaOpenCL/sampler_t.cl

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=299524=299523=299524=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Apr  5 04:02:56 2017
@@ -7174,7 +7174,7 @@ InitializationSequence::Perform(Sema ,
   QualType SourceType = Init->getType();
   // Case 1
   if (Entity.isParameterKind()) {
-if (!SourceType->isSamplerT()) {
+if (!SourceType->isSamplerT() && !SourceType->isIntegerType()) {
   S.Diag(Kind.getLocation(), diag::err_sampler_argument_required)
 << SourceType;
   break;

Modified: cfe/trunk/test/CodeGenOpenCL/sampler.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/sampler.cl?rev=299524=299523=299524=diff
==
--- cfe/trunk/test/CodeGenOpenCL/sampler.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/sampler.cl Wed Apr  5 04:02:56 2017
@@ -54,4 +54,8 @@ kernel void foo(sampler_t smp_par) {
   fnc4smp(smp_par);
   // CHECK: [[SAMP:%[0-9]+]] = load %opencl.sampler_t addrspace(2)*, 
%opencl.sampler_t addrspace(2)** [[smp_par_ptr]]
   // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* 
[[SAMP]])
+
+  fnc4smp(5);
+  // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 5)
+  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* 
[[SAMP]])
 }

Modified: cfe/trunk/test/SemaOpenCL/sampler_t.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/sampler_t.cl?rev=299524=299523=299524=diff
==
--- cfe/trunk/test/SemaOpenCL/sampler_t.cl (original)
+++ cfe/trunk/test/SemaOpenCL/sampler_t.cl Wed Apr  5 04:02:56 2017
@@ -30,7 +30,7 @@ constant sampler_t glb_smp8 = 1.0f; // e
 
 constant sampler_t glb_smp9 = 0x1LL; // expected-error{{sampler_t 
initialization requires 32-bit integer, not 'long long'}}
 
-void foo(sampler_t);
+void foo(sampler_t); // expected-note{{passing argument to parameter here}}
 
 constant struct sampler_s {
   sampler_t smp; // expected-error{{the 'sampler_t' type cannot be used to 
declare a structure or union field}}
@@ -65,7 +65,8 @@ void kernel ker(sampler_t argsmp) {
   foo(const_smp5);
   foo(const_smp6);
   foo(argsmp);
-  foo(5); // expected-error{{sampler_t variable required - got 'int'}}
+  foo(5);
+  foo(5.0f); // expected-error {{passing 'float' to parameter of incompatible 
type 'sampler_t'}}
   sampler_t sa[] = {argsmp, const_smp}; // expected-error {{array of 
'sampler_t' type is invalid in OpenCL}}
   foo(sa[0]);
   foo(bad());


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


r299523 - [analyzer] alpha.core.Conversion - Fix false positive for 'U32 += S16; ' expression, that is not unsafe

2017-04-05 Thread Daniel Marjamaki via cfe-commits
Author: danielmarjamaki
Date: Wed Apr  5 03:57:04 2017
New Revision: 299523

URL: http://llvm.org/viewvc/llvm-project?rev=299523=rev
Log:
[analyzer] alpha.core.Conversion - Fix false positive for 'U32 += S16;' 
expression, that is not unsafe

Summary:
The alpha.core.Conversion was too strict about compound assignments and could 
warn even though there is no problem.

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


Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
cfe/trunk/test/Analysis/conversion.c

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/ConversionChecker.cpp?rev=299523=299522=299523=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/ConversionChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/ConversionChecker.cpp Wed Apr  5 
03:57:04 2017
@@ -41,7 +41,8 @@ private:
   mutable std::unique_ptr BT;
 
   // Is there loss of precision
-  bool isLossOfPrecision(const ImplicitCastExpr *Cast, CheckerContext ) 
const;
+  bool isLossOfPrecision(const ImplicitCastExpr *Cast, QualType DestType,
+ CheckerContext ) const;
 
   // Is there loss of sign
   bool isLossOfSign(const ImplicitCastExpr *Cast, CheckerContext ) const;
@@ -73,16 +74,30 @@ void ConversionChecker::checkPreStmt(con
   // Loss of sign/precision in binary operation.
   if (const auto *B = dyn_cast(Parent)) {
 BinaryOperator::Opcode Opc = B->getOpcode();
-if (Opc == BO_Assign || Opc == BO_AddAssign || Opc == BO_SubAssign ||
-Opc == BO_MulAssign) {
+if (Opc == BO_Assign) {
   LossOfSign = isLossOfSign(Cast, C);
-  LossOfPrecision = isLossOfPrecision(Cast, C);
+  LossOfPrecision = isLossOfPrecision(Cast, Cast->getType(), C);
+} else if (Opc == BO_AddAssign || Opc == BO_SubAssign) {
+  // No loss of sign.
+  LossOfPrecision = isLossOfPrecision(Cast, B->getLHS()->getType(), C);
+} else if (Opc == BO_MulAssign) {
+  LossOfSign = isLossOfSign(Cast, C);
+  LossOfPrecision = isLossOfPrecision(Cast, B->getLHS()->getType(), C);
+} else if (Opc == BO_DivAssign || Opc == BO_RemAssign) {
+  LossOfSign = isLossOfSign(Cast, C);
+  // No loss of precision.
+} else if (Opc == BO_AndAssign) {
+  LossOfSign = isLossOfSign(Cast, C);
+  // No loss of precision.
+} else if (Opc == BO_OrAssign || Opc == BO_XorAssign) {
+  LossOfSign = isLossOfSign(Cast, C);
+  LossOfPrecision = isLossOfPrecision(Cast, B->getLHS()->getType(), C);
 } else if (B->isRelationalOp() || B->isMultiplicativeOp()) {
   LossOfSign = isLossOfSign(Cast, C);
 }
   } else if (isa(Parent)) {
 LossOfSign = isLossOfSign(Cast, C);
-LossOfPrecision = isLossOfPrecision(Cast, C);
+LossOfPrecision = isLossOfPrecision(Cast, Cast->getType(), C);
   }
 
   if (LossOfSign || LossOfPrecision) {
@@ -113,6 +128,13 @@ static bool isGreaterEqual(CheckerContex
unsigned long long Val) {
   ProgramStateRef State = C.getState();
   SVal EVal = C.getSVal(E);
+  if (EVal.isUnknownOrUndef())
+return false;
+  if (!EVal.getAs() && EVal.getAs()) {
+ProgramStateManager  = C.getStateManager();
+EVal =
+Mgr.getStoreManager().getBinding(State->getStore(), 
EVal.castAs());
+  }
   if (EVal.isUnknownOrUndef() || !EVal.getAs())
 return false;
 
@@ -153,22 +175,22 @@ static bool isNegative(CheckerContext 
 }
 
 bool ConversionChecker::isLossOfPrecision(const ImplicitCastExpr *Cast,
-CheckerContext ) const {
+  QualType DestType,
+  CheckerContext ) const {
   // Don't warn about explicit loss of precision.
   if (Cast->isEvaluatable(C.getASTContext()))
 return false;
 
-  QualType CastType = Cast->getType();
   QualType SubType = Cast->IgnoreParenImpCasts()->getType();
 
-  if (!CastType->isIntegerType() || !SubType->isIntegerType())
+  if (!DestType->isIntegerType() || !SubType->isIntegerType())
 return false;
 
-  if (C.getASTContext().getIntWidth(CastType) >=
+  if (C.getASTContext().getIntWidth(DestType) >=
   C.getASTContext().getIntWidth(SubType))
 return false;
 
-  unsigned W = C.getASTContext().getIntWidth(CastType);
+  unsigned W = C.getASTContext().getIntWidth(DestType);
   if (W == 1 || W >= 64U)
 return false;
 

Modified: cfe/trunk/test/Analysis/conversion.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/conversion.c?rev=299523=299522=299523=diff
==
--- cfe/trunk/test/Analysis/conversion.c (original)
+++ cfe/trunk/test/Analysis/conversion.c Wed Apr  5 03:57:04 2017
@@ -9,9 +9,67 @@ void assign(unsigned U, signed S) {
   if (U > 300)
 S8 = U; // expected-warning {{Loss 

[PATCH] D25596: alpha.core.Conversion - Fix false positive for 'U32 += S16; ' expression, that is not unsafe

2017-04-05 Thread Daniel Marjamäki via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL299523: [analyzer] alpha.core.Conversion - Fix false 
positive for 'U32 += S16;'… (authored by danielmarjamaki).

Changed prior to commit:
  https://reviews.llvm.org/D25596?vs=92810=94176#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25596

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
  cfe/trunk/test/Analysis/conversion.c

Index: cfe/trunk/test/Analysis/conversion.c
===
--- cfe/trunk/test/Analysis/conversion.c
+++ cfe/trunk/test/Analysis/conversion.c
@@ -9,9 +9,67 @@
   if (U > 300)
 S8 = U; // expected-warning {{Loss of precision in implicit conversion}}
   if (S > 10)
-U8 = S;
+U8 = S; // no-warning
   if (U < 200)
-S8 = U;
+S8 = U; // no-warning
+}
+
+void addAssign() {
+  unsigned long L = 1000;
+  int I = -100;
+  U8 += L; // expected-warning {{Loss of precision in implicit conversion}}
+  L += I; // no-warning
+}
+
+void subAssign() {
+  unsigned long L = 1000;
+  int I = -100;
+  U8 -= L; // expected-warning {{Loss of precision in implicit conversion}}
+  L -= I; // no-warning
+}
+
+void mulAssign() {
+  unsigned long L = 1000;
+  int I = -1;
+  U8 *= L; // expected-warning {{Loss of precision in implicit conversion}}
+  L *= I;  // expected-warning {{Loss of sign in implicit conversion}}
+  I = 10;
+  L *= I; // no-warning
+}
+
+void divAssign() {
+  unsigned long L = 1000;
+  int I = -1;
+  U8 /= L; // no-warning
+  L /= I; // expected-warning {{Loss of sign in implicit conversion}}
+}
+
+void remAssign() {
+  unsigned long L = 1000;
+  int I = -1;
+  U8 %= L; // no-warning
+  L %= I; // expected-warning {{Loss of sign in implicit conversion}}
+}
+
+void andAssign() {
+  unsigned long L = 1000;
+  int I = -1;
+  U8 &= L; // no-warning
+  L &= I; // expected-warning {{Loss of sign in implicit conversion}}
+}
+
+void orAssign() {
+  unsigned long L = 1000;
+  int I = -1;
+  U8 |= L; // expected-warning {{Loss of precision in implicit conversion}}
+  L |= I;  // expected-warning {{Loss of sign in implicit conversion}}
+}
+
+void xorAssign() {
+  unsigned long L = 1000;
+  int I = -1;
+  U8 ^= L; // expected-warning {{Loss of precision in implicit conversion}}
+  L ^= I;  // expected-warning {{Loss of sign in implicit conversion}}
 }
 
 void init1() {
@@ -21,7 +79,7 @@
 
 void relational(unsigned U, signed S) {
   if (S > 10) {
-if (U < S) {
+if (U < S) { // no-warning
 }
   }
   if (S < -10) {
@@ -32,14 +90,14 @@
 
 void multiplication(unsigned U, signed S) {
   if (S > 5)
-S = U * S;
+S = U * S; // no-warning
   if (S < -10)
 S = U * S; // expected-warning {{Loss of sign}}
 }
 
 void division(unsigned U, signed S) {
   if (S > 5)
-S = U / S;
+S = U / S; // no-warning
   if (S < -10)
 S = U / S; // expected-warning {{Loss of sign}}
 }
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
@@ -41,7 +41,8 @@
   mutable std::unique_ptr BT;
 
   // Is there loss of precision
-  bool isLossOfPrecision(const ImplicitCastExpr *Cast, CheckerContext ) const;
+  bool isLossOfPrecision(const ImplicitCastExpr *Cast, QualType DestType,
+ CheckerContext ) const;
 
   // Is there loss of sign
   bool isLossOfSign(const ImplicitCastExpr *Cast, CheckerContext ) const;
@@ -73,16 +74,30 @@
   // Loss of sign/precision in binary operation.
   if (const auto *B = dyn_cast(Parent)) {
 BinaryOperator::Opcode Opc = B->getOpcode();
-if (Opc == BO_Assign || Opc == BO_AddAssign || Opc == BO_SubAssign ||
-Opc == BO_MulAssign) {
+if (Opc == BO_Assign) {
   LossOfSign = isLossOfSign(Cast, C);
-  LossOfPrecision = isLossOfPrecision(Cast, C);
+  LossOfPrecision = isLossOfPrecision(Cast, Cast->getType(), C);
+} else if (Opc == BO_AddAssign || Opc == BO_SubAssign) {
+  // No loss of sign.
+  LossOfPrecision = isLossOfPrecision(Cast, B->getLHS()->getType(), C);
+} else if (Opc == BO_MulAssign) {
+  LossOfSign = isLossOfSign(Cast, C);
+  LossOfPrecision = isLossOfPrecision(Cast, B->getLHS()->getType(), C);
+} else if (Opc == BO_DivAssign || Opc == BO_RemAssign) {
+  LossOfSign = isLossOfSign(Cast, C);
+  // No loss of precision.
+} else if (Opc == BO_AndAssign) {
+  LossOfSign = isLossOfSign(Cast, C);
+  // No loss of precision.
+} else if (Opc == BO_OrAssign || Opc == BO_XorAssign) {
+  LossOfSign = isLossOfSign(Cast, C);
+  LossOfPrecision = isLossOfPrecision(Cast, B->getLHS()->getType(), C);
 } else if (B->isRelationalOp() || B->isMultiplicativeOp()) {
   LossOfSign = isLossOfSign(Cast, C);
 }
   } else if (isa(Parent)) {
 LossOfSign = isLossOfSign(Cast, 

[PATCH] D31235: Enhance -Wshadow to warn when shadowing typedefs or type aliases

2017-04-05 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg added a comment.

Comitted follow-up diff 94007 as rL299522: Don't issue a warning if the 
shadowing declaration is in a class  now.


https://reviews.llvm.org/D31235



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


r299522 - Don't issue a warning if the shadowing declaration is in a class

2017-04-05 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Wed Apr  5 03:36:58 2017
New Revision: 299522

URL: http://llvm.org/viewvc/llvm-project?rev=299522=rev
Log:
Don't issue a warning if the shadowing declaration is in a class

Follow-up to r299363 "Enhance -Wshadow to warn when shadowing typedefs or type
aliases".

Patch by Ahmed Asadi.

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

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/warn-shadow.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=299522=299521=299522=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Apr  5 03:36:58 2017
@@ -6744,6 +6744,10 @@ NamedDecl *Sema::getShadowedDeclaration(
 /// if it doesn't shadow any declaration or shadowing warnings are disabled.
 NamedDecl *Sema::getShadowedDeclaration(const TypedefNameDecl *D,
 const LookupResult ) {
+  // Don't warn if typedef declaration is part of a class
+  if (D->getDeclContext()->isRecord())
+return nullptr;
+  
   if (!shouldWarnIfShadowedDecl(Diags, R))
 return nullptr;
 

Modified: cfe/trunk/test/SemaCXX/warn-shadow.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-shadow.cpp?rev=299522=299521=299522=diff
==
--- cfe/trunk/test/SemaCXX/warn-shadow.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-shadow.cpp Wed Apr  5 03:36:58 2017
@@ -87,6 +87,16 @@ class A {
   }
 };
 
+struct path {
+  using value_type = char;
+  typedef char value_type2;
+  struct iterator {
+using value_type = path; // no warning
+typedef path value_type2; // no warning
+  };
+};
+
+
 // TODO: this should warn, 
 class B : A {
   int data;


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


[PATCH] D31698: clang-format: [JS] fix whitespace around "of" operator.

2017-04-05 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added inline comments.
This revision is now accepted and ready to land.



Comment at: lib/Format/TokenAnnotator.cpp:2275
+  tok::kw_const) ||
+ // "of" can only occur in a for loop, as a "const x of y".
+ (Left.is(Keywords.kw_of) && Left.Previous &&

Maybe:

  // "of" is only a keyword if it appears after another identifier
  // (e.g. as "const x of y" in a for loop).



https://reviews.llvm.org/D31698



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